LCOV - code coverage report
Current view: top level - lib - strerror-stringprep.c (source / functions) Hit Total Coverage
Test: GNU Libidn Lines: 30 30 100.0 %
Date: 2013-07-10 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 13 13 100.0 %

           Branch data     Line data    Source code
       1                 :            : /* strerror-stringprep.c --- Convert stringprep errors into text.
       2                 :            :    Copyright (C) 2004-2013 Simon Josefsson
       3                 :            : 
       4                 :            :    This file is part of GNU Libidn.
       5                 :            : 
       6                 :            :    GNU Libidn is free software: you can redistribute it and/or
       7                 :            :    modify it under the terms of either:
       8                 :            : 
       9                 :            :      * the GNU Lesser General Public License as published by the Free
      10                 :            :        Software Foundation; either version 3 of the License, or (at
      11                 :            :        your option) any later version.
      12                 :            : 
      13                 :            :    or
      14                 :            : 
      15                 :            :      * the GNU General Public License as published by the Free
      16                 :            :        Software Foundation; either version 2 of the License, or (at
      17                 :            :        your option) any later version.
      18                 :            : 
      19                 :            :    or both in parallel, as here.
      20                 :            : 
      21                 :            :    GNU Libidn is distributed in the hope that it will be useful,
      22                 :            :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      23                 :            :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      24                 :            :    General Public License for more details.
      25                 :            : 
      26                 :            :    You should have received copies of the GNU General Public License and
      27                 :            :    the GNU Lesser General Public License along with this program.  If
      28                 :            :    not, see <http://www.gnu.org/licenses/>. */
      29                 :            : 
      30                 :            : #ifdef HAVE_CONFIG_H
      31                 :            : # include "config.h"
      32                 :            : #endif
      33                 :            : 
      34                 :            : #include "stringprep.h"
      35                 :            : 
      36                 :            : #include "gettext.h"
      37                 :            : #define _(String) dgettext (PACKAGE, String)
      38                 :            : 
      39                 :            : /**
      40                 :            :  * stringprep_strerror:
      41                 :            :  * @rc: a #Stringprep_rc return code.
      42                 :            :  *
      43                 :            :  * Convert a return code integer to a text string.  This string can be
      44                 :            :  * used to output a diagnostic message to the user.
      45                 :            :  *
      46                 :            :  * STRINGPREP_OK: Successful operation.  This value is guaranteed to
      47                 :            :  *   always be zero, the remaining ones are only guaranteed to hold
      48                 :            :  *   non-zero values, for logical comparison purposes.
      49                 :            :  * STRINGPREP_CONTAINS_UNASSIGNED: String contain unassigned Unicode
      50                 :            :  *   code points, which is forbidden by the profile.
      51                 :            :  * STRINGPREP_CONTAINS_PROHIBITED: String contain code points
      52                 :            :  *   prohibited by the profile.
      53                 :            :  * STRINGPREP_BIDI_BOTH_L_AND_RAL: String contain code points with
      54                 :            :  *   conflicting bidirection category.
      55                 :            :  * STRINGPREP_BIDI_LEADTRAIL_NOT_RAL: Leading and trailing character
      56                 :            :  *   in string not of proper bidirectional category.
      57                 :            :  * STRINGPREP_BIDI_CONTAINS_PROHIBITED: Contains prohibited code
      58                 :            :  *   points detected by bidirectional code.
      59                 :            :  * STRINGPREP_TOO_SMALL_BUFFER: Buffer handed to function was too
      60                 :            :  *   small.  This usually indicate a problem in the calling
      61                 :            :  *   application.
      62                 :            :  * STRINGPREP_PROFILE_ERROR: The stringprep profile was inconsistent.
      63                 :            :  *   This usually indicate an internal error in the library.
      64                 :            :  * STRINGPREP_FLAG_ERROR: The supplied flag conflicted with profile.
      65                 :            :  *   This usually indicate a problem in the calling application.
      66                 :            :  * STRINGPREP_UNKNOWN_PROFILE: The supplied profile name was not
      67                 :            :  *   known to the library.
      68                 :            :  * STRINGPREP_NFKC_FAILED: The Unicode NFKC operation failed.  This
      69                 :            :  *   usually indicate an internal error in the library.
      70                 :            :  * STRINGPREP_MALLOC_ERROR: The malloc() was out of memory.  This is
      71                 :            :  *   usually a fatal error.
      72                 :            :  *
      73                 :            :  * Return value: Returns a pointer to a statically allocated string
      74                 :            :  *   containing a description of the error with the return code @rc.
      75                 :            :  **/
      76                 :            : const char *
      77                 :         20 : stringprep_strerror (Stringprep_rc rc)
      78                 :            : {
      79                 :            :   const char *p;
      80                 :            : 
      81                 :         20 :   bindtextdomain (PACKAGE, LOCALEDIR);
      82                 :            : 
      83   [ +  +  +  +  :         20 :   switch (rc)
          +  +  +  +  +  
             +  +  +  + ]
      84                 :            :     {
      85                 :            :     case STRINGPREP_OK:
      86                 :          2 :       p = _("Success");
      87                 :          2 :       break;
      88                 :            : 
      89                 :            :     case STRINGPREP_CONTAINS_UNASSIGNED:
      90                 :          1 :       p = _("Forbidden unassigned code points in input");
      91                 :          1 :       break;
      92                 :            : 
      93                 :            :     case STRINGPREP_CONTAINS_PROHIBITED:
      94                 :          1 :       p = _("Prohibited code points in input");
      95                 :          1 :       break;
      96                 :            : 
      97                 :            :     case STRINGPREP_BIDI_BOTH_L_AND_RAL:
      98                 :          1 :       p = _("Conflicting bidirectional properties in input");
      99                 :          1 :       break;
     100                 :            : 
     101                 :            :     case STRINGPREP_BIDI_LEADTRAIL_NOT_RAL:
     102                 :          1 :       p = _("Malformed bidirectional string");
     103                 :          1 :       break;
     104                 :            : 
     105                 :            :     case STRINGPREP_BIDI_CONTAINS_PROHIBITED:
     106                 :          1 :       p = _("Prohibited bidirectional code points in input");
     107                 :          1 :       break;
     108                 :            : 
     109                 :            :     case STRINGPREP_TOO_SMALL_BUFFER:
     110                 :          1 :       p = _("Output would exceed the buffer space provided");
     111                 :          1 :       break;
     112                 :            : 
     113                 :            :     case STRINGPREP_PROFILE_ERROR:
     114                 :          1 :       p = _("Error in stringprep profile definition");
     115                 :          1 :       break;
     116                 :            : 
     117                 :            :     case STRINGPREP_FLAG_ERROR:
     118                 :          1 :       p = _("Flag conflict with profile");
     119                 :          1 :       break;
     120                 :            : 
     121                 :            :     case STRINGPREP_UNKNOWN_PROFILE:
     122                 :          1 :       p = _("Unknown profile");
     123                 :          1 :       break;
     124                 :            : 
     125                 :            :     case STRINGPREP_NFKC_FAILED:
     126                 :          1 :       p = _("Unicode normalization failed (internal error)");
     127                 :          1 :       break;
     128                 :            : 
     129                 :            :     case STRINGPREP_MALLOC_ERROR:
     130                 :          1 :       p = _("Cannot allocate memory");
     131                 :          1 :       break;
     132                 :            : 
     133                 :            :     default:
     134                 :          7 :       p = _("Unknown error");
     135                 :          7 :       break;
     136                 :            :     }
     137                 :            : 
     138                 :         20 :   return p;
     139                 :            : }

Generated by: LCOV version 1.9