1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00
Beef/BeefRT/rt/Chars.cpp

202 lines
4.8 KiB
C++
Raw Normal View History

2019-08-23 11:56:54 -07:00
#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:
2020-10-23 09:02:35 -07:00
BFRT_EXPORT static bool get__IsWhiteSpace_EX__im(char32_t c);
2019-08-23 11:56:54 -07:00
public:
2020-10-23 09:02:35 -07:00
BFRT_EXPORT static char32_t get__ToLower__im(char32_t c);
BFRT_EXPORT static char32_t get__ToUpper__im(char32_t c);
BFRT_EXPORT static bool get__IsLower__im(char32_t c);
BFRT_EXPORT static bool get__IsUpper__im(char32_t c);
BFRT_EXPORT static bool get__IsLetterOrDigit__im(char32_t c);
BFRT_EXPORT static bool get__IsLetter__im(char32_t c);
BFRT_EXPORT static bool get__IsNumber__im(char32_t c);
2019-08-23 11:56:54 -07:00
};
struct Char16
{
public:
2020-10-23 09:02:35 -07:00
BFRT_EXPORT static char16_t get__ToLower__im(char16_t c);
BFRT_EXPORT static char16_t get__ToUpper__im(char16_t c);
BFRT_EXPORT static bool get__IsLower__im(char16_t c);
BFRT_EXPORT static bool get__IsUpper__im(char16_t c);
BFRT_EXPORT static bool get__IsWhiteSpace__im(char16_t c);
BFRT_EXPORT static bool get__IsLetterOrDigit__im(char16_t c);
BFRT_EXPORT static bool get__IsLetter__im(char16_t c);
BFRT_EXPORT static bool get__IsNumber__im(char16_t c);
2019-08-23 11:56:54 -07:00
};
}
}
2020-10-23 09:02:35 -07:00
char32_t bf::System::Char32::get__ToLower__im(char32_t c)
2019-08-23 11:56:54 -07:00
{
return utf8proc_tolower(c);
}
2020-10-23 09:02:35 -07:00
char32_t bf::System::Char32::get__ToUpper__im(char32_t c)
2019-08-23 11:56:54 -07:00
{
return utf8proc_toupper(c);
}
2020-10-23 09:02:35 -07:00
bool bf::System::Char32::get__IsLower__im(char32_t c)
2019-08-23 11:56:54 -07:00
{
return utf8proc_category(c) == UTF8PROC_CATEGORY_LL;
}
2020-10-23 09:02:35 -07:00
bool bf::System::Char32::get__IsUpper__im(char32_t c)
2019-08-23 11:56:54 -07:00
{
return utf8proc_category(c) == UTF8PROC_CATEGORY_LU;
}
2020-10-23 09:02:35 -07:00
bool bf::System::Char32::get__IsWhiteSpace_EX__im(char32_t c)
2019-08-23 11:56:54 -07:00
{
auto cat = utf8proc_category(c);
return (cat == UTF8PROC_CATEGORY_ZS) || (cat == UTF8PROC_CATEGORY_ZL) || (cat == UTF8PROC_CATEGORY_ZP);
}
2020-10-23 09:02:35 -07:00
bool bf::System::Char32::get__IsLetterOrDigit__im(char32_t c)
2019-08-23 11:56:54 -07:00
{
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;
2019-08-23 11:56:54 -07:00
}
return false;
}
2020-10-23 09:02:35 -07:00
bool bf::System::Char32::get__IsLetter__im(char32_t c)
2019-08-23 11:56:54 -07:00
{
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;
2019-08-23 11:56:54 -07:00
}
return false;
}
2020-10-23 09:02:35 -07:00
bool bf::System::Char32::get__IsNumber__im(char32_t c)
2019-08-23 11:56:54 -07:00
{
auto cat = utf8proc_category(c);
switch (cat)
{
case UTF8PROC_CATEGORY_ND:
case UTF8PROC_CATEGORY_NL:
case UTF8PROC_CATEGORY_NO: return true;
default: break;
2019-08-23 11:56:54 -07:00
}
return false;
}
//////////////////////////////////////////////////////////////////////////
2020-10-23 09:02:35 -07:00
char16_t bf::System::Char16::get__ToLower__im(char16_t c)
2019-08-23 11:56:54 -07:00
{
return utf8proc_tolower(c);
}
2020-10-23 09:02:35 -07:00
char16_t bf::System::Char16::get__ToUpper__im(char16_t c)
2019-08-23 11:56:54 -07:00
{
return utf8proc_toupper(c);
}
2020-10-23 09:02:35 -07:00
bool bf::System::Char16::get__IsLower__im(char16_t c)
2019-08-23 11:56:54 -07:00
{
return utf8proc_category(c) == UTF8PROC_CATEGORY_LL;
}
2020-10-23 09:02:35 -07:00
bool bf::System::Char16::get__IsUpper__im(char16_t c)
2019-08-23 11:56:54 -07:00
{
return utf8proc_category(c) == UTF8PROC_CATEGORY_LU;
}
2020-10-23 09:02:35 -07:00
bool bf::System::Char16::get__IsWhiteSpace__im(char16_t c)
2019-08-23 11:56:54 -07:00
{
return utf8proc_category(c) == UTF8PROC_CATEGORY_ZS;
}
2020-10-23 09:02:35 -07:00
bool bf::System::Char16::get__IsLetterOrDigit__im(char16_t c)
2019-08-23 11:56:54 -07:00
{
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;
2019-08-23 11:56:54 -07:00
}
return false;
}
2020-10-23 09:02:35 -07:00
bool bf::System::Char16::get__IsLetter__im(char16_t c)
2019-08-23 11:56:54 -07:00
{
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;
2019-08-23 11:56:54 -07:00
}
return false;
}
2020-10-23 09:02:35 -07:00
bool bf::System::Char16::get__IsNumber__im(char16_t c)
2019-08-23 11:56:54 -07:00
{
auto cat = utf8proc_category(c);
switch (cat)
{
case UTF8PROC_CATEGORY_ND:
case UTF8PROC_CATEGORY_NL:
case UTF8PROC_CATEGORY_NO: return true;
default: break;
2019-08-23 11:56:54 -07:00
}
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;
}