[prev in list] [next in list] [prev in thread] [next in thread]
List: kopete-devel
Subject: Re: [Kopete-devel] [Bug 72917] UTF8 and other cause XML parsing
From: Martijn Klingens <klingens () kde ! org>
Date: 2004-01-23 20:03:11
Message-ID: 200401232103.11701.klingens () kde ! org
[Download RAW message or body]
On Friday 23 January 2004 20:38, Thiago Macieira wrote:
> Latin 1 decoding can't fail, so this will never be reached.
Hmm, I stated before that AFAIK it *could* fail. If both latin AND utf cannot
fail that would be both weird and annoying. Or is there also an isLatin1()
method in KStringHandler?
> What are "invalid characters" here? Those I listed below?
Yes.
> /*private*/
> QString KopeteMessage::decodeStringCodec(QCString input, QTextCodec
> *codec)
> {
> // sanity check
> if (codec == 0L)
> return QString::null;
>
> // special case: UTF-8
> // KStringHandler::isUtf8 doesn't allocate memory to validate the input
> // whereas the code below (doing encoding and decoding) is much more
> // expensive
> // Besides, this works around a Qt "misfeature" that allows the UTF-8
> // decoder decode any arbitrary input.
> if (codec->mibEnum() == 106 && !KStringHandler::isUtf8(input))
> return QString::null;
>
> QString unicode = codec->toUnicode(input);
> if (input != codec->fromUnicode(unicode))
> // decoding didn't work
> return QString::null;
>
> // now clean up: remove control characters (U+0000 to U+001F)
> // except for the line breakers
> for (int i = 0; i < unicode.length(); i++)
> if (unicode[i] < ' ' &&
> unicode[i] != '\r' && unicode[i] != '\n')
> unicode[i] = QChar::replacement;
>
> return unicode;
> }
Looks nice :)
--
Martijn
_______________________________________________
Kopete-devel mailing list
Kopete-devel@kde.org
https://mail.kde.org/mailman/listinfo/kopete-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic