sheepy

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

from-unicode-buffer.i (4264B)


      1 /* -*- C++ -*- vim: set syntax=cpp:
      2  * PURPOSE: 
      3  *
      4  * Provide the implementation of character and string converter functions
      5  * FROM the buffer's unicode to utf8, utf16, utf32, char, and wchar_t.
      6  *
      7  * STEPS:
      8  *
      9  * (1) Include the COMPLETE implementation of a reference transformation.
     10  *
     11  *             "character-converter-from-utf8.i"
     12  *             "character-converter-from-utf16.i"
     13  *             "character-converter-from-utf32.i"
     14  *
     15  *     Sometimes the size of QUEX_TYPE_LEXATOM could not be determined at 
     16  *     code generation time, therefore all need to be included.
     17  *
     18  * (2) Map the functions of the pattern
     19  *
     20  *        QUEX_CONVERTER_CHAR(unicode, *)(....)
     21  *
     22  *     to what is appropriate from the given headers, e.g.
     23  *
     24  *        QUEX_CONVERTER_CHAR(utf8, *)(....)
     25  *
     26  * (2b) Generate converters towards 'char' and 'wchar_t'
     27  *
     28  *        generator/character-converter-to-char-wchar_t.gi
     29  *
     30  * (3) Derive string converter functions from character converters.
     31  *
     32  *        generator/implementations.gi
     33  *
     34  * These functions ARE DEPENDENT on QUEX_TYPE_LEXATOM.
     35  * => Thus, they are placed in the analyzer's namespace.
     36  *
     37  * 2010 (C) Frank-Rene Schaefer; 
     38  * ABSOLUTELY NO WARRANTY                                                    */
     39 #if    ! defined(__QUEX_INCLUDE_GUARD__CONVERTER_HELPER__FROM_UNICODE_BUFFER_I) \
     40     ||   defined(__QUEX_INCLUDE_GUARD__CONVERTER_HELPER__TMP_DISABLED)
     41 #if    ! defined(__QUEX_INCLUDE_GUARD__CONVERTER_HELPER__TMP_DISABLED)
     42 #        define  __QUEX_INCLUDE_GUARD__CONVERTER_HELPER__FROM_UNICODE_BUFFER_I
     43 #endif
     44 
     45 #include "from-unicode-buffer"
     46 
     47 /* (1) Access the implementation of the converter that will implement
     48  *     the unicode conversion.                                               */
     49 #include "from-utf8.i"
     50 #include "from-utf16.i"
     51 #include "from-utf32.i"
     52 
     53 QUEX_NAMESPACE_MAIN_OPEN
     54 
     55 /* (2) Route the converters from 'unicode' to the implementing converter.    */
     56 QUEX_INLINE void
     57 QUEX_CONVERTER_CHAR_DEF(unicode, utf8)(const QUEX_TYPE_LEXATOM**  input_pp, 
     58                                        uint8_t**                    output_pp)
     59 { 
     60     switch( sizeof(QUEX_TYPE_LEXATOM) )
     61     {
     62     case 1:  QUEX_CONVERTER_CHAR(utf8, utf8)((const uint8_t**)input_pp, output_pp);   break;
     63     case 2:  QUEX_CONVERTER_CHAR(utf16, utf8)((const uint16_t**)input_pp, output_pp); break;
     64     case 4:  QUEX_CONVERTER_CHAR(utf32, utf8)((const uint32_t**)input_pp, output_pp); break;
     65     default: QUEX_ERROR_EXIT("Cannot derive converter for given element size.");
     66     }
     67 }
     68 
     69 QUEX_INLINE void
     70 QUEX_CONVERTER_CHAR_DEF(unicode, utf16)(const QUEX_TYPE_LEXATOM**  input_pp, 
     71                                         uint16_t**                   output_pp)
     72 { 
     73     switch( sizeof(QUEX_TYPE_LEXATOM) )
     74     {
     75     case 1:  QUEX_CONVERTER_CHAR(utf8, utf16)((const uint8_t**)input_pp, output_pp);   break;
     76     case 2:  QUEX_CONVERTER_CHAR(utf16, utf16)((const uint16_t**)input_pp, output_pp); break;
     77     case 4:  QUEX_CONVERTER_CHAR(utf32, utf16)((const uint32_t**)input_pp, output_pp); break;
     78     default: QUEX_ERROR_EXIT("Cannot derive converter for given element size.");
     79     }
     80 }
     81 
     82 QUEX_INLINE void
     83 QUEX_CONVERTER_CHAR_DEF(unicode, utf32)(const QUEX_TYPE_LEXATOM**  input_pp, 
     84                                         uint32_t**                   output_pp)
     85 { 
     86     switch( sizeof(QUEX_TYPE_LEXATOM) )
     87     {
     88     case 1:  QUEX_CONVERTER_CHAR(utf8, utf32)((const uint8_t**)input_pp, output_pp);   break;
     89     case 2:  QUEX_CONVERTER_CHAR(utf16, utf32)((const uint16_t**)input_pp, output_pp); break;
     90     case 4:  QUEX_CONVERTER_CHAR(utf32, utf32)((const uint32_t**)input_pp, output_pp); break;
     91     default: QUEX_ERROR_EXIT("Cannot derive converter for given element size.");
     92     }
     93 }
     94 
     95 
     96 /* (2b) Derive converters to char and wchar_t from the given set 
     97  *      of converters. (Generator uses __QUEX_FROM and QUEX_FROM_TYPE)      */
     98 #define  __QUEX_FROM       unicode
     99 #define  __QUEX_FROM_TYPE  QUEX_TYPE_LEXATOM
    100 #include "character-converter-to-char-wchar_t.gi"
    101 
    102 /* (3) Generate string converters to utf8, utf16, utf32 based on the
    103  *     definitions of the character converters.                             */
    104 #include "implementations.gi"
    105 
    106 QUEX_NAMESPACE_MAIN_CLOSE
    107 
    108 #endif /* __QUEX_INCLUDE_GUARD__CONVERTER_HELPER__FROM_UNICODE_BUFFER_I */