Chars.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #include "BeefySysLib/Common.h"
  2. #include "BeefySysLib/util/TLSingleton.h"
  3. #include "BfObjects.h"
  4. extern "C"
  5. {
  6. #include "BeefySysLib/third_party/utf8proc/utf8proc.h"
  7. }
  8. namespace bf
  9. {
  10. namespace System
  11. {
  12. struct Char32
  13. {
  14. private:
  15. BFRT_EXPORT static bool get__IsWhiteSpace_EX(char32_t c);
  16. public:
  17. BFRT_EXPORT static char32_t get__ToLower(char32_t c);
  18. BFRT_EXPORT static char32_t get__ToUpper(char32_t c);
  19. BFRT_EXPORT static bool get__IsLower(char32_t c);
  20. BFRT_EXPORT static bool get__IsUpper(char32_t c);
  21. BFRT_EXPORT static bool get__IsLetterOrDigit(char32_t c);
  22. BFRT_EXPORT static bool get__IsLetter(char32_t c);
  23. BFRT_EXPORT static bool get__IsNumber(char32_t c);
  24. };
  25. struct Char16
  26. {
  27. public:
  28. BFRT_EXPORT static char16_t get__ToLower(char16_t c);
  29. BFRT_EXPORT static char16_t get__ToUpper(char16_t c);
  30. BFRT_EXPORT static bool get__IsLower(char16_t c);
  31. BFRT_EXPORT static bool get__IsUpper(char16_t c);
  32. BFRT_EXPORT static bool get__IsWhiteSpace(char16_t c);
  33. BFRT_EXPORT static bool get__IsLetterOrDigit(char16_t c);
  34. BFRT_EXPORT static bool get__IsLetter(char16_t c);
  35. BFRT_EXPORT static bool get__IsNumber(char16_t c);
  36. };
  37. }
  38. }
  39. char32_t bf::System::Char32::get__ToLower(char32_t c)
  40. {
  41. return utf8proc_tolower(c);
  42. }
  43. char32_t bf::System::Char32::get__ToUpper(char32_t c)
  44. {
  45. return utf8proc_toupper(c);
  46. }
  47. bool bf::System::Char32::get__IsLower(char32_t c)
  48. {
  49. return utf8proc_category(c) == UTF8PROC_CATEGORY_LL;
  50. }
  51. bool bf::System::Char32::get__IsUpper(char32_t c)
  52. {
  53. return utf8proc_category(c) == UTF8PROC_CATEGORY_LU;
  54. }
  55. bool bf::System::Char32::get__IsWhiteSpace_EX(char32_t c)
  56. {
  57. auto cat = utf8proc_category(c);
  58. return (cat == UTF8PROC_CATEGORY_ZS) || (cat == UTF8PROC_CATEGORY_ZL) || (cat == UTF8PROC_CATEGORY_ZP);
  59. }
  60. bool bf::System::Char32::get__IsLetterOrDigit(char32_t c)
  61. {
  62. auto cat = utf8proc_category(c);
  63. switch (cat)
  64. {
  65. case UTF8PROC_CATEGORY_LU:
  66. case UTF8PROC_CATEGORY_LL:
  67. case UTF8PROC_CATEGORY_LT:
  68. case UTF8PROC_CATEGORY_LM:
  69. case UTF8PROC_CATEGORY_LO:
  70. case UTF8PROC_CATEGORY_ND:
  71. case UTF8PROC_CATEGORY_NL:
  72. case UTF8PROC_CATEGORY_NO: return true;
  73. default: break;
  74. }
  75. return false;
  76. }
  77. bool bf::System::Char32::get__IsLetter(char32_t c)
  78. {
  79. auto cat = utf8proc_category(c);
  80. switch (cat)
  81. {
  82. case UTF8PROC_CATEGORY_LU:
  83. case UTF8PROC_CATEGORY_LL:
  84. case UTF8PROC_CATEGORY_LT:
  85. case UTF8PROC_CATEGORY_LM:
  86. case UTF8PROC_CATEGORY_LO: return true;
  87. default: break;
  88. }
  89. return false;
  90. }
  91. bool bf::System::Char32::get__IsNumber(char32_t c)
  92. {
  93. auto cat = utf8proc_category(c);
  94. switch (cat)
  95. {
  96. case UTF8PROC_CATEGORY_ND:
  97. case UTF8PROC_CATEGORY_NL:
  98. case UTF8PROC_CATEGORY_NO: return true;
  99. default: break;
  100. }
  101. return false;
  102. }
  103. //////////////////////////////////////////////////////////////////////////
  104. char16_t bf::System::Char16::get__ToLower(char16_t c)
  105. {
  106. return utf8proc_tolower(c);
  107. }
  108. char16_t bf::System::Char16::get__ToUpper(char16_t c)
  109. {
  110. return utf8proc_toupper(c);
  111. }
  112. bool bf::System::Char16::get__IsLower(char16_t c)
  113. {
  114. return utf8proc_category(c) == UTF8PROC_CATEGORY_LL;
  115. }
  116. bool bf::System::Char16::get__IsUpper(char16_t c)
  117. {
  118. return utf8proc_category(c) == UTF8PROC_CATEGORY_LU;
  119. }
  120. bool bf::System::Char16::get__IsWhiteSpace(char16_t c)
  121. {
  122. return utf8proc_category(c) == UTF8PROC_CATEGORY_ZS;
  123. }
  124. bool bf::System::Char16::get__IsLetterOrDigit(char16_t c)
  125. {
  126. auto cat = utf8proc_category(c);
  127. switch (cat)
  128. {
  129. case UTF8PROC_CATEGORY_LU:
  130. case UTF8PROC_CATEGORY_LL:
  131. case UTF8PROC_CATEGORY_LT:
  132. case UTF8PROC_CATEGORY_LM:
  133. case UTF8PROC_CATEGORY_LO:
  134. case UTF8PROC_CATEGORY_ND:
  135. case UTF8PROC_CATEGORY_NL:
  136. case UTF8PROC_CATEGORY_NO: return true;
  137. default: break;
  138. }
  139. return false;
  140. }
  141. bool bf::System::Char16::get__IsLetter(char16_t c)
  142. {
  143. auto cat = utf8proc_category(c);
  144. switch (cat)
  145. {
  146. case UTF8PROC_CATEGORY_LU:
  147. case UTF8PROC_CATEGORY_LL:
  148. case UTF8PROC_CATEGORY_LT:
  149. case UTF8PROC_CATEGORY_LM:
  150. case UTF8PROC_CATEGORY_LO: return true;
  151. default: break;
  152. }
  153. return false;
  154. }
  155. bool bf::System::Char16::get__IsNumber(char16_t c)
  156. {
  157. auto cat = utf8proc_category(c);
  158. switch (cat)
  159. {
  160. case UTF8PROC_CATEGORY_ND:
  161. case UTF8PROC_CATEGORY_NL:
  162. case UTF8PROC_CATEGORY_NO: return true;
  163. default: break;
  164. }
  165. return false;
  166. }
  167. intptr bf::System::String::UTF8GetAllocSize(char* str, intptr strlen, int32 options)
  168. {
  169. return utf8proc_decompose_custom((const utf8proc_uint8_t*)str, strlen, NULL, 0, (utf8proc_option_t)options, NULL, NULL);
  170. }
  171. intptr bf::System::String::UTF8Map(char* str, intptr strlen, char* outStr, intptr outSize, int32 options)
  172. {
  173. intptr result = utf8proc_decompose_custom((const utf8proc_uint8_t*)str, strlen, (utf8proc_int32_t*)outStr, outSize, (utf8proc_option_t)options, NULL, NULL);
  174. if (result < 0)
  175. return result;
  176. result = utf8proc_reencode((utf8proc_int32_t*)outStr, outSize, (utf8proc_option_t)options);
  177. return result;
  178. }