unicode.h 924 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef _SCDOC_UNICODE_H
  2. #define _SCDOC_UNICODE_H
  3. #include <stddef.h>
  4. #include <stdint.h>
  5. #include <stdio.h>
  6. // Technically UTF-8 supports up to 6 byte codepoints, but Unicode itself
  7. // doesn't really bother with more than 4.
  8. #define UTF8_MAX_SIZE 4
  9. #define UTF8_INVALID 0x80
  10. /**
  11. * Grabs the next UTF-8 character and advances the string pointer
  12. */
  13. uint32_t utf8_decode(const char **str);
  14. /**
  15. * Encodes a character as UTF-8 and returns the length of that character.
  16. */
  17. size_t utf8_encode(char *str, uint32_t ch);
  18. /**
  19. * Returns the size of the next UTF-8 character
  20. */
  21. int utf8_size(const char *str);
  22. /**
  23. * Returns the size of a UTF-8 character
  24. */
  25. size_t utf8_chsize(uint32_t ch);
  26. /**
  27. * Reads and returns the next character from the file.
  28. */
  29. uint32_t utf8_fgetch(FILE *f);
  30. /**
  31. * Writes this character to the file and returns the number of bytes written.
  32. */
  33. size_t utf8_fputch(FILE *f, uint32_t ch);
  34. #endif