PIString/PIChar explicit, support char16_t

This commit is contained in:
2023-07-06 19:59:26 +03:00
parent 8ad2503c5a
commit 61f1a34c14
11 changed files with 132 additions and 73 deletions

View File

@@ -90,7 +90,7 @@ int charCompare(const PIChar & f, const PIChar & s) {
if (f.isAscii() && s.isAscii()) return strncmp(f.toCharPtr(), s.toCharPtr(), 1);
return
#ifdef PIP_ICU
u_strCompare((const UChar *)f.toWCharPtr(), 1, (const UChar *)s.toWCharPtr(), 1, 0);
u_strCompare((const UChar *)f.toWCharPtr(), 1, (const UChar *)s.toWCharPtr(), 1, 0);
#else
# ifdef WINDOWS
CompareStringW(LOCALE_USER_DEFAULT, 0, (PCNZWCH)f.toWCharPtr(), 1, (PCNZWCH)s.toWCharPtr(), 1) - 2;
@@ -111,11 +111,6 @@ bool winIsCharType(const ushort * ch, int type) {
}
PIChar::PIChar(const char * c, int * bytes) {
ch = charFromCodepage(c, 4, __syslocname__, bytes);
}
PIChar PIChar::fromConsole(char c) {
PIChar ret;
ret.ch = charFromCodepage(&c, 1, __sysoemname__);
@@ -130,10 +125,20 @@ PIChar PIChar::fromSystem(char c) {
}
PIChar PIChar::fromSystem(const char * c) {
PIChar ret;
int l = 0;
while (c[l] != '\0' && l < 4)
++l;
ret.ch = charFromCodepage(c, l, __syslocname__);
return ret;
}
PIChar PIChar::fromUTF8(const char * c) {
PIChar ret;
int l = 0;
while (c[l] != '\0')
while (c[l] != '\0' && l < 4)
++l;
ret.ch = charFromCodepage(c, l, __utf8name__);
return ret;