123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- #include "BeefySysLib/Common.h"
- #include "BeefySysLib/util/TLSingleton.h"
- #include "BfObjects.h"
- extern "C"
- {
- #include "BeefySysLib/third_party/utf8proc/utf8proc.h"
- }
- namespace bf
- {
- namespace System
- {
- struct Char32
- {
- private:
- BFRT_EXPORT static bool get__IsWhiteSpace_EX(char32_t c);
- public:
- BFRT_EXPORT static char32_t get__ToLower(char32_t c);
- BFRT_EXPORT static char32_t get__ToUpper(char32_t c);
- BFRT_EXPORT static bool get__IsLower(char32_t c);
- BFRT_EXPORT static bool get__IsUpper(char32_t c);
- BFRT_EXPORT static bool get__IsLetterOrDigit(char32_t c);
- BFRT_EXPORT static bool get__IsLetter(char32_t c);
- BFRT_EXPORT static bool get__IsNumber(char32_t c);
- };
- struct Char16
- {
- public:
- BFRT_EXPORT static char16_t get__ToLower(char16_t c);
- BFRT_EXPORT static char16_t get__ToUpper(char16_t c);
- BFRT_EXPORT static bool get__IsLower(char16_t c);
- BFRT_EXPORT static bool get__IsUpper(char16_t c);
- BFRT_EXPORT static bool get__IsWhiteSpace(char16_t c);
- BFRT_EXPORT static bool get__IsLetterOrDigit(char16_t c);
- BFRT_EXPORT static bool get__IsLetter(char16_t c);
- BFRT_EXPORT static bool get__IsNumber(char16_t c);
- };
- }
- }
- char32_t bf::System::Char32::get__ToLower(char32_t c)
- {
- return utf8proc_tolower(c);
- }
- char32_t bf::System::Char32::get__ToUpper(char32_t c)
- {
- return utf8proc_toupper(c);
- }
- bool bf::System::Char32::get__IsLower(char32_t c)
- {
- return utf8proc_category(c) == UTF8PROC_CATEGORY_LL;
- }
- bool bf::System::Char32::get__IsUpper(char32_t c)
- {
- return utf8proc_category(c) == UTF8PROC_CATEGORY_LU;
- }
- bool bf::System::Char32::get__IsWhiteSpace_EX(char32_t c)
- {
- auto cat = utf8proc_category(c);
- return (cat == UTF8PROC_CATEGORY_ZS) || (cat == UTF8PROC_CATEGORY_ZL) || (cat == UTF8PROC_CATEGORY_ZP);
- }
- bool bf::System::Char32::get__IsLetterOrDigit(char32_t c)
- {
- auto cat = utf8proc_category(c);
- switch (cat)
- {
- case UTF8PROC_CATEGORY_LU:
- case UTF8PROC_CATEGORY_LL:
- case UTF8PROC_CATEGORY_LT:
- case UTF8PROC_CATEGORY_LM:
- case UTF8PROC_CATEGORY_LO:
- case UTF8PROC_CATEGORY_ND:
- case UTF8PROC_CATEGORY_NL:
- case UTF8PROC_CATEGORY_NO: return true;
- default: break;
- }
- return false;
- }
- bool bf::System::Char32::get__IsLetter(char32_t c)
- {
- auto cat = utf8proc_category(c);
- switch (cat)
- {
- case UTF8PROC_CATEGORY_LU:
- case UTF8PROC_CATEGORY_LL:
- case UTF8PROC_CATEGORY_LT:
- case UTF8PROC_CATEGORY_LM:
- case UTF8PROC_CATEGORY_LO: return true;
- default: break;
- }
- return false;
- }
- bool bf::System::Char32::get__IsNumber(char32_t c)
- {
- auto cat = utf8proc_category(c);
- switch (cat)
- {
- case UTF8PROC_CATEGORY_ND:
- case UTF8PROC_CATEGORY_NL:
- case UTF8PROC_CATEGORY_NO: return true;
- default: break;
- }
- return false;
- }
- //////////////////////////////////////////////////////////////////////////
- char16_t bf::System::Char16::get__ToLower(char16_t c)
- {
- return utf8proc_tolower(c);
- }
- char16_t bf::System::Char16::get__ToUpper(char16_t c)
- {
- return utf8proc_toupper(c);
- }
- bool bf::System::Char16::get__IsLower(char16_t c)
- {
- return utf8proc_category(c) == UTF8PROC_CATEGORY_LL;
- }
- bool bf::System::Char16::get__IsUpper(char16_t c)
- {
- return utf8proc_category(c) == UTF8PROC_CATEGORY_LU;
- }
- bool bf::System::Char16::get__IsWhiteSpace(char16_t c)
- {
- return utf8proc_category(c) == UTF8PROC_CATEGORY_ZS;
- }
- bool bf::System::Char16::get__IsLetterOrDigit(char16_t c)
- {
- auto cat = utf8proc_category(c);
- switch (cat)
- {
- case UTF8PROC_CATEGORY_LU:
- case UTF8PROC_CATEGORY_LL:
- case UTF8PROC_CATEGORY_LT:
- case UTF8PROC_CATEGORY_LM:
- case UTF8PROC_CATEGORY_LO:
- case UTF8PROC_CATEGORY_ND:
- case UTF8PROC_CATEGORY_NL:
- case UTF8PROC_CATEGORY_NO: return true;
- default: break;
- }
- return false;
- }
- bool bf::System::Char16::get__IsLetter(char16_t c)
- {
- auto cat = utf8proc_category(c);
- switch (cat)
- {
- case UTF8PROC_CATEGORY_LU:
- case UTF8PROC_CATEGORY_LL:
- case UTF8PROC_CATEGORY_LT:
- case UTF8PROC_CATEGORY_LM:
- case UTF8PROC_CATEGORY_LO: return true;
- default: break;
- }
- return false;
- }
- bool bf::System::Char16::get__IsNumber(char16_t c)
- {
- auto cat = utf8proc_category(c);
- switch (cat)
- {
- case UTF8PROC_CATEGORY_ND:
- case UTF8PROC_CATEGORY_NL:
- case UTF8PROC_CATEGORY_NO: return true;
- default: break;
- }
- return false;
- }
- intptr bf::System::String::UTF8GetAllocSize(char* str, intptr strlen, int32 options)
- {
- return utf8proc_decompose_custom((const utf8proc_uint8_t*)str, strlen, NULL, 0, (utf8proc_option_t)options, NULL, NULL);
- }
- intptr bf::System::String::UTF8Map(char* str, intptr strlen, char* outStr, intptr outSize, int32 options)
- {
- intptr result = utf8proc_decompose_custom((const utf8proc_uint8_t*)str, strlen, (utf8proc_int32_t*)outStr, outSize, (utf8proc_option_t)options, NULL, NULL);
- if (result < 0)
- return result;
- result = utf8proc_reencode((utf8proc_int32_t*)outStr, outSize, (utf8proc_option_t)options);
- return result;
- }
|