Commit 2b8692a5 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

qt: Clean as many null characters from the end as possible

Not only one

Fixes KDE bug #425791
parent 4febe9d3
...@@ -77,8 +77,8 @@ QString unicodeToQString(const Unicode *u, int len) ...@@ -77,8 +77,8 @@ QString unicodeToQString(const Unicode *u, int len)
{ {
const UnicodeMap *utf8Map = globalParams->getUtf8Map(); const UnicodeMap *utf8Map = globalParams->getUtf8Map();
// ignore the last character if it is 0x0 // ignore the last characters if they are 0x0
if ((len > 0) && (u[len - 1] == 0)) { while ((len > 0) && (u[len - 1] == 0)) {
--len; --len;
} }
......
...@@ -114,6 +114,15 @@ void TestStrings::check_unicodeToQString_data() ...@@ -114,6 +114,15 @@ void TestStrings::check_unicodeToQString_data()
u[2] = 0x0; u[2] = 0x0;
QTest::newRow("\xe5\xb0\x81\xe9\x9d\xa2 + 0") << u << l << QStringLiteral("封面"); QTest::newRow("\xe5\xb0\x81\xe9\x9d\xa2 + 0") << u << l << QStringLiteral("封面");
} }
{
const int l = 4;
Unicode *u = new Unicode[l];
u[0] = 0x5c01;
u[1] = 0x9762;
u[2] = 0x0;
u[3] = 0x0;
QTest::newRow("\xe5\xb0\x81\xe9\x9d\xa2 + two 0") << u << l << QStringLiteral("封面");
}
} }
void TestStrings::check_unicodeToQString() void TestStrings::check_unicodeToQString()
......
...@@ -77,8 +77,8 @@ QString unicodeToQString(const Unicode *u, int len) ...@@ -77,8 +77,8 @@ QString unicodeToQString(const Unicode *u, int len)
{ {
const UnicodeMap *utf8Map = globalParams->getUtf8Map(); const UnicodeMap *utf8Map = globalParams->getUtf8Map();
// ignore the last character if it is 0x0 // ignore the last characters if they are 0x0
if ((len > 0) && (u[len - 1] == 0)) { while ((len > 0) && (u[len - 1] == 0)) {
--len; --len;
} }
......
...@@ -114,6 +114,15 @@ void TestStrings::check_unicodeToQString_data() ...@@ -114,6 +114,15 @@ void TestStrings::check_unicodeToQString_data()
u[2] = 0x0; u[2] = 0x0;
QTest::newRow("\xe5\xb0\x81\xe9\x9d\xa2 + 0") << u << l << QStringLiteral("封面"); QTest::newRow("\xe5\xb0\x81\xe9\x9d\xa2 + 0") << u << l << QStringLiteral("封面");
} }
{
const int l = 4;
Unicode *u = new Unicode[l];
u[0] = 0x5c01;
u[1] = 0x9762;
u[2] = 0x0;
u[3] = 0x0;
QTest::newRow("\xe5\xb0\x81\xe9\x9d\xa2 + two 0") << u << l << QStringLiteral("封面");
}
} }
void TestStrings::check_unicodeToQString() void TestStrings::check_unicodeToQString()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment