sheepy

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

Converter (4681B)


      1 /* -*- C++ -*-  vim: set syntax=cpp:
      2  * (C) 2007-2016 Frank-Rene Schaefer  */
      3 #ifndef  __QUEX_INCLUDE_GUARD__BUFFER__LEXATOMS__CONVERTER__CONVERTER
      4 #define  __QUEX_INCLUDE_GUARD__BUFFER__LEXATOMS__CONVERTER__CONVERTER
      5 
      6 #include "definitions"
      7 #include "MemoryManager"
      8 
      9 QUEX_NAMESPACE_MAIN_OPEN
     10 
     11 
     12 typedef struct QUEX_SETTING_USER_CLASS_DECLARATION_EPILOG QUEX_NAME(Converter_tag) {
     13     E_Ownership   ownership;
     14 
     15     E_LoadResult    (*convert)(struct QUEX_NAME(Converter_tag)*, 
     16                                uint8_t**           source, const uint8_t*           SourceEnd, 
     17                                QUEX_TYPE_LEXATOM** drain,  const QUEX_TYPE_LEXATOM* DrainEnd);
     18     /* Tries to convert all lexatoms given in 'source' with the coding specified
     19      * earlier to _open(...). 'source' and 'drain' are passed as pointers to pointers
     20      * so that the pointers can be changed. This way the converter can inform the
     21      * user about the state of conversion from source to drain buffer.
     22      *
     23      * BEFORE:         *source              SourceEnd
     24      *                 |                    |
     25      *          [      .....................]   source buffer
     26      *
     27      *               *drain         DrainEnd
     28      *               |              |
     29      *          [....               ] drain buffer
     30      *
     31      *       At the beginning, 'source' points to the first lexatom to be
     32      *       converted. 'drain' points to the place where the first converted
     33      *       lexatom is to be written to.
     34      *  
     35      * AFTER:                          *source                              
     36      *                                 |     
     37      *          [                      .....]   source buffer
     38      *
     39      *                        *drain 
     40      *                        |      
     41      *          [.............      ] drain buffer
     42      *
     43      *       After conversion, 'source' points immediately behind the last 
     44      *       lexatom that was subject to conversion. 'drain' points behind the
     45      *       last lexatom that resulted from the conversion. 
     46      *  
     47      * RETURNS:  true  --> Drain buffer is filled as much as possible with converted 
     48      *                     lexatoms.
     49      *           false --> More source bytes are needed to fill the drain buffer.     */
     50 
     51     ptrdiff_t (*stomach_byte_n)(struct QUEX_NAME(Converter_tag)*);
     52     void      (*stomach_clear)(struct QUEX_NAME(Converter_tag)*);
     53     /*  [OPTIONAL] can be set to '0x0'. 
     54      * 
     55      *  This function is called whenever a conversion discontinuity appears.
     56      *  Such cases appear only when the user navigates through the input
     57      *  stream (seek_lexatom_index(...)), or with long pre-conditions when
     58      *  the buffer size is exceeded. 
     59      *
     60      *  For 'normal' converters this function can be set to '0x0'. If a converter
     61      *  has an internal 'statefulness' that is difficult to be tamed, then use
     62      *  this function to reset the converter. Actually, the initial reason
     63      *  for introducing the function pointer was the strange behavior of the 
     64      *  ICU Converters of IBM(R).                                                     */
     65 
     66     void    (*delete_self)(struct QUEX_NAME(Converter_tag)*);
     67     /* Closes the conversion handle produced with open(...).      
     68      * Deletes the object of the derived class.                                       */
     69 
     70     int     byte_n_per_lexatom;
     71     /* Some encodings (such as UTF-8) occupy different number of bytes for different
     72      * lexatoms. Others, such as ASCII or UCS-4 use the same number of bytes for
     73      * all lexatoms of the lexatom set. Using the flag, the buffer filler can
     74      * adapt the seek algorithm for navigation in the lexatom stream.                 */
     75 
     76     bool    virginity_f;
     77 
     78 } QUEX_NAME(Converter);
     79 
     80 QUEX_INLINE bool
     81 QUEX_NAME(Converter_construct)(QUEX_NAME(Converter)* me,
     82                     const char*  FromCodec, const char* ToCodec,
     83                     bool         (*open)(QUEX_NAME(Converter)*, 
     84                                          const char* FromCodingName, const char* ToCodingName),  
     85                     E_LoadResult (*convert)(QUEX_NAME(Converter)*, 
     86                                             uint8_t**             source, const uint8_t*             SourceEnd, 
     87                                             QUEX_TYPE_LEXATOM** drain,  const QUEX_TYPE_LEXATOM* DrainEnd),
     88                     void         (*delete_self)(QUEX_NAME(Converter)*),
     89                     ptrdiff_t    (*stomach_byte_n)(QUEX_NAME(Converter)*),
     90                     void         (*stomach_clear)(QUEX_NAME(Converter)*));
     91 
     92 
     93 QUEX_NAMESPACE_MAIN_CLOSE
     94 
     95 #endif /*  __QUEX_INCLUDE_GUARD__BUFFER__LEXATOMS__CONVERTER__CONVERTER */