mf_encoding.h 1.2 KB

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