From 506f9f26bde74fe3c82f71bb4aaaf5e493c1fcdf Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 28 Oct 2020 15:07:41 +0800 Subject: [PATCH] Change CViewText to UTF-8, ryzom/ryzomcore#335 --- nel/include/nel/misc/common.h | 8 ++++---- nel/include/nel/misc/ucstring.h | 6 ++++++ nel/src/gui/string_case.cpp | 4 ++-- nel/src/misc/common.cpp | 4 ---- nel/src/misc/unicode.cpp | 24 ++++++++++++------------ 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/nel/include/nel/misc/common.h b/nel/include/nel/misc/common.h index 7b89bae3b..2f678acef 100644 --- a/nel/include/nel/misc/common.h +++ b/nel/include/nel/misc/common.h @@ -227,8 +227,8 @@ inline double isValidDouble (double v) * \param str a string to transform to lower case */ -std::string toLower ( const char *str ); // UTF-8 -std::string toLower ( const std::string &str ); // UTF-8 +std::string toLower ( const char *str ); // Ascii only +std::string toLower ( const std::string &str ); // Ascii only void toLower ( char *str ); // Ascii only char toLower ( const char ch ); // convert only one character @@ -236,8 +236,8 @@ char toLower ( const char ch ); // convert only one character * \param a string to transform to upper case */ -std::string toUpper ( const char *str ); // UTF-8 -std::string toUpper ( const std::string &str); // UTF-8 +// std::string toUpper ( const char *str ); // Ascii only +std::string toUpper ( const std::string &str); // Ascii only void toUpper ( char *str); // Ascii only diff --git a/nel/include/nel/misc/ucstring.h b/nel/include/nel/misc/ucstring.h index 61f7f416b..8bbcd828d 100644 --- a/nel/include/nel/misc/ucstring.h +++ b/nel/include/nel/misc/ucstring.h @@ -260,6 +260,12 @@ ucstring toUpper(const ucstring &str); void toUpper(ucchar *str); ucchar toUpper(ucchar c); +std::string toLowerAsUtf8(const char *str); +std::string toLowerAsUtf8(const std::string &str); + +std::string toUpperAsUtf8(const char *str); +std::string toUpperAsUtf8(const std::string &str); + }; #endif // NL_UCSTRING_H diff --git a/nel/src/gui/string_case.cpp b/nel/src/gui/string_case.cpp index f6218d39a..d970d1e03 100644 --- a/nel/src/gui/string_case.cpp +++ b/nel/src/gui/string_case.cpp @@ -148,10 +148,10 @@ namespace NLGUI switch (mode) { case CaseLower: - str = NLMISC::toLower(str); + str = NLMISC::toLowerAsUtf8(str); break; case CaseUpper: - str = NLMISC::toUpper(str); + str = NLMISC::toUpperAsUtf8(str); break; case CaseFirstStringLetterUp: { diff --git a/nel/src/misc/common.cpp b/nel/src/misc/common.cpp index c1bf67efa..b9e9a7d85 100644 --- a/nel/src/misc/common.cpp +++ b/nel/src/misc/common.cpp @@ -594,7 +594,6 @@ NLMISC_CATEGORISED_COMMAND(nel,stohr, "Convert a second number into an human rea return true; } -/* std::string toLower(const char *str) { if (!str) return ""; @@ -625,7 +624,6 @@ std::string toLower(const std::string &str) } return res; } -*/ char toLower(const char ch) { @@ -654,7 +652,6 @@ void toLower(char *str) } } -/* std::string toUpper(const std::string &str) { string res; @@ -668,7 +665,6 @@ std::string toUpper(const std::string &str) } return res; } -*/ void toUpper(char *str) { diff --git a/nel/src/misc/unicode.cpp b/nel/src/misc/unicode.cpp index 12dfdcad4..6a0bf25c0 100644 --- a/nel/src/misc/unicode.cpp +++ b/nel/src/misc/unicode.cpp @@ -1950,7 +1950,7 @@ ucchar toLower (ucchar c) // *************************************************************************** -static std::string toLower(CUtfStringView sv) +static std::string toLowerAsUtf8(CUtfStringView sv) { std::string res; res.reserve(sv.largestSize()); @@ -1962,23 +1962,23 @@ static std::string toLower(CUtfStringView sv) ucchar uc = c; ucchar *result = toLowerUpperSearch(&uc, UnicodeUpperToLower); if (result) - c = uc; + c = result[1]; } CUtfStringView::append(res, c); } return res; } -std::string toLower(const char *str) +std::string toLowerAsUtf8(const char *str) { - return toLower(CUtfStringView(str)); + return toLowerAsUtf8(CUtfStringView(str)); } // *************************************************************************** -std::string toLower(const std::string &str) +std::string toLowerAsUtf8(const std::string &str) { - return toLower(CUtfStringView(str)); + return toLowerAsUtf8(CUtfStringView(str)); } // *************************************************************************** @@ -2025,7 +2025,7 @@ ucchar toUpper (ucchar c) // *************************************************************************** -static std::string toUpper(CUtfStringView sv) +static std::string toUpperAsUtf8(CUtfStringView sv) { std::string res; res.reserve(sv.largestSize()); @@ -2037,23 +2037,23 @@ static std::string toUpper(CUtfStringView sv) ucchar uc = c; ucchar *result = toLowerUpperSearch(&uc, UnicodeLowerToUpper); if (result) - c = uc; + c = result[1]; } CUtfStringView::append(res, c); } return res; } -std::string toUpper(const char *str) +std::string toUpperAsUtf8(const char *str) { - return toUpper(CUtfStringView(str)); + return toUpperAsUtf8(CUtfStringView(str)); } // *************************************************************************** -std::string toUpper(const std::string &str) +std::string toUpperAsUtf8(const std::string &str) { - return toUpper(CUtfStringView(str)); + return toUpperAsUtf8(CUtfStringView(str)); } // ***************************************************************************