diff options
author | Robin Burchell <robin+qt@viroteck.net> | 2012-01-30 14:23:22 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-22 14:00:32 +0100 |
commit | 186692f81f2612c3cf3a4090cbf949f2fb1558f8 (patch) | |
tree | e4506e520a88a1c75086516a1edeb1ab2fb4d057 /src/corelib/tools/qchar.cpp | |
parent | 9d173c92183c30144e8bd4f115b2cd93c3da0d40 (diff) |
Remove custom text codec for C strings.
This setting is extremely harmful, as code cannot know whether or not to expect
it. It also made the behaviour of QString::fromAscii and ::toAscii unintuitive,
and caused a lot of people to make mistakes with it.
Change-Id: I2f429fa7ef93bd75bb93a7f64c56db15b7283388
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/corelib/tools/qchar.cpp')
-rw-r--r-- | src/corelib/tools/qchar.cpp | 63 |
1 files changed, 16 insertions, 47 deletions
diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp index 01241dce6b..0261843a3a 100644 --- a/src/corelib/tools/qchar.cpp +++ b/src/corelib/tools/qchar.cpp @@ -413,33 +413,16 @@ QT_BEGIN_NAMESPACE */ /*! + \fn QChar::QChar(char ch) + Constructs a QChar corresponding to ASCII/Latin-1 character \a ch. */ -QChar::QChar(char ch) -{ -#ifndef QT_NO_CODEC_FOR_C_STRINGS - if (QTextCodec::codecForCStrings()) - // ##### - ucs = QTextCodec::codecForCStrings()->toUnicode(&ch, 1).at(0).unicode(); - else -#endif - ucs = uchar(ch); -} /*! + \fn QChar::QChar(uchar ch) + Constructs a QChar corresponding to ASCII/Latin-1 character \a ch. */ -QChar::QChar(uchar ch) -{ -#ifndef QT_NO_CODEC_FOR_C_STRINGS - if (QTextCodec::codecForCStrings()) { - // ##### - char c = char(ch); - ucs = QTextCodec::codecForCStrings()->toUnicode(&c, 1).at(0).unicode(); - } else -#endif - ucs = ch; -} /*! \fn QChar::QChar(uchar cell, uchar row) @@ -1256,49 +1239,35 @@ ushort QChar::toCaseFolded(ushort ucs2) Returns the Latin-1 character equivalent to the QChar, or 0. This is mainly useful for non-internationalized software. - \sa toAscii(), unicode(), QTextCodec::codecForCStrings() + \sa toAscii(), unicode() */ /*! - Returns the character value of the QChar obtained using the current - codec used to read C strings, or 0 if the character is not representable - using this codec. The default codec handles Latin-1 encoded text, - but this can be changed to assist developers writing source code using - other encodings. + \fn char QChar::toAscii() const + + Returns the Latin-1 character value of the QChar, or 0 if the character is not + representable. The main purpose of this function is to preserve ASCII characters used in C strings. This is mainly useful for developers of non-internationalized software. - \sa toLatin1(), unicode(), QTextCodec::codecForCStrings() + \note It is not possible to distinguish a non-Latin 1 character from an ASCII 0 + (NUL) character. Prefer to use unicode(), which does not have this ambiguity. + + \sa toLatin1(), unicode() */ -char QChar::toAscii() const -{ -#ifndef QT_NO_CODEC_FOR_C_STRINGS - if (QTextCodec::codecForCStrings()) - // ##### - return QTextCodec::codecForCStrings()->fromUnicode(QString(*this)).at(0); -#endif - return ucs > 0xff ? 0 : char(ucs); -} /*! + \fn QChar QChar::fromAscii(char) + Converts the ASCII character \a c to it's equivalent QChar. This is mainly useful for non-internationalized software. An alternative is to use QLatin1Char. - \sa fromLatin1(), unicode(), QTextCodec::codecForCStrings() + \sa fromLatin1(), unicode() */ -QChar QChar::fromAscii(char c) -{ -#ifndef QT_NO_CODEC_FOR_C_STRINGS - if (QTextCodec::codecForCStrings()) - // ##### - return QTextCodec::codecForCStrings()->toUnicode(&c, 1).at(0).unicode(); -#endif - return QChar(ushort((uchar)c)); -} #ifndef QT_NO_DATASTREAM /*! |