diff --git a/nel/include/nel/misc/utf_string_view.h b/nel/include/nel/misc/utf_string_view.h index 309377578..5b349a2d8 100644 --- a/nel/include/nel/misc/utf_string_view.h +++ b/nel/include/nel/misc/utf_string_view.h @@ -147,8 +147,8 @@ public: static void append(IStream &s, u32char c); static u32char get(IStream &s); - /// Get an UTF-8 string from an undefined ASCII-based codepage - static std::string fromAscii(std::string &str); + /// Get an UTF-8 string from an undefined ASCII-based codepage, without attempting to convert non-7-bit characters + static std::string fromAscii(const std::string &str); private: typedef u32char (*TIterator)(const void **addr); diff --git a/nel/src/misc/utf_string_view.cpp b/nel/src/misc/utf_string_view.cpp index dd7a88868..5fedc5328 100644 --- a/nel/src/misc/utf_string_view.cpp +++ b/nel/src/misc/utf_string_view.cpp @@ -174,11 +174,11 @@ std::string CUtfStringView::toAscii() const return res; } -std::string CUtfStringView::fromAscii(std::string &str) +std::string CUtfStringView::fromAscii(const std::string &str) { std::string res; res.reserve(str.size()); - for (std::string::iterator it(str.begin()), end(str.end()); it != end; ++it) + for (std::string::const_iterator it(str.begin()), end(str.end()); it != end; ++it) { unsigned char c = *it; if (c < 0x80) diff --git a/ryzom/client/src/interface_v3/music_player.cpp b/ryzom/client/src/interface_v3/music_player.cpp index 90eee9a0b..e211bb9d2 100644 --- a/ryzom/client/src/interface_v3/music_player.cpp +++ b/ryzom/client/src/interface_v3/music_player.cpp @@ -582,19 +582,18 @@ static void addFromPlaylist(const std::string &playlist, const std::vector= 3 && memcmp(line, utf8Header, 3) == 0) + { useUtf8 = true; + lineStr = trim(std::string(line + 3)); + } if (!useUtf8) { lineStr = NLMISC::mbcsToUtf8(line); // Attempt local codepage first if (lineStr.empty()) - lineStr = CUtfStringView::fromAscii(std::string(line)); + lineStr = CUtfStringView::fromAscii(std::string(line)); // Fallback lineStr = trim(lineStr); } - else - { - lineStr = trim(std::string(line + 3)); - } lineStr = CUtfStringView(lineStr).toUtf8(true); // Re-encode external string