From 1ec9f16de45311388ee8eb215f662d49f6513997 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 28 Oct 2020 08:26:53 +0800 Subject: [PATCH] Get rid of useless raw copy in ucstring, default to UTF-8, ryzom/ryzomcore#335 --- nel/include/nel/misc/ucstring.h | 4 +--- nel/src/misc/ucstring.cpp | 22 +--------------------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/nel/include/nel/misc/ucstring.h b/nel/include/nel/misc/ucstring.h index 5b7597f00..61f7f416b 100644 --- a/nel/include/nel/misc/ucstring.h +++ b/nel/include/nel/misc/ucstring.h @@ -50,7 +50,7 @@ public: ucstring(const std::string &str) : ucstringbase() { - rawCopy(str); + fromUtf8(str); } ~ucstring() { } @@ -171,8 +171,6 @@ public: return ret; } -private: - void rawCopy(const std::string &str); }; inline ucstring operator+(const ucstringbase &ucstr, ucchar c) diff --git a/nel/src/misc/ucstring.cpp b/nel/src/misc/ucstring.cpp index 79cf78f7e..05c0d24ab 100644 --- a/nel/src/misc/ucstring.cpp +++ b/nel/src/misc/ucstring.cpp @@ -20,14 +20,7 @@ void ucstring::toString(std::string &str) const { - str.resize(size()); - for (uint i = 0; i < str.size(); i++) - { - if (operator[](i) > 255) - str[i] = '?'; - else - str[i] = (char)operator[](i); - } + str = nlmove(NLMISC::CUtfStringView(*this).toUtf8()); } std::string ucstring::toUtf8() const @@ -40,17 +33,4 @@ void ucstring::fromUtf8(const std::string &stringUtf8) *this = NLMISC::CUtfStringView(stringUtf8).toUtf16(); } -void ucstring::rawCopy(const std::string &str) -{ - // We need to convert the char into 8bits unsigned int before promotion to 16 bits - // otherwise, as char are signed on some compiler (MSCV for ex), the sign bit is extended to 16 bits. - resize(str.size()); - std::string::const_iterator first(str.begin()), last(str.end()); - iterator dest(begin()); - for (; first != last; ++first, ++dest) - { - *dest = uint8(*first); - } -} - /* end of file */