1 /* Simple UTF-8 decoder. Also implements the much simpler ASCII and UTF16 2 * input encodings. 3 */ 4 5 #ifndef _MF_ENCODING_H_ 6 #define _MF_ENCODING_H_ 7 8 #include "mf_config.h" 9 #include <stdint.h> 10 11 /* Type used to represent characters internally. */ 12 #if MF_ENCODING == MF_ENCODING_ASCII 13 typedef char mf_char; 14 #else 15 typedef uint16_t mf_char; 16 #endif 17 18 /* Type used to represent input strings. */ 19 #if MF_ENCODING == MF_ENCODING_ASCII 20 typedef const char * mf_str; 21 #elif MF_ENCODING == MF_ENCODING_UTF8 22 typedef const char * mf_str; 23 #elif MF_ENCODING == MF_ENCODING_UTF16 24 typedef const uint16_t * mf_str; 25 #elif MF_ENCODING == MF_ENCODING_WCHAR 26 #include <stddef.h> 27 typedef const wchar_t * mf_str; 28 #endif 29 30 /* Returns the next character in the string and advances the pointer. 31 * When the string ends, returns 0 and leaves the pointer at the 0 byte. 32 * 33 * str: Pointer to variable holding current location in string. 34 * Initialize it to the start of the string. 35 * 36 * Returns: The next character, as unicode codepoint. 37 */ 38 MF_EXTERN mf_char mf_getchar(mf_str *str); 39 40 /* Moves back the pointer to the beginning of the previous character. 41 * Be careful not to go beyond the start of the string. 42 */ 43 MF_EXTERN void mf_rewind(mf_str *str); 44 45 #endif 46