Core: ToAscii optimized, ToUpperAscii, ToLowerAscii

git-svn-id: svn://ultimatepp.org/upp/trunk@12678 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2019-01-19 14:12:43 +00:00
parent b47bfa76ca
commit ad7d8a5a3e
7 changed files with 202 additions and 8 deletions

View file

@ -136,4 +136,44 @@ Vector<dword> ToUtf32(const wchar *s, int len)
return r;
}
String Utf8ToAscii(const String& src)
{
StringBuffer r(src.GetLength());
const char *s = src.begin();
const char *lim = src.end();
char *t = r;
while(s < lim)
*t++ = (byte)*s < 128 ? *s++ : ToAscii(FetchUtf8(s, lim));
r.SetLength(int(t - ~r));
return r;
}
String Utf8ToUpperAscii(const String& src)
{
StringBuffer r(src.GetLength());
const char *s = src.begin();
const char *lim = src.end();
char *t = r;
while(s < lim) {
*t++ = (byte)*s <= 'Z' ? *s++ : ToUpperAscii(FetchUtf8(s, lim));
}
r.SetLength(int(t - ~r));
return r;
}
String Utf8ToLowerAscii(const String& src)
{
StringBuffer r(src.GetLength());
const char *s = src.begin();
const char *lim = src.end();
char *t = r;
while(s < lim)
*t++ = ToLowerAscii(FetchUtf8(s, lim));
r.SetLength(int(t - ~r));
return r;
}
};