From 360e837828c244e3aaa92f794d7996c16a09703d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Fricker?= <fricker@froglogic.com> Date: Mon, 6 Aug 2012 18:42:56 +0200 Subject: [PATCH 2/2] Euro modif --- src/corelib/codecs/qlatincodec.cpp | 4 ++- tests/auto/corelib/tools/qstring/tst_qstring.cpp | 25 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletions(-) diff --git a/src/corelib/codecs/qlatincodec.cpp b/src/corelib/codecs/qlatincodec.cpp index cf7c106..bb1ee5e 100644 --- a/src/corelib/codecs/qlatincodec.cpp +++ b/src/corelib/codecs/qlatincodec.cpp @@ -66,7 +66,9 @@ QByteArray QLatin1Codec::convertFromUnicode(const QChar *ch, int len, ConverterS char *d = r.data(); int invalid = 0; for (int i = 0; i < len; ++i) { - if (ch[i] > 0xff) { + if (ch[i] == 0x20AC) { // MODIFICATION: Euro symbol handling + d[i] = 'E'; // MODIFICATION: Euro symbol handling + } else if (ch[i] > 0xff) { d[i] = replacement; ++invalid; } else { diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 7476fa0..c17b41c 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -78,6 +78,8 @@ public: public slots: void cleanup(); private slots: + void euroSym(); + void invalidUnicodeConversionToLatin1(); void fromStdString(); void toStdString(); void check_QTextIOStream(); @@ -245,7 +247,29 @@ private slots: template <class T> const T &verifyZeroTermination(const T &t) { return t; } +void tst_QString::invalidUnicodeConversionToLatin1() +{ + QTextCodec *codec = QTextCodec::codecForName("Latin1"); + QVERIFY(codec != NULL); + + QString str; + str += QChar(0x21AC); + QByteArray latin1_converted = codec->fromUnicode(str); + QCOMPARE(latin1_converted , QByteArray("?")); +} + +void tst_QString::euroSym() +{ + QTextCodec *codec = QTextCodec::codecForName("Latin1"); + QVERIFY(codec != NULL); + + QString str; + str += QChar(0x20AC); + QByteArray latin1_converted = codec->fromUnicode(str); + + QCOMPARE(latin1_converted , QByteArray("E")); +} + QString verifyZeroTermination(const QString &str) { // This test does some evil stuff, it's all supposed to work. -- 1.7.2.5 |