develop
kaetemi 4 years ago
parent 36c676e2b2
commit f8de4aff59

@ -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);

@ -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)

@ -582,19 +582,18 @@ static void addFromPlaylist(const std::string &playlist, const std::vector<std::
// id a UTF-8 BOM header is present, parse as UTF-8
if (!useUtf8 && lineStr.length() >= 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

Loading…
Cancel
Save