sheepy

build system (sheepy) and package manager (spm) for C
git clone https://spartatek.se/git/sheepy.git
Log | Files | Refs | README | LICENSE

character-converter-to-char-wchar_t.gi (2527B)


      1 /* -*- C++ -*- vim: set syntax=cpp:
      2  * PURPOSE: Character converters towards 'char' and 'wchar_t'.
      3  *
      4  * Generate string converter functions which convert a string from one 
      5  * character codec into 'char' or 'wchar'. The conversion is implemented by
      6  * means of a character converter function given by:
      7  *
      8  *            QUEX_CONVERTER_CHAR(FROM, TO)(in, out); 
      9  *
     10  * which converts only a single character. The converter function must
     11  * be defined before the inclusion of this file. This file implements default
     12  * converters for char and wchar. So for 'char' utf8 us used for 'wchar' utf16
     13  * or utf32 are used depending on the system's settings.
     14  *
     15  * (C) 2010-2012 Frank-Rene Schaefer 
     16  * ABSOLUTELY NO WARRANTY                                                    */
     17 
     18 #if   ! defined(__QUEX_FROM)
     19 #   error "__QUEX_FROM must be defined!"
     20 #elif ! defined(__QUEX_FROM_TYPE)
     21 #   error "__QUEX_FROM_TYPE must be defined!"
     22 #elif   defined(__QUEX_TO_TYPE) 
     23 #   error "__QUEX_TO_TYPE must NOT be defined!"
     24 #elif   defined(__QUEX_TO) 
     25 #   error "__QUEX_TO must NOT be defined!"
     26 #elif   defined(__QUEX_TO_CODEC)
     27 #   error "__QUEX_TO_CODEC must NOT be defined!"
     28 #endif
     29 
     30 QUEX_INLINE void
     31 QUEX_CONVERTER_CHAR_DEF(__QUEX_FROM, char)(const __QUEX_FROM_TYPE**  source_pp, 
     32                                            char**                    drain_pp)  
     33 {
     34     switch( sizeof(char) )
     35     {
     36     case 1:
     37         QUEX_CONVERTER_CHAR(__QUEX_FROM, utf8)(source_pp, (uint8_t**)drain_pp);
     38         break;
     39     case 2:
     40         QUEX_CONVERTER_CHAR(__QUEX_FROM, utf16)(source_pp, (uint16_t**)drain_pp);
     41         break;
     42     case 4:
     43         QUEX_CONVERTER_CHAR(__QUEX_FROM, utf32)(source_pp, (uint32_t**)drain_pp);
     44         break;
     45     default:
     46         __quex_assert(false); /* Cannot be handled */
     47     }
     48 }
     49 
     50 #if ! defined(__QUEX_OPTION_WCHAR_T_DISABLED)
     51     QUEX_INLINE void
     52     QUEX_CONVERTER_CHAR_DEF(__QUEX_FROM, wchar)(const __QUEX_FROM_TYPE**  source_pp, 
     53                                                 wchar_t**                 drain_pp)  
     54     {
     55         switch( sizeof(wchar_t) )
     56         {
     57         case 1:
     58             QUEX_CONVERTER_CHAR(__QUEX_FROM, utf8)(source_pp, (uint8_t**)drain_pp);
     59             break;
     60         case 2:
     61             QUEX_CONVERTER_CHAR(__QUEX_FROM, utf16)(source_pp, (uint16_t**)drain_pp);
     62             break;
     63         case 4:
     64             QUEX_CONVERTER_CHAR(__QUEX_FROM, utf32)(source_pp, (uint32_t**)drain_pp);
     65             break;
     66         default:
     67             __quex_assert(false); /* Cannot be handled */
     68         }
     69     }
     70 #endif
     71