Locale-independent implementation of UTF-8 string case conversion.

This commit is contained in:
Matthias Koefferlein 2018-07-13 01:07:46 +02:00
parent 4f326572d4
commit 70a4bd7aa2
2 changed files with 6271 additions and 2 deletions

View File

@ -40,6 +40,31 @@ namespace tl
static std::locale c_locale ("C");
// -------------------------------------------------------------------------
// lower and upper case for wchar_t
#include "utf_casefolding.h"
wchar_t wdowncase (wchar_t c)
{
int ch = c >> 8;
if (ch >= 0 && ch < int (sizeof (uc_tab) / sizeof (uc_tab[0])) && uc_tab[ch]) {
return uc_tab[ch][c & 0xff];
} else {
return c;
}
}
wchar_t wupcase (wchar_t c)
{
int ch = c >> 8;
if (ch >= 0 && ch < int (sizeof (lc_tab) / sizeof (lc_tab[0])) && lc_tab[ch]) {
return lc_tab[ch][c & 0xff];
} else {
return c;
}
}
// -------------------------------------------------------------------------
// Conversion of UTF8 to wchar_t
@ -146,7 +171,7 @@ std::string to_upper_case (const std::string &s)
{
std::wstring ws = to_wstring (s);
for (std::wstring::iterator c = ws.begin (); c != ws.end (); ++c) {
*c = towupper (*c);
*c = wupcase (*c);
}
return to_string (ws);
}
@ -155,7 +180,7 @@ std::string to_lower_case (const std::string &s)
{
std::wstring ws = to_wstring (s);
for (std::wstring::iterator c = ws.begin (); c != ws.end (); ++c) {
*c = towlower (*c);
*c = wdowncase (*c);
}
return to_string (ws);
}

6244
src/tl/tl/utf_casefolding.h Normal file

File diff suppressed because it is too large Load Diff