pluginxUTF8.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // ccUTF8.h
  3. // cocos2dx
  4. //
  5. // Created by James Chen on 2/27/13.
  6. //
  7. #ifndef __pluginx__ccUTF8__
  8. #define __pluginx__ccUTF8__
  9. #include <vector>
  10. namespace pluginx {
  11. int cc_wcslen(const unsigned short* str);
  12. void cc_utf8_trim_ws(std::vector<unsigned short>* str);
  13. /*
  14. * @ch is the unicode character whitespace?
  15. *
  16. * Reference: http://en.wikipedia.org/wiki/Whitespace_character#Unicode
  17. *
  18. * Return value: weather the character is a whitespace character.
  19. * */
  20. bool isspace_unicode(unsigned short ch);
  21. /*
  22. * cc_utf8_strlen:
  23. * @p: pointer to the start of a UTF-8 encoded string.
  24. * @max: the maximum number of bytes to examine. If @max
  25. * is less than 0, then the string is assumed to be
  26. * null-terminated. If @max is 0, @p will not be examined and
  27. * may be %NULL.
  28. *
  29. * Returns the length of the string in characters.
  30. *
  31. * Return value: the length of the string in characters
  32. **/
  33. long
  34. cc_utf8_strlen (const char * p, int max);
  35. /*
  36. * @str: the string to search through.
  37. * @c: the character to not look for.
  38. *
  39. * Return value: the index of the last character that is not c.
  40. * */
  41. unsigned int cc_utf8_find_last_not_char(std::vector<unsigned short> str, unsigned short c);
  42. std::vector<unsigned short> cc_utf16_vec_from_utf16_str(const unsigned short* str);
  43. /*
  44. * cc_utf8_to_utf16:
  45. * @str_old: pointer to the start of a C string.
  46. *
  47. * Creates a utf8 string from a cstring.
  48. *
  49. * Return value: the newly created utf8 string.
  50. * */
  51. unsigned short* cc_utf8_to_utf16(const char* str_old, int length = -1, int* rUtf16Size = 0);
  52. /**
  53. * cc_utf16_to_utf8:
  54. * @str: a UTF-16 encoded string
  55. * @len: the maximum length of @str to use. If @len < 0, then
  56. * the string is terminated with a 0 character.
  57. * @items_read: location to store number of words read, or %NULL.
  58. * If %NULL, then %G_CONVERT_ERROR_PARTIAL_INPUT will be
  59. * returned in case @str contains a trailing partial
  60. * character. If an error occurs then the index of the
  61. * invalid input is stored here.
  62. * @items_written: location to store number of bytes written, or %NULL.
  63. * The value stored here does not include the trailing
  64. * 0 byte.
  65. * @error: location to store the error occuring, or %NULL to ignore
  66. * errors. Any of the errors in #GConvertError other than
  67. * %G_CONVERT_ERROR_NO_CONVERSION may occur.
  68. *
  69. * Convert a string from UTF-16 to UTF-8. The result will be
  70. * terminated with a 0 byte.
  71. *
  72. * Return value: a pointer to a newly allocated UTF-8 string.
  73. * This value must be freed with free(). If an
  74. * error occurs, %NULL will be returned and
  75. * @error set.
  76. **/
  77. char *
  78. cc_utf16_to_utf8 (const unsigned short *str,
  79. long len,
  80. long *items_read,
  81. long *items_written);
  82. } // namespace pluginx {
  83. #endif /* defined(__cocos2dx__ccUTF8__) */