UTF8.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #pragma once
  2. #include "../Common.h"
  3. NS_BF_BEGIN;
  4. /* is c the start of a utf8 sequence? */
  5. #define isutf(c) (((c)&0xC0)!=0x80)
  6. /* convert UTF-8 data to wide character */
  7. int u8_toucs(wchar_t *dest, int sz, char *src, int srcsz);
  8. uint32 u8_toucs(const char* src, int srcsz, int* outLen = NULL);
  9. /* the opposite conversion */
  10. int u8_toutf8(char *dest, int sz, wchar_t *src, int srcsz);
  11. /* the opposite conversion */
  12. int u8_toutf8(char *dest, int sz, uint32 ch);
  13. /* single character to UTF-8 */
  14. int u8_wc_toutf8(char *dest, uint32 ch);
  15. /* character number to byte offset */
  16. int u8_offset(char *str, int charnum);
  17. /* byte offset to character number */
  18. int u8_charnum(char *s, int offset);
  19. /* return next character, updating an index variable */
  20. uint32 u8_nextchar(char *s, int *i);
  21. /* move to next character */
  22. void u8_inc(char *s, int *i);
  23. /* move to previous character */
  24. void u8_dec(char *s, int *i);
  25. /* returns length of next utf-8 sequence */
  26. int u8_seqlen(char *s);
  27. int u8_seqlen(uint32 ch);
  28. /* assuming src points to the character after a backslash, read an
  29. escape sequence, storing the result in dest and returning the number of
  30. input characters processed */
  31. int u8_read_escape_sequence(char *src, uint32 *dest);
  32. /* given a wide character, convert it to an ASCII escape sequence stored in
  33. buf, where buf is "sz" bytes. returns the number of characters output. */
  34. int u8_escape_wchar(char *buf, int sz, uint32 ch);
  35. /* convert a string "src" containing escape sequences to UTF-8 */
  36. int u8_unescape(char *buf, int sz, char *src);
  37. /* convert UTF-8 "src" to ASCII with escape sequences.
  38. if escape_quotes is nonzero, quote characters will be preceded by
  39. backslashes as well. */
  40. int u8_escape(char *buf, int sz, char *src, int escape_quotes);
  41. /* utility predicates used by the above */
  42. int octal_digit(char c);
  43. int hex_digit(char c);
  44. /* return a pointer to the first occurrence of ch in s, or NULL if not
  45. found. character index of found character returned in *charn. */
  46. char *u8_strchr(char *s, uint32 ch, int *charn);
  47. /* same as the above, but searches a buffer of a given size instead of
  48. a NUL-terminated string. */
  49. char *u8_memchr(char *s, uint32 ch, size_t sz, int *charn);
  50. /* count the number of characters in a UTF-8 string */
  51. int u8_strlen(char *s);
  52. int u8_is_locale_utf8(char *locale);
  53. /* printf where the format string and arguments may be in UTF-8.
  54. you can avoid this function and just use ordinary printf() if the current
  55. locale is UTF-8. */
  56. int u8_vprintf(char *fmt, va_list ap);
  57. int u8_printf(char *fmt, ...);
  58. bool UTF8IsCombiningMark(uint32 c);
  59. bool UTF8GetGraphemeClusterSpan(const char* str, int strLength, int idx, int& startIdx, int& spanLength);
  60. void UTF8Categorize(const char* str, int strLength, int& numCodePoints, int& numCombiningMarks);
  61. NS_BF_END;