summaryrefslogtreecommitdiffstats
path: root/src/corelib/codecs
diff options
context:
space:
mode:
authorQt by Nokia <qt-info@nokia.com>2011-04-27 12:05:43 +0200
committeraxis <qt-info@nokia.com>2011-04-27 12:05:43 +0200
commit38be0d13830efd2d98281c645c3a60afe05ffece (patch)
tree6ea73f3ec77f7d153333779883e8120f82820abe /src/corelib/codecs
Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
Diffstat (limited to 'src/corelib/codecs')
-rw-r--r--src/corelib/codecs/codecs.pri59
-rw-r--r--src/corelib/codecs/codecs.qdoc532
-rw-r--r--src/corelib/codecs/qfontlaocodec.cpp123
-rw-r--r--src/corelib/codecs/qfontlaocodec_p.h78
-rw-r--r--src/corelib/codecs/qiconvcodec.cpp548
-rw-r--r--src/corelib/codecs/qiconvcodec_p.h104
-rw-r--r--src/corelib/codecs/qisciicodec.cpp285
-rw-r--r--src/corelib/codecs/qisciicodec_p.h81
-rw-r--r--src/corelib/codecs/qlatincodec.cpp244
-rw-r--r--src/corelib/codecs/qlatincodec_p.h94
-rw-r--r--src/corelib/codecs/qsimplecodec.cpp735
-rw-r--r--src/corelib/codecs/qsimplecodec_p.h91
-rw-r--r--src/corelib/codecs/qtextcodec.cpp1878
-rw-r--r--src/corelib/codecs/qtextcodec.h198
-rw-r--r--src/corelib/codecs/qtextcodec_p.h111
-rw-r--r--src/corelib/codecs/qtextcodec_symbian.cpp689
-rw-r--r--src/corelib/codecs/qtextcodecplugin.cpp161
-rw-r--r--src/corelib/codecs/qtextcodecplugin.h96
-rw-r--r--src/corelib/codecs/qtsciicodec.cpp498
-rw-r--r--src/corelib/codecs/qtsciicodec_p.h106
-rw-r--r--src/corelib/codecs/qutfcodec.cpp670
-rw-r--r--src/corelib/codecs/qutfcodec_p.h170
22 files changed, 7551 insertions, 0 deletions
diff --git a/src/corelib/codecs/codecs.pri b/src/corelib/codecs/codecs.pri
new file mode 100644
index 0000000000..46d7dd46da
--- /dev/null
+++ b/src/corelib/codecs/codecs.pri
@@ -0,0 +1,59 @@
+# Qt core library codecs module
+
+HEADERS += \
+ codecs/qisciicodec_p.h \
+ codecs/qlatincodec_p.h \
+ codecs/qsimplecodec_p.h \
+ codecs/qtextcodec_p.h \
+ codecs/qtextcodec.h \
+ codecs/qtsciicodec_p.h \
+ codecs/qutfcodec_p.h \
+ codecs/qtextcodecplugin.h
+
+SOURCES += \
+ codecs/qisciicodec.cpp \
+ codecs/qlatincodec.cpp \
+ codecs/qsimplecodec.cpp \
+ codecs/qtextcodec.cpp \
+ codecs/qtsciicodec.cpp \
+ codecs/qutfcodec.cpp \
+ codecs/qtextcodecplugin.cpp
+
+unix {
+ SOURCES += codecs/qfontlaocodec.cpp
+
+ contains(QT_CONFIG,iconv) {
+ HEADERS += codecs/qiconvcodec_p.h
+ SOURCES += codecs/qiconvcodec.cpp
+ } else:contains(QT_CONFIG,gnu-libiconv) {
+ HEADERS += codecs/qiconvcodec_p.h
+ SOURCES += codecs/qiconvcodec.cpp
+
+ DEFINES += GNU_LIBICONV
+ !mac:LIBS_PRIVATE *= -liconv
+ } else:contains(QT_CONFIG,sun-libiconv) {
+ HEADERS += codecs/qiconvcodec_p.h
+ SOURCES += codecs/qiconvcodec.cpp
+ DEFINES += GNU_LIBICONV
+ } else:!symbian {
+ # no iconv, so we put all plugins in the library
+ HEADERS += \
+ ../plugins/codecs/cn/qgb18030codec.h \
+ ../plugins/codecs/jp/qeucjpcodec.h \
+ ../plugins/codecs/jp/qjiscodec.h \
+ ../plugins/codecs/jp/qsjiscodec.h \
+ ../plugins/codecs/kr/qeuckrcodec.h \
+ ../plugins/codecs/tw/qbig5codec.h \
+ ../plugins/codecs/jp/qfontjpcodec.h
+ SOURCES += \
+ ../plugins/codecs/cn/qgb18030codec.cpp \
+ ../plugins/codecs/jp/qjpunicode.cpp \
+ ../plugins/codecs/jp/qeucjpcodec.cpp \
+ ../plugins/codecs/jp/qjiscodec.cpp \
+ ../plugins/codecs/jp/qsjiscodec.cpp \
+ ../plugins/codecs/kr/qeuckrcodec.cpp \
+ ../plugins/codecs/tw/qbig5codec.cpp \
+ ../plugins/codecs/jp/qfontjpcodec.cpp
+ }
+}
+symbian:LIBS += -lcharconv
diff --git a/src/corelib/codecs/codecs.qdoc b/src/corelib/codecs/codecs.qdoc
new file mode 100644
index 0000000000..c88f073f28
--- /dev/null
+++ b/src/corelib/codecs/codecs.qdoc
@@ -0,0 +1,532 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of this
+** file.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \group codecs
+ \title Codecs
+ \ingroup groups
+ \brief Codec support in Qt.
+
+ These codecs provide facilities for conversion between Unicode and
+ specific text encodings.
+
+ \generatelist{related}
+*/
+
+/*!
+ \page codec-big5.html
+ \title Big5 Text Codec
+ \ingroup codecs
+
+ The Big5 codec provides conversion to and from the Big5 encoding.
+ The code was originally contributed by Ming-Che Chuang
+ \<mingche@cobra.ee.ntu.edu.tw\> for the Big-5+ encoding, and was
+ included in Qt with the author's permission, and the grateful
+ thanks of the Qt team. (Note: Ming-Che's code is QPL'd, as
+ per an mail to qt-info@nokia.com.)
+
+ However, since Big-5+ was never formally approved, and was never
+ used by anyone, the Taiwan Free Software community and the Li18nux
+ Big5 Standard Subgroup agree that the de-facto standard Big5-ETen
+ (zh_TW.Big5 or zh_TW.TW-Big5) be used instead.
+
+ The Big5 is currently implemented as a pure subset of the
+ Big5-HKSCS codec, so more fine-tuning is needed to make it
+ identical to the standard Big5 mapping as determined by
+ Li18nux-Big5. See \l{http://www.autrijus.org/xml/} for the draft
+ Big5 (2002) standard.
+
+ James Su \<suzhe@turbolinux.com.cn\> \<suzhe@gnuchina.org\>
+ generated the Big5-HKSCS-to-Unicode tables with a very
+ space-efficient algorithm. He generously donated his code to glibc
+ in May 2002. Subsequently, James has kindly allowed Anthony Fok
+ \<anthony@thizlinux.com\> \<foka@debian.org\> to adapt the code
+ for Qt.
+
+ \legalese
+ Copyright (C) 2000 Ming-Che Chuang \BR
+ Copyright (C) 2002 James Su, Turbolinux Inc. \BR
+ Copyright (C) 2002 Anthony Fok, ThizLinux Laboratory Ltd.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ \list 1
+ \o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ \o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ \endlist
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+ \endlegalese
+*/
+
+/*!
+ \page codec-big5hkscs.html
+ \title Big5-HKSCS Text Codec
+ \ingroup codecs
+
+ The Big5-HKSCS codec provides conversion to and from the
+ Big5-HKSCS encoding.
+
+ The codec grew out of the QBig5Codec originally contributed by
+ Ming-Che Chuang \<mingche@cobra.ee.ntu.edu.tw\>. James Su
+ \<suzhe@turbolinux.com.cn\> \<suzhe@gnuchina.org\> and Anthony Fok
+ \<anthony@thizlinux.com\> \<foka@debian.org\> implemented HKSCS-1999
+ QBig5hkscsCodec for Qt-2.3.x, but it was too late in Qt development
+ schedule to be officially included in the Qt-2.3.x series.
+
+ Wu Yi \<wuyi@hancom.com\> ported the HKSCS-1999 QBig5hkscsCodec to
+ Qt-3.0.1 in March 2002.
+
+ With the advent of the new HKSCS-2001 standard, James Su
+ \<suzhe@turbolinux.com.cn\> \<suzhe@gnuchina.org\> generated the
+ Big5-HKSCS<->Unicode tables with a very space-efficient algorithm.
+ He generously donated his code to glibc in May 2002. Subsequently,
+ James has generously allowed Anthony Fok to adapt the code for
+ Qt-3.0.5.
+
+ Currently, the Big5-HKSCS tables are generated from the following
+ sources, and with the Euro character added:
+ \list 1
+ \o \l{http://www.microsoft.com/typography/unicode/950.txt}
+ \o \l{http://www.info.gov.hk/digital21/chi/hkscs/download/big5-iso.txt}
+ \o \l{http://www.info.gov.hk/digital21/chi/hkscs/download/big5cmp.txt}
+ \endlist
+
+ There may be more fine-tuning to the QBig5hkscsCodec to maximize its
+ compatibility with the standard Big5 (2002) mapping as determined by
+ Li18nux Big5 Standard Subgroup. See \l{http://www.autrijus.org/xml/}
+ for the various Big5 CharMapML tables.
+
+ \legalese
+ Copyright (C) 2000 Ming-Che Chuang \BR
+ Copyright (C) 2001, 2002 James Su, Turbolinux Inc. \BR
+ Copyright (C) 2002 WU Yi, HancomLinux Inc. \BR
+ Copyright (C) 2001, 2002 Anthony Fok, ThizLinux Laboratory Ltd.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ \list 1
+ \o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ \o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ \endlist
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+ \endlegalese
+*/
+
+/*!
+ \page codec-eucjp.html
+ \title EUC-JP Text Codec
+ \ingroup codecs
+
+ The EUC-JP codec provides conversion to and from EUC-JP, the main
+ legacy encoding for Unix machines in Japan.
+
+ The environment variable \c UNICODEMAP_JP can be used to
+ fine-tune the JIS, Shift-JIS, and EUC-JP codecs. The \l{ISO
+ 2022-JP (JIS) Text Codec} documentation describes how to use this
+ variable.
+
+ Most of the code here was written by Serika Kurusugawa,
+ a.k.a. Junji Takagi, and is included in Qt with the author's
+ permission and the grateful thanks of the Qt team. Here is
+ the copyright statement for that code:
+
+ \legalese
+
+ Copyright (C) 1999 Serika Kurusugawa. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ \list 1
+ \o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ \o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ \endlist
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS".
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+ \endlegalese
+*/
+
+/*!
+ \page codec-euckr.html
+ \title EUC-KR Text Codec
+ \ingroup codecs
+
+ The EUC-KR codec provides conversion to and from EUC-KR, KR, the
+ main legacy encoding for Unix machines in Korea.
+
+ It was largely written by Mizi Research Inc. Here is the
+ copyright statement for the code as it was at the point of
+ contribution. The subsequent modifications are covered by
+ the usual copyright for Qt.
+
+ \legalese
+
+ Copyright (C) 1999-2000 Mizi Research Inc. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ \list 1
+ \o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ \o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ \endlist
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+ \endlegalese
+*/
+
+/*!
+ \page codec-gbk.html
+ \title GBK Text Codec
+ \ingroup codecs
+
+ The GBK codec provides conversion to and from the Chinese
+ GB18030/GBK/GB2312 encoding.
+
+ GBK, formally the Chinese Internal Code Specification, is a commonly
+ used extension of GB 2312-80. Microsoft Windows uses it under the
+ name codepage 936.
+
+ GBK has been superseded by the new Chinese national standard
+ GB 18030-2000, which added a 4-byte encoding while remaining
+ compatible with GB2312 and GBK. The new GB 18030-2000 may be described
+ as a special encoding of Unicode 3.x and ISO-10646-1.
+
+ Special thanks to charset gurus Markus Scherer (IBM),
+ Dirk Meyer (Adobe Systems) and Ken Lunde (Adobe Systems) for publishing
+ an excellent GB 18030-2000 summary and specification on the Internet.
+ Some must-read documents are:
+
+ \list
+ \o \l{ftp://ftp.oreilly.com/pub/examples/nutshell/cjkv/pdf/GB18030_Summary.pdf}
+ \o \l{http://oss.software.ibm.com/cvs/icu/~checkout~/charset/source/gb18030/gb18030.html}
+ \o \l{http://oss.software.ibm.com/cvs/icu/~checkout~/charset/data/xml/gb-18030-2000.xml}
+ \endlist
+
+ The GBK codec was contributed to Qt by
+ Justin Yu \<justiny@turbolinux.com.cn\> and
+ Sean Chen \<seanc@turbolinux.com.cn\>. They may also be reached at
+ Yu Mingjian \<yumj@sun.ihep.ac.cn\>, \<yumingjian@china.com\>
+ Chen Xiangyang \<chenxy@sun.ihep.ac.cn\>
+
+ The GB18030 codec Qt functions were contributed to Qt by
+ James Su \<suzhe@gnuchina.org\>, \<suzhe@turbolinux.com.cn\>
+ who pioneered much of GB18030 development on GNU/Linux systems.
+
+ The GB18030 codec was contributed to Qt by
+ Anthony Fok \<anthony@thizlinux.com\>, \<foka@debian.org\>
+ using a Perl script to generate C++ tables from gb-18030-2000.xml
+ while merging contributions from James Su, Justin Yu and Sean Chen.
+ A copy of the source Perl script is available at
+ \l{http://people.debian.org/~foka/gb18030/gen-qgb18030codec.pl}
+
+ The copyright notice for their code follows:
+
+ \legalese
+ Copyright (C) 2000 TurboLinux, Inc. Written by Justin Yu and Sean Chen. \BR
+ Copyright (C) 2001, 2002 Turbolinux, Inc. Written by James Su. \BR
+ Copyright (C) 2001, 2002 ThizLinux Laboratory Ltd. Written by Anthony Fok.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ \list 1
+ \o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ \o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ \endlist
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+ \endlegalese
+*/
+
+/*!
+ \page codecs-jis.html
+ \title ISO 2022-JP (JIS) Text Codec
+ \ingroup codecs
+
+ The JIS codec provides conversion to and from ISO 2022-JP.
+
+ The environment variable \c UNICODEMAP_JP can be used to
+ fine-tune the JIS, Shift-JIS, and EUC-JP codecs. The mapping
+ names are as for the Japanese XML working group's \link
+ http://www.y-adagio.com/public/standards/tr_xml_jpf/toc.htm XML
+ Japanese Profile\endlink, because it names and explains all the
+ widely used mappings. Here are brief descriptions, written by
+ Serika Kurusugawa:
+
+ \list
+
+ \o "unicode-0.9" or "unicode-0201" for Unicode style. This assumes
+ JISX0201 for 0x00-0x7f. (0.9 is a table version of jisx02xx mapping
+ used for Unicode 1.1.)
+
+ \o "unicode-ascii" This assumes US-ASCII for 0x00-0x7f; some
+ chars (JISX0208 0x2140 and JISX0212 0x2237) are different from
+ Unicode 1.1 to avoid conflict.
+
+ \o "open-19970715-0201" ("open-0201" for convenience) or
+ "jisx0221-1995" for JISX0221-JISX0201 style. JIS X 0221 is JIS
+ version of Unicode, but a few chars (0x5c, 0x7e, 0x2140, 0x216f,
+ 0x2131) are different from Unicode 1.1. This is used when 0x5c is
+ treated as YEN SIGN.
+
+ \o "open-19970715-ascii" ("open-ascii" for convenience) for
+ JISX0221-ASCII style. This is used when 0x5c is treated as REVERSE
+ SOLIDUS.
+
+ \o "open-19970715-ms" ("open-ms" for convenience) or "cp932" for
+ Microsoft Windows style. Windows Code Page 932. Some chars (0x2140,
+ 0x2141, 0x2142, 0x215d, 0x2171, 0x2172) are different from Unicode
+ 1.1.
+
+ \o "jdk1.1.7" for Sun's JDK style. Same as Unicode 1.1, except that
+ JIS 0x2140 is mapped to UFF3C. Either ASCII or JISX0201 can be used
+ for 0x00-0x7f.
+
+ \endlist
+
+ In addition, the extensions "nec-vdc", "ibm-vdc" and "udc" are
+ supported.
+
+ For example, if you want to use Unicode style conversion but with
+ NEC's extension, set \c UNICODEMAP_JP to \c {unicode-0.9,
+ nec-vdc}. (You will probably need to quote that in a shell
+ command.)
+
+ Most of the code here was written by Serika Kurusugawa,
+ a.k.a. Junji Takagi, and is included in Qt with the author's
+ permission and the grateful thanks of the Qt team. Here is
+ the copyright statement for that code:
+
+ \legalese
+
+ Copyright (C) 1999 Serika Kurusugawa. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ \list 1
+ \o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ \o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ \endlist
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS".
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+ \endlegalese
+*/
+
+/*!
+ \page codec-sjis.html
+ \title Shift-JIS Text Codec
+ \ingroup codecs
+
+ The Shift-JIS codec provides conversion to and from Shift-JIS, an
+ encoding of JIS X 0201 Latin, JIS X 0201 Kana and JIS X 0208.
+
+ The environment variable \c UNICODEMAP_JP can be used to
+ fine-tune the codec. The \l{ISO 2022-JP (JIS) Text Codec}
+ documentation describes how to use this variable.
+
+ Most of the code here was written by Serika Kurusugawa, a.k.a.
+ Junji Takagi, and is included in Qt with the author's permission
+ and the grateful thanks of the Qt team. Here is the
+ copyright statement for the code as it was at the point of
+ contribution. The subsequent modifications are covered by
+ the usual copyright for Qt.
+
+ \legalese
+
+ Copyright (C) 1999 Serika Kurusugawa. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ \list 1
+ \o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ \o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ \endlist
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS".
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+ \endlegalese
+*/
+
+/*!
+ \page codec-tscii.html
+ \title TSCII Text Codec
+ \ingroup codecs
+
+ The TSCII codec provides conversion to and from the Tamil TSCII
+ encoding.
+
+ TSCII, formally the Tamil Standard Code Information Interchange
+ specification, is a commonly used charset for Tamils. The
+ official page for the standard is at
+ \link http://www.tamil.net/tscii/ http://www.tamil.net/tscii/\endlink
+
+ This codec uses the mapping table found at
+ \link http://www.geocities.com/Athens/5180/tsciiset.html
+ http://www.geocities.com/Athens/5180/tsciiset.html\endlink.
+ Tamil uses composed Unicode which might cause some
+ problems if you are using Unicode fonts instead of TSCII fonts.
+
+ Most of the code was written by Hans Petter Bieker and is
+ included in Qt with the author's permission and the grateful
+ thanks of the Qt team. Here is the copyright statement for
+ the code as it was at the point of contribution. The
+ subsequent modifications are covered by the usual copyright for
+ Qt:
+
+ \legalese
+
+ Copyright (c) 2000 Hans Petter Bieker. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ \list 1
+ \o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ \o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ \endlist
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+ \endlegalese
+*/
diff --git a/src/corelib/codecs/qfontlaocodec.cpp b/src/corelib/codecs/qfontlaocodec.cpp
new file mode 100644
index 0000000000..981492c54a
--- /dev/null
+++ b/src/corelib/codecs/qfontlaocodec.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qfontlaocodec_p.h"
+#include "qlist.h"
+
+#ifndef QT_NO_CODECS
+#ifndef QT_NO_BIG_CODECS
+
+QT_BEGIN_NAMESPACE
+
+static unsigned char const unicode_to_mulelao[256] =
+ {
+ // U+0E80
+ 0x00, 0xa1, 0xa2, 0x00, 0xa4, 0x00, 0x00, 0xa7,
+ 0xa8, 0x00, 0xaa, 0x00, 0x00, 0xad, 0x00, 0x00,
+ // U+0E90
+ 0x00, 0x00, 0x00, 0x00, 0xb4, 0xb5, 0xb6, 0xb7,
+ 0x00, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
+ // U+0EA0
+ 0x00, 0xc1, 0xc2, 0xc3, 0x00, 0xc5, 0x00, 0xc7,
+ 0x00, 0x00, 0xca, 0xcb, 0x00, 0xcd, 0xce, 0xcf,
+ // U+0EB0
+ 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
+ 0xd8, 0xd9, 0x00, 0xdb, 0xdc, 0xdd, 0x00, 0x00,
+ // U+0EC0
+ 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0x00, 0xe6, 0x00,
+ 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0x00, 0x00,
+ // U+0ED0
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0x00, 0x00, 0xfc, 0xfd, 0x00, 0x00,
+ // U+0EE0
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ // U+0EF0
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ };
+
+
+QFontLaoCodec::~QFontLaoCodec()
+{
+}
+
+QByteArray QFontLaoCodec::name() const
+{
+ return "mulelao-1";
+}
+
+int QFontLaoCodec::mibEnum() const
+{
+ return -4242;
+}
+
+QString QFontLaoCodec::convertToUnicode(const char *, int, ConverterState *) const
+{
+ return QString();
+}
+
+QByteArray QFontLaoCodec::convertFromUnicode(const QChar *uc, int len, ConverterState *) const
+{
+ QByteArray rstring(len, Qt::Uninitialized);
+ uchar *rdata = (uchar *) rstring.data();
+ const QChar *sdata = uc;
+ int i = 0;
+ for (; i < len; ++i, ++sdata, ++rdata) {
+ if (sdata->unicode() < 0x80) {
+ *rdata = (uchar) sdata->unicode();
+ } else if (sdata->unicode() >= 0x0e80 && sdata->unicode() <= 0x0eff) {
+ uchar lao = unicode_to_mulelao[sdata->unicode() - 0x0e80];
+ if (lao)
+ *rdata = lao;
+ else
+ *rdata = 0;
+ } else {
+ *rdata = 0;
+ }
+ }
+ return rstring;
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_BIG_CODECS
+#endif // QT_NO_CODECS
diff --git a/src/corelib/codecs/qfontlaocodec_p.h b/src/corelib/codecs/qfontlaocodec_p.h
new file mode 100644
index 0000000000..7d0c957f27
--- /dev/null
+++ b/src/corelib/codecs/qfontlaocodec_p.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QFONTLAOCODEC_P_H
+#define QFONTLAOCODEC_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of qfontencodings_x11.cpp and qfont_x11.cpp. This header file may
+// change from version to version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "QtCore/qtextcodec.h"
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_CODECS
+
+class Q_CORE_EXPORT QFontLaoCodec : public QTextCodec
+{
+public:
+ ~QFontLaoCodec();
+
+ QByteArray name() const;
+ int mibEnum() const;
+
+ QString convertToUnicode(const char *, int, ConverterState *) const;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+};
+
+#endif // QT_NO_CODECS
+
+QT_END_NAMESPACE
+
+#endif // QFONTLAOCODEC_P_H
diff --git a/src/corelib/codecs/qiconvcodec.cpp b/src/corelib/codecs/qiconvcodec.cpp
new file mode 100644
index 0000000000..053b3d2834
--- /dev/null
+++ b/src/corelib/codecs/qiconvcodec.cpp
@@ -0,0 +1,548 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qiconvcodec_p.h"
+#include "qtextcodec_p.h"
+#include <qlibrary.h>
+#include <qdebug.h>
+#include <qthreadstorage.h>
+
+#include <errno.h>
+#include <locale.h>
+#include <stdio.h>
+#include <dlfcn.h>
+
+// unistd.h is needed for the _XOPEN_UNIX macro
+#include <unistd.h>
+#if defined(_XOPEN_UNIX) && !defined(Q_OS_QNX) && !defined(Q_OS_OSF)
+# include <langinfo.h>
+#endif
+
+#if defined(Q_OS_HPUX)
+# define NO_BOM
+# define UTF16 "ucs2"
+#elif defined(Q_OS_AIX)
+# define NO_BOM
+# define UTF16 "UCS-2"
+#elif defined(Q_OS_FREEBSD) || defined(Q_OS_MAC)
+# define NO_BOM
+# if Q_BYTE_ORDER == Q_BIG_ENDIAN
+# define UTF16 "UTF-16BE"
+# else
+# define UTF16 "UTF-16LE"
+# endif
+#else
+# define UTF16 "UTF-16"
+#endif
+
+#if defined(Q_OS_MAC)
+#ifndef GNU_LIBICONV
+#define GNU_LIBICONV
+#endif
+typedef iconv_t (*Ptr_iconv_open) (const char*, const char*);
+typedef size_t (*Ptr_iconv) (iconv_t, const char **, size_t *, char **, size_t *);
+typedef int (*Ptr_iconv_close) (iconv_t);
+
+static Ptr_iconv_open ptr_iconv_open = 0;
+static Ptr_iconv ptr_iconv = 0;
+static Ptr_iconv_close ptr_iconv_close = 0;
+#endif
+
+QT_BEGIN_NAMESPACE
+
+extern bool qt_locale_initialized;
+
+QIconvCodec::QIconvCodec()
+ : utf16Codec(0)
+{
+ utf16Codec = QTextCodec::codecForMib(1015);
+ Q_ASSERT_X(utf16Codec != 0,
+ "QIconvCodec::convertToUnicode",
+ "internal error, UTF-16 codec not found");
+ if (!utf16Codec) {
+ fprintf(stderr, "QIconvCodec::convertToUnicode: internal error, UTF-16 codec not found\n");
+ utf16Codec = reinterpret_cast<QTextCodec *>(~0);
+ }
+#if defined(Q_OS_MAC)
+ if (ptr_iconv_open == 0) {
+ QLibrary libiconv(QLatin1String("/usr/lib/libiconv"));
+ libiconv.setLoadHints(QLibrary::ExportExternalSymbolsHint);
+
+ ptr_iconv_open = reinterpret_cast<Ptr_iconv_open>(libiconv.resolve("libiconv_open"));
+ if (!ptr_iconv_open)
+ ptr_iconv_open = reinterpret_cast<Ptr_iconv_open>(libiconv.resolve("iconv_open"));
+ ptr_iconv = reinterpret_cast<Ptr_iconv>(libiconv.resolve("libiconv"));
+ if (!ptr_iconv)
+ ptr_iconv = reinterpret_cast<Ptr_iconv>(libiconv.resolve("iconv"));
+ ptr_iconv_close = reinterpret_cast<Ptr_iconv_close>(libiconv.resolve("libiconv_close"));
+ if (!ptr_iconv_close)
+ ptr_iconv_close = reinterpret_cast<Ptr_iconv_close>(libiconv.resolve("iconv_close"));
+
+ Q_ASSERT_X(ptr_iconv_open && ptr_iconv && ptr_iconv_close,
+ "QIconvCodec::QIconvCodec()",
+ "internal error, could not resolve the iconv functions");
+
+# undef iconv_open
+# define iconv_open ptr_iconv_open
+# undef iconv
+# define iconv ptr_iconv
+# undef iconv_close
+# define iconv_close ptr_iconv_close
+ }
+#endif
+}
+
+QIconvCodec::~QIconvCodec()
+{
+}
+
+QIconvCodec::IconvState::IconvState(iconv_t x)
+ : buffer(array), bufferLen(sizeof array), cd(x)
+{
+}
+
+QIconvCodec::IconvState::~IconvState()
+{
+ if (cd != reinterpret_cast<iconv_t>(-1))
+ iconv_close(cd);
+ if (buffer != array)
+ delete[] buffer;
+}
+
+void QIconvCodec::IconvState::saveChars(const char *c, int count)
+{
+ if (count > bufferLen) {
+ if (buffer != array)
+ delete[] buffer;
+ buffer = new char[bufferLen = count];
+ }
+
+ memcpy(buffer, c, count);
+}
+
+static void qIconvCodecStateFree(QTextCodec::ConverterState *state)
+{
+ delete reinterpret_cast<QIconvCodec::IconvState *>(state->d);
+}
+
+Q_GLOBAL_STATIC(QThreadStorage<QIconvCodec::IconvState *>, toUnicodeState)
+
+QString QIconvCodec::convertToUnicode(const char* chars, int len, ConverterState *convState) const
+{
+ if (utf16Codec == reinterpret_cast<QTextCodec *>(~0))
+ return QString::fromLatin1(chars, len);
+
+ int invalidCount = 0;
+ int remainingCount = 0;
+ char *remainingBuffer = 0;
+ IconvState *temporaryState = 0;
+ IconvState **pstate;
+
+ if (convState) {
+ // stateful conversion
+ pstate = reinterpret_cast<IconvState **>(&convState->d);
+ if (convState->d) {
+ // restore state
+ remainingCount = convState->remainingChars;
+ remainingBuffer = (*pstate)->buffer;
+ } else {
+ // first time
+ convState->flags |= FreeFunction;
+ QTextCodecUnalignedPointer::encode(convState->state_data, qIconvCodecStateFree);
+ }
+ } else {
+ QThreadStorage<QIconvCodec::IconvState *> *ts = toUnicodeState();
+ if (!qt_locale_initialized || !ts) {
+ // we're running after the Q_GLOBAL_STATIC has been deleted
+ // or before the QCoreApplication initialization
+ // bad programmer, no cookie for you
+ pstate = &temporaryState;
+ } else {
+ // stateless conversion -- use thread-local data
+ pstate = &toUnicodeState()->localData();
+ }
+ }
+
+ if (!*pstate) {
+ // first time, create the state
+ iconv_t cd = QIconvCodec::createIconv_t(UTF16, 0);
+ if (cd == reinterpret_cast<iconv_t>(-1)) {
+ static int reported = 0;
+ if (!reported++) {
+ fprintf(stderr,
+ "QIconvCodec::convertToUnicode: using Latin-1 for conversion, iconv_open failed\n");
+ }
+ return QString::fromLatin1(chars, len);
+ }
+
+ *pstate = new IconvState(cd);
+ }
+
+ IconvState *state = *pstate;
+ size_t inBytesLeft = len;
+ // best case assumption, each byte is converted into one UTF-16 character, plus 2 bytes for the BOM
+#ifdef GNU_LIBICONV
+ // GNU doesn't disagree with POSIX :/
+ const char *inBytes = chars;
+#else
+ char *inBytes = const_cast<char *>(chars);
+#endif
+
+ QByteArray in;
+ if (remainingCount) {
+ // we have to prepend the remaining bytes from the previous conversion
+ inBytesLeft += remainingCount;
+ in.resize(inBytesLeft);
+ inBytes = in.data();
+
+ memcpy(in.data(), remainingBuffer, remainingCount);
+ memcpy(in.data() + remainingCount, chars, len);
+
+ remainingCount = 0;
+ }
+
+ size_t outBytesLeft = len * 2 + 2;
+ QByteArray ba(outBytesLeft, Qt::Uninitialized);
+ char *outBytes = ba.data();
+ do {
+ size_t ret = iconv(state->cd, &inBytes, &inBytesLeft, &outBytes, &outBytesLeft);
+ if (ret == (size_t) -1) {
+ if (errno == E2BIG) {
+ int offset = ba.size() - outBytesLeft;
+ ba.resize(ba.size() * 2);
+ outBytes = ba.data() + offset;
+ outBytesLeft = ba.size() - offset;
+
+ continue;
+ }
+
+ if (errno == EILSEQ) {
+ // conversion stopped because of an invalid character in the sequence
+ ++invalidCount;
+ } else if (errno == EINVAL && convState) {
+ // conversion stopped because the remaining inBytesLeft make up
+ // an incomplete multi-byte sequence; save them for later
+ state->saveChars(inBytes, inBytesLeft);
+ remainingCount = inBytesLeft;
+ break;
+ }
+
+ if (errno == EILSEQ || errno == EINVAL) {
+ // skip the next character
+ ++inBytes;
+ --inBytesLeft;
+ continue;
+ }
+
+ // some other error
+ // note, cannot use qWarning() since we are implementing the codecForLocale :)
+ perror("QIconvCodec::convertToUnicode: using Latin-1 for conversion, iconv failed");
+
+ if (!convState) {
+ // reset state
+ iconv(state->cd, 0, &inBytesLeft, 0, &outBytesLeft);
+ }
+
+ delete temporaryState;
+ return QString::fromLatin1(chars, len);
+ }
+ } while (inBytesLeft != 0);
+
+ QString s = utf16Codec->toUnicode(ba.constData(), ba.size() - outBytesLeft);
+
+ if (convState) {
+ convState->invalidChars = invalidCount;
+ convState->remainingChars = remainingCount;
+ } else {
+ // reset state
+ iconv(state->cd, 0, &inBytesLeft, 0, &outBytesLeft);
+ }
+
+ delete temporaryState;
+ return s;
+}
+
+Q_GLOBAL_STATIC(QThreadStorage<QIconvCodec::IconvState *>, fromUnicodeState)
+
+static bool setByteOrder(iconv_t cd)
+{
+#if !defined(NO_BOM)
+ // give iconv() a BOM
+ char buf[4];
+ ushort bom[] = { QChar::ByteOrderMark };
+
+ char *outBytes = buf;
+ char *inBytes = reinterpret_cast<char *>(bom);
+ size_t outBytesLeft = sizeof buf;
+ size_t inBytesLeft = sizeof bom;
+
+#if defined(GNU_LIBICONV)
+ const char **inBytesPtr = const_cast<const char **>(&inBytes);
+#else
+ char **inBytesPtr = &inBytes;
+#endif
+
+ if (iconv(cd, inBytesPtr, &inBytesLeft, &outBytes, &outBytesLeft) == (size_t) -1) {
+ return false;
+ }
+#endif // NO_BOM
+
+ return true;
+}
+
+QByteArray QIconvCodec::convertFromUnicode(const QChar *uc, int len, ConverterState *convState) const
+{
+ char *inBytes;
+ char *outBytes;
+ size_t inBytesLeft;
+
+#if defined(GNU_LIBICONV)
+ const char **inBytesPtr = const_cast<const char **>(&inBytes);
+#else
+ char **inBytesPtr = &inBytes;
+#endif
+
+ IconvState *temporaryState = 0;
+ QThreadStorage<QIconvCodec::IconvState *> *ts = fromUnicodeState();
+ IconvState *&state = (qt_locale_initialized && ts) ? ts->localData() : temporaryState;
+ if (!state) {
+ iconv_t cd = QIconvCodec::createIconv_t(0, UTF16);
+ if (cd != reinterpret_cast<iconv_t>(-1)) {
+ if (!setByteOrder(cd)) {
+ perror("QIconvCodec::convertFromUnicode: using Latin-1 for conversion, iconv failed for BOM");
+
+ iconv_close(cd);
+ cd = reinterpret_cast<iconv_t>(-1);
+
+ return QString(uc, len).toLatin1();
+ }
+ }
+ state = new IconvState(cd);
+ }
+ if (state->cd == reinterpret_cast<iconv_t>(-1)) {
+ static int reported = 0;
+ if (!reported++) {
+ fprintf(stderr,
+ "QIconvCodec::convertFromUnicode: using Latin-1 for conversion, iconv_open failed\n");
+ }
+ delete temporaryState;
+ return QString(uc, len).toLatin1();
+ }
+
+ size_t outBytesLeft = len;
+ QByteArray ba(outBytesLeft, Qt::Uninitialized);
+ outBytes = ba.data();
+
+ // now feed iconv() the real data
+ inBytes = const_cast<char *>(reinterpret_cast<const char *>(uc));
+ inBytesLeft = len * sizeof(QChar);
+
+ QByteArray in;
+ if (convState && convState->remainingChars) {
+ // we have one surrogate char to be prepended
+ in.resize(sizeof(QChar) + len);
+ inBytes = in.data();
+
+ QChar remaining = convState->state_data[0];
+ memcpy(in.data(), &remaining, sizeof(QChar));
+ memcpy(in.data() + sizeof(QChar), uc, inBytesLeft);
+
+ inBytesLeft += sizeof(QChar);
+ convState->remainingChars = 0;
+ }
+
+ int invalidCount = 0;
+ while (inBytesLeft != 0) {
+ if (iconv(state->cd, inBytesPtr, &inBytesLeft, &outBytes, &outBytesLeft) == (size_t) -1) {
+ if (errno == EINVAL && convState) {
+ // buffer ends in a surrogate
+ Q_ASSERT(inBytesLeft == 2);
+ convState->remainingChars = 1;
+ convState->state_data[0] = uc[len - 1].unicode();
+ break;
+ }
+
+ switch (errno) {
+ case EILSEQ:
+ ++invalidCount;
+ // fall through
+ case EINVAL:
+ {
+ inBytes += sizeof(QChar);
+ inBytesLeft -= sizeof(QChar);
+ break;
+ }
+ case E2BIG:
+ {
+ int offset = ba.size() - outBytesLeft;
+ ba.resize(ba.size() * 2);
+ outBytes = ba.data() + offset;
+ outBytesLeft = ba.size() - offset;
+ break;
+ }
+ default:
+ {
+ // note, cannot use qWarning() since we are implementing the codecForLocale :)
+ perror("QIconvCodec::convertFromUnicode: using Latin-1 for conversion, iconv failed");
+
+ // reset to initial state
+ iconv(state->cd, 0, &inBytesLeft, 0, &outBytesLeft);
+
+ delete temporaryState;
+ return QString(uc, len).toLatin1();
+ }
+ }
+ }
+ }
+
+ // reset to initial state
+ iconv(state->cd, 0, &inBytesLeft, 0, &outBytesLeft);
+ setByteOrder(state->cd);
+
+ ba.resize(ba.size() - outBytesLeft);
+
+ if (convState)
+ convState->invalidChars = invalidCount;
+
+ delete temporaryState;
+ return ba;
+}
+
+QByteArray QIconvCodec::name() const
+{
+ return "System";
+}
+
+int QIconvCodec::mibEnum() const
+{
+ return 0;
+}
+
+iconv_t QIconvCodec::createIconv_t(const char *to, const char *from)
+{
+ Q_ASSERT((to == 0 && from != 0) || (to != 0 && from == 0));
+
+ iconv_t cd = (iconv_t) -1;
+#if defined(__GLIBC__) || defined(GNU_LIBICONV)
+ // both GLIBC and libgnuiconv will use the locale's encoding if from or to is an empty string
+ static const char empty_codeset[] = "";
+ const char *codeset = empty_codeset;
+ cd = iconv_open(to ? to : codeset, from ? from : codeset);
+#else
+ char *codeset = 0;
+#endif
+
+#if defined(_XOPEN_UNIX) && !defined(Q_OS_QNX) && !defined(Q_OS_OSF)
+ if (cd == (iconv_t) -1) {
+ codeset = nl_langinfo(CODESET);
+ if (codeset)
+ cd = iconv_open(to ? to : codeset, from ? from : codeset);
+ }
+#endif
+
+ if (cd == (iconv_t) -1) {
+ // Very poorly defined and followed standards causes lots of
+ // code to try to get all the cases... This logic is
+ // duplicated in QTextCodec, so if you change it here, change
+ // it there too.
+
+ // Try to determine locale codeset from locale name assigned to
+ // LC_CTYPE category.
+
+ // First part is getting that locale name. First try setlocale() which
+ // definitely knows it, but since we cannot fully trust it, get ready
+ // to fall back to environment variables.
+ char * ctype = qstrdup(setlocale(LC_CTYPE, 0));
+
+ // Get the first nonempty value from $LC_ALL, $LC_CTYPE, and $LANG
+ // environment variables.
+ char * lang = qstrdup(qgetenv("LC_ALL").constData());
+ if (!lang || lang[0] == 0 || strcmp(lang, "C") == 0) {
+ if (lang) delete [] lang;
+ lang = qstrdup(qgetenv("LC_CTYPE").constData());
+ }
+ if (!lang || lang[0] == 0 || strcmp(lang, "C") == 0) {
+ if (lang) delete [] lang;
+ lang = qstrdup(qgetenv("LANG").constData());
+ }
+
+ // Now try these in order:
+ // 1. CODESET from ctype if it contains a .CODESET part (e.g. en_US.ISO8859-15)
+ // 2. CODESET from lang if it contains a .CODESET part
+ // 3. ctype (maybe the locale is named "ISO-8859-1" or something)
+ // 4. locale (ditto)
+ // 5. check for "@euro"
+
+ // 1. CODESET from ctype if it contains a .CODESET part (e.g. en_US.ISO8859-15)
+ codeset = ctype ? strchr(ctype, '.') : 0;
+ if (codeset && *codeset == '.') {
+ ++codeset;
+ cd = iconv_open(to ? to : codeset, from ? from : codeset);
+ }
+
+ // 2. CODESET from lang if it contains a .CODESET part
+ codeset = lang ? strchr(lang, '.') : 0;
+ if (cd == (iconv_t) -1 && codeset && *codeset == '.') {
+ ++codeset;
+ cd = iconv_open(to ? to : codeset, from ? from : codeset);
+ }
+
+ // 3. ctype (maybe the locale is named "ISO-8859-1" or something)
+ if (cd == (iconv_t) -1 && ctype && *ctype != 0 && strcmp (ctype, "C") != 0)
+ cd = iconv_open(to ? to : ctype, from ? from : ctype);
+
+
+ // 4. locale (ditto)
+ if (cd == (iconv_t) -1 && lang && *lang != 0)
+ cd = iconv_open(to ? to : lang, from ? from : lang);
+
+ // 5. "@euro"
+ if ((cd == (iconv_t) -1 && ctype && strstr(ctype, "@euro")) || (lang && strstr(lang, "@euro")))
+ cd = iconv_open(to ? to : "ISO8859-15", from ? from : "ISO8859-15");
+
+ delete [] ctype;
+ delete [] lang;
+ }
+
+ return cd;
+}
+
+QT_END_NAMESPACE
diff --git a/src/corelib/codecs/qiconvcodec_p.h b/src/corelib/codecs/qiconvcodec_p.h
new file mode 100644
index 0000000000..131347ca1b
--- /dev/null
+++ b/src/corelib/codecs/qiconvcodec_p.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QICONVCODEC_P_H
+#define QICONVCODEC_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of the QLibrary class. This header file may change from
+// version to version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qtextcodec.h"
+
+#if defined(Q_OS_UNIX) && !defined(QT_NO_ICONV) && !defined(QT_BOOTSTRAPPED)
+
+#ifdef Q_OS_MAC
+typedef void * iconv_t;
+#else
+#include <iconv.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+class QIconvCodec: public QTextCodec
+{
+private:
+ mutable QTextCodec *utf16Codec;
+
+public:
+ QIconvCodec();
+ ~QIconvCodec();
+
+ QString convertToUnicode(const char *, int, ConverterState *) const;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+
+ QByteArray name() const;
+ int mibEnum() const;
+
+ static iconv_t createIconv_t(const char *to, const char *from);
+
+ class IconvState
+ {
+ public:
+ IconvState(iconv_t x);
+ ~IconvState();
+ char *buffer;
+ int bufferLen;
+ iconv_t cd;
+
+ char array[8];
+
+ void saveChars(const char *c, int count);
+ };
+};
+
+QT_END_NAMESPACE
+
+#endif // Q_OS_UNIX && !QT_NO_ICONV && !QT_BOOTSTRAPPED
+
+#endif // QICONVCODEC_P_H
diff --git a/src/corelib/codecs/qisciicodec.cpp b/src/corelib/codecs/qisciicodec.cpp
new file mode 100644
index 0000000000..f7b450b4e4
--- /dev/null
+++ b/src/corelib/codecs/qisciicodec.cpp
@@ -0,0 +1,285 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "qisciicodec_p.h"
+#include "qlist.h"
+
+#ifndef QT_NO_CODECS
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QIsciiCodec
+ \brief The QIsciiCodec class provides conversion to and from the ISCII encoding.
+
+ \internal
+*/
+
+
+struct Codecs {
+ const char name[10];
+ ushort base;
+};
+
+static const Codecs codecs [] = {
+ { "Iscii-Dev", 0x900 },
+ { "Iscii-Bng", 0x980 },
+ { "Iscii-Pnj", 0xa00 },
+ { "Iscii-Gjr", 0xa80 },
+ { "Iscii-Ori", 0xb00 },
+ { "Iscii-Tml", 0xb80 },
+ { "Iscii-Tlg", 0xc00 },
+ { "Iscii-Knd", 0xc80 },
+ { "Iscii-Mlm", 0xd00 }
+};
+
+QIsciiCodec::~QIsciiCodec()
+{
+}
+
+QByteArray QIsciiCodec::name() const
+{
+ return codecs[idx].name;
+}
+
+int QIsciiCodec::mibEnum() const
+{
+ /* There is no MIBEnum for Iscii */
+ return -3000-idx;
+}
+
+static const uchar inv = 0xFF;
+
+/* iscii range from 0xa0 - 0xff */
+static const uchar iscii_to_uni_table[0x60] = {
+ 0x00, 0x01, 0x02, 0x03,
+ 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0a, 0x0b, 0x0e,
+ 0x0f, 0x20, 0x0d, 0x12,
+
+ 0x13, 0x14, 0x11, 0x15,
+ 0x16, 0x17, 0x18, 0x19,
+ 0x1a, 0x1b, 0x1c, 0x1d,
+ 0x1e, 0x1f, 0x20, 0x21,
+
+ 0x22, 0x23, 0x24, 0x25,
+ 0x26, 0x27, 0x28, 0x29,
+ 0x2a, 0x2b, 0x2c, 0x2d,
+ 0x2e, 0x2f, 0x5f, 0x30,
+
+ 0x31, 0x32, 0x33, 0x34,
+ 0x35, 0x36, 0x37, 0x38,
+ 0x39, inv, 0x3e, 0x3f,
+ 0x40, 0x41, 0x42, 0x43,
+
+ 0x46, 0x47, 0x48, 0x45,
+ 0x4a, 0x4b, 0x4c, 0x49,
+ 0x4d, 0x3c, 0x64, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+
+ 0x00, 0x66, 0x67, 0x68,
+ 0x69, 0x6a, 0x6b, 0x6c,
+ 0x6d, 0x6e, 0x6f, 0x00,
+ 0x00, 0x00, 0x00, 0x00
+};
+
+static const uchar uni_to_iscii_table[0x80] = {
+ 0x00, 0xa1, 0xa2, 0xa3,
+ 0x00, 0xa4, 0xa5, 0xa6,
+ 0xa7, 0xa8, 0xa9, 0xaa,
+ 0x00, 0xae, 0xab, 0xac,
+
+ 0xad, 0xb2, 0xaf, 0xb0,
+ 0xb1, 0xb3, 0xb4, 0xb5,
+ 0xb6, 0xb7, 0xb8, 0xb9,
+ 0xba, 0xbb, 0xbc, 0xbd,
+
+ 0xbe, 0xbf, 0xc0, 0xc1,
+ 0xc2, 0xc3, 0xc4, 0xc5,
+ 0xc6, 0xc7, 0xc8, 0xc9,
+ 0xca, 0xcb, 0xcc, 0xcd,
+
+ 0xcf, 0xd0, 0xd1, 0xd2,
+ 0xd3, 0xd4, 0xd5, 0xd6,
+ 0xd7, 0xd8, 0x00, 0x00,
+ 0xe9, 0x00, 0xda, 0xdb,
+
+ 0xdc, 0xdd, 0xde, 0xdf,
+ 0x00, 0xe3, 0xe0, 0xe1,
+ 0xe2, 0xe7, 0xe4, 0xe5,
+ 0xe6, 0xe8, 0x00, 0x00,
+
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x01, 0x02, 0x03, 0x04, // decomposable into the uc codes listed here + nukta
+ 0x05, 0x06, 0x07, 0xce,
+
+ 0x00, 0x00, 0x00, 0x00,
+ 0xea, 0x08, 0xf1, 0xf2,
+ 0xf3, 0xf4, 0xf5, 0xf6,
+ 0xf7, 0xf8, 0xf9, 0xfa,
+
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00
+};
+
+static const uchar uni_to_iscii_pairs[] = {
+ 0x00, 0x00,
+ 0x15, 0x3c, // 0x958
+ 0x16, 0x3c, // 0x959
+ 0x17, 0x3c, // 0x95a
+ 0x1c, 0x3c, // 0x95b
+ 0x21, 0x3c, // 0x95c
+ 0x22, 0x3c, // 0x95d
+ 0x2b, 0x3c, // 0x95e
+ 0x64, 0x64 // 0x965
+};
+
+
+QByteArray QIsciiCodec::convertFromUnicode(const QChar *uc, int len, ConverterState *state) const
+{
+ char replacement = '?';
+ bool halant = false;
+ if (state) {
+ if (state->flags & ConvertInvalidToNull)
+ replacement = 0;
+ halant = state->state_data[0];
+ }
+ int invalid = 0;
+
+ QByteArray result(2 * len, Qt::Uninitialized); //worst case
+
+ uchar *ch = reinterpret_cast<uchar *>(result.data());
+
+ const int base = codecs[idx].base;
+
+ for (int i =0; i < len; ++i) {
+ const ushort codePoint = uc[i].unicode();
+
+ /* The low 7 bits of ISCII is plain ASCII. However, we go all the
+ * way up to 0xA0 such that we can roundtrip with convertToUnicode()'s
+ * behavior. */
+ if(codePoint < 0xA0) {
+ *ch++ = static_cast<uchar>(codePoint);
+ continue;
+ }
+
+ const int pos = codePoint - base;
+ if (pos > 0 && pos < 0x80) {
+ uchar iscii = uni_to_iscii_table[pos];
+ if (iscii > 0x80) {
+ *ch++ = iscii;
+ } else if (iscii) {
+ const uchar *pair = uni_to_iscii_pairs + 2*iscii;
+ *ch++ = *pair++;
+ *ch++ = *pair++;
+ } else {
+ *ch++ = replacement;
+ ++invalid;
+ }
+ } else {
+ if (uc[i].unicode() == 0x200c) { // ZWNJ
+ if (halant)
+ // Consonant Halant ZWNJ -> Consonant Halant Halant
+ *ch++ = 0xe8;
+ } else if (uc[i].unicode() == 0x200d) { // ZWJ
+ if (halant)
+ // Consonant Halant ZWJ -> Consonant Halant Nukta
+ *ch++ = 0xe9;
+ } else {
+ *ch++ = replacement;
+ ++invalid;
+ }
+ }
+ halant = (pos == 0x4d);
+ }
+ result.truncate(ch - (uchar *)result.data());
+
+ if (state) {
+ state->invalidChars += invalid;
+ state->state_data[0] = halant;
+ }
+ return result;
+}
+
+QString QIsciiCodec::convertToUnicode(const char* chars, int len, ConverterState *state) const
+{
+ bool halant = false;
+ if (state) {
+ halant = state->state_data[0];
+ }
+
+ QString result(len, Qt::Uninitialized);
+ QChar *uc = result.data();
+
+ const int base = codecs[idx].base;
+
+ for (int i = 0; i < len; ++i) {
+ ushort ch = (uchar) chars[i];
+ if (ch < 0xa0)
+ *uc++ = ch;
+ else {
+ ushort c = iscii_to_uni_table[ch - 0xa0];
+ if (halant && (c == inv || c == 0xe9)) {
+ // Consonant Halant inv -> Consonant Halant ZWJ
+ // Consonant Halant Nukta -> Consonant Halant ZWJ
+ *uc++ = QChar(0x200d);
+ } else if (halant && c == 0xe8) {
+ // Consonant Halant Halant -> Consonant Halant ZWNJ
+ *uc++ = QChar(0x200c);
+ } else {
+ *uc++ = QChar(c+base);
+ }
+ }
+ halant = ((uchar)chars[i] == 0xe8);
+ }
+ result.resize(uc - result.unicode());
+
+ if (state) {
+ state->state_data[0] = halant;
+ }
+ return result;
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_CODECS
diff --git a/src/corelib/codecs/qisciicodec_p.h b/src/corelib/codecs/qisciicodec_p.h
new file mode 100644
index 0000000000..024670c527
--- /dev/null
+++ b/src/corelib/codecs/qisciicodec_p.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QISCIICODEC_P_H
+#define QISCIICODEC_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "QtCore/qtextcodec.h"
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_CODECS
+
+class QIsciiCodec : public QTextCodec {
+public:
+ explicit QIsciiCodec(int i) : idx(i) {}
+ ~QIsciiCodec();
+
+ QByteArray name() const;
+ int mibEnum() const;
+
+ QString convertToUnicode(const char *, int, ConverterState *) const;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+
+private:
+ int idx;
+};
+
+#endif // QT_NO_CODECS
+
+QT_END_NAMESPACE
+
+#endif // QISCIICODEC_P_H
diff --git a/src/corelib/codecs/qlatincodec.cpp b/src/corelib/codecs/qlatincodec.cpp
new file mode 100644
index 0000000000..20e59533a2
--- /dev/null
+++ b/src/corelib/codecs/qlatincodec.cpp
@@ -0,0 +1,244 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlatincodec_p.h"
+#include "qlist.h"
+
+#ifndef QT_NO_TEXTCODEC
+
+QT_BEGIN_NAMESPACE
+
+QLatin1Codec::~QLatin1Codec()
+{
+}
+
+QString QLatin1Codec::convertToUnicode(const char *chars, int len, ConverterState *) const
+{
+ if (chars == 0)
+ return QString();
+
+ return QString::fromLatin1(chars, len);
+}
+
+
+QByteArray QLatin1Codec::convertFromUnicode(const QChar *ch, int len, ConverterState *state) const
+{
+ const char replacement = (state && state->flags & ConvertInvalidToNull) ? 0 : '?';
+ QByteArray r(len, Qt::Uninitialized);
+ char *d = r.data();
+ int invalid = 0;
+ for (int i = 0; i < len; ++i) {
+ if (ch[i] > 0xff) {
+ d[i] = replacement;
+ ++invalid;
+ } else {
+ d[i] = (char)ch[i].cell();
+ }
+ }
+ if (state) {
+ state->invalidChars += invalid;
+ }
+ return r;
+}
+
+QByteArray QLatin1Codec::name() const
+{
+ return "ISO-8859-1";
+}
+
+QList<QByteArray> QLatin1Codec::aliases() const
+{
+ QList<QByteArray> list;
+ list << "latin1"
+ << "CP819"
+ << "IBM819"
+ << "iso-ir-100"
+ << "csISOLatin1";
+ return list;
+}
+
+
+int QLatin1Codec::mibEnum() const
+{
+ return 4;
+}
+
+
+QLatin15Codec::~QLatin15Codec()
+{
+}
+
+QString QLatin15Codec::convertToUnicode(const char* chars, int len, ConverterState *) const
+{
+ if (chars == 0)
+ return QString();
+
+ QString str = QString::fromLatin1(chars, len);
+ QChar *uc = str.data();
+ while(len--) {
+ switch(uc->unicode()) {
+ case 0xa4:
+ *uc = 0x20ac;
+ break;
+ case 0xa6:
+ *uc = 0x0160;
+ break;
+ case 0xa8:
+ *uc = 0x0161;
+ break;
+ case 0xb4:
+ *uc = 0x017d;
+ break;
+ case 0xb8:
+ *uc = 0x017e;
+ break;
+ case 0xbc:
+ *uc = 0x0152;
+ break;
+ case 0xbd:
+ *uc = 0x0153;
+ break;
+ case 0xbe:
+ *uc = 0x0178;
+ break;
+ default:
+ break;
+ }
+ uc++;
+ }
+ return str;
+}
+
+QByteArray QLatin15Codec::convertFromUnicode(const QChar *in, int length, ConverterState *state) const
+{
+ const char replacement = (state && state->flags & ConvertInvalidToNull) ? 0 : '?';
+ QByteArray r(length, Qt::Uninitialized);
+ char *d = r.data();
+ int invalid = 0;
+ for (int i = 0; i < length; ++i) {
+ uchar c;
+ ushort uc = in[i].unicode();
+ if (uc < 0x0100) {
+ if (uc > 0xa3) {
+ switch(uc) {
+ case 0xa4:
+ case 0xa6:
+ case 0xa8:
+ case 0xb4:
+ case 0xb8:
+ case 0xbc:
+ case 0xbd:
+ case 0xbe:
+ c = replacement;
+ ++invalid;
+ break;
+ default:
+ c = (unsigned char) uc;
+ break;
+ }
+ } else {
+ c = (unsigned char) uc;
+ }
+ } else {
+ if (uc == 0x20ac)
+ c = 0xa4;
+ else if ((uc & 0xff00) == 0x0100) {
+ switch(uc) {
+ case 0x0160:
+ c = 0xa6;
+ break;
+ case 0x0161:
+ c = 0xa8;
+ break;
+ case 0x017d:
+ c = 0xb4;
+ break;
+ case 0x017e:
+ c = 0xb8;
+ break;
+ case 0x0152:
+ c = 0xbc;
+ break;
+ case 0x0153:
+ c = 0xbd;
+ break;
+ case 0x0178:
+ c = 0xbe;
+ break;
+ default:
+ c = replacement;
+ ++invalid;
+ }
+ } else {
+ c = replacement;
+ ++invalid;
+ }
+ }
+ d[i] = (char)c;
+ }
+ if (state) {
+ state->remainingChars = 0;
+ state->invalidChars += invalid;
+ }
+ return r;
+}
+
+
+QByteArray QLatin15Codec::name() const
+{
+ return "ISO-8859-15";
+}
+
+QList<QByteArray> QLatin15Codec::aliases() const
+{
+ QList<QByteArray> list;
+ list << "latin9";
+ return list;
+}
+
+int QLatin15Codec::mibEnum() const
+{
+ return 111;
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_TEXTCODEC
diff --git a/src/corelib/codecs/qlatincodec_p.h b/src/corelib/codecs/qlatincodec_p.h
new file mode 100644
index 0000000000..fffc1fa983
--- /dev/null
+++ b/src/corelib/codecs/qlatincodec_p.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QLATINCODEC_P_H
+#define QLATINCODEC_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "QtCore/qtextcodec.h"
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_TEXTCODEC
+
+class QLatin1Codec : public QTextCodec
+{
+public:
+ ~QLatin1Codec();
+
+ QString convertToUnicode(const char *, int, ConverterState *) const;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+
+ QByteArray name() const;
+ QList<QByteArray> aliases() const;
+ int mibEnum() const;
+};
+
+
+
+class QLatin15Codec: public QTextCodec
+{
+public:
+ ~QLatin15Codec();
+
+ QString convertToUnicode(const char *, int, ConverterState *) const;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+
+ QByteArray name() const;
+ QList<QByteArray> aliases() const;
+ int mibEnum() const;
+};
+
+#endif // QT_NO_TEXTCODEC
+
+QT_END_NAMESPACE
+
+#endif // QLATINCODEC_P_H
diff --git a/src/corelib/codecs/qsimplecodec.cpp b/src/corelib/codecs/qsimplecodec.cpp
new file mode 100644
index 0000000000..abbbc8d650
--- /dev/null
+++ b/src/corelib/codecs/qsimplecodec.cpp
@@ -0,0 +1,735 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsimplecodec_p.h"
+#include "qlist.h"
+
+#ifndef QT_NO_TEXTCODEC
+
+QT_BEGIN_NAMESPACE
+
+#define LAST_MIB 2004
+
+static const struct {
+ const char *mime;
+ const char *aliases[7];
+ int mib;
+ quint16 values[128];
+} unicodevalues[QSimpleTextCodec::numSimpleCodecs] = {
+#ifndef Q_OS_SYMBIAN
+ // from RFC 1489, ftp://ftp.isi.edu/in-notes/rfc1489.txt
+ { "KOI8-R", { "csKOI8R", 0 }, 2084,
+ { 0x2500, 0x2502, 0x250C, 0x2510, 0x2514, 0x2518, 0x251C, 0x2524,
+ 0x252C, 0x2534, 0x253C, 0x2580, 0x2584, 0x2588, 0x258C, 0x2590,
+ 0x2591, 0x2592, 0x2593, 0x2320, 0x25A0, 0x2219/**/, 0x221A, 0x2248,
+ 0x2264, 0x2265, 0x00A0, 0x2321, 0x00B0, 0x00B2, 0x00B7, 0x00F7,
+ 0x2550, 0x2551, 0x2552, 0x0451, 0x2553, 0x2554, 0x2555, 0x2556,
+ 0x2557, 0x2558, 0x2559, 0x255A, 0x255B, 0x255C, 0x255D, 0x255E,
+ 0x255F, 0x2560, 0x2561, 0x0401, 0x2562, 0x2563, 0x2564, 0x2565,
+ 0x2566, 0x2567, 0x2568, 0x2569, 0x256A, 0x256B, 0x256C, 0x00A9,
+ 0x044E, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433,
+ 0x0445, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E,
+ 0x043F, 0x044F, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432,
+ 0x044C, 0x044B, 0x0437, 0x0448, 0x044D, 0x0449, 0x0447, 0x044A,
+ 0x042E, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413,
+ 0x0425, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E,
+ 0x041F, 0x042F, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412,
+ 0x042C, 0x042B, 0x0417, 0x0428, 0x042D, 0x0429, 0x0427, 0x042A } },
+ // /**/ - The BULLET OPERATOR is confused. Some people think
+ // it should be 0x2022 (BULLET).
+
+ // from RFC 2319, ftp://ftp.isi.edu/in-notes/rfc2319.txt
+ { "KOI8-U", { "KOI8-RU", 0 }, 2088,
+ { 0x2500, 0x2502, 0x250C, 0x2510, 0x2514, 0x2518, 0x251C, 0x2524,
+ 0x252C, 0x2534, 0x253C, 0x2580, 0x2584, 0x2588, 0x258C, 0x2590,
+ 0x2591, 0x2592, 0x2593, 0x2320, 0x25A0, 0x2219, 0x221A, 0x2248,
+ 0x2264, 0x2265, 0x00A0, 0x2321, 0x00B0, 0x00B2, 0x00B7, 0x00F7,
+ 0x2550, 0x2551, 0x2552, 0x0451, 0x0454, 0x2554, 0x0456, 0x0457,
+ 0x2557, 0x2558, 0x2559, 0x255A, 0x255B, 0x0491, 0x255D, 0x255E,
+ 0x255F, 0x2560, 0x2561, 0x0401, 0x0404, 0x2563, 0x0406, 0x0407,
+ 0x2566, 0x2567, 0x2568, 0x2569, 0x256A, 0x0490, 0x256C, 0x00A9,
+ 0x044E, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433,
+ 0x0445, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E,
+ 0x043F, 0x044F, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432,
+ 0x044C, 0x044B, 0x0437, 0x0448, 0x044D, 0x0449, 0x0447, 0x044A,
+ 0x042E, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413,
+ 0x0425, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E,
+ 0x041F, 0x042F, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412,
+ 0x042C, 0x042B, 0x0417, 0x0428, 0x042D, 0x0429, 0x0427, 0x042A } },
+
+ // next bits generated from tables on the Unicode 2.0 CD. we can
+ // use these tables since this is part of the transition to using
+ // unicode everywhere in qt.
+
+ // $ for A in 8 9 A B C D E F ; do for B in 0 1 2 3 4 5 6 7 8 9 A B C D E F ; do echo 0x${A}${B} 0xFFFD ; done ; done > /tmp/digits ; for a in 8859-* ; do (awk '/^0x[89ABCDEF]/{ print $1, $2 }' < $a ; cat /tmp/digits) | sort | uniq -w4 | cut -c6- | paste '-d ' - - - - - - - - | sed -e 's/ /, /g' -e 's/$/,/' -e '$ s/,$/} },/' -e '1 s/^/{ /' > ~/tmp/$a ; done
+
+ // then I inserted the files manually.
+ { "ISO-8859-2", {"latin2", "iso-ir-101", "csISOLatin2", 0 }, 5,
+ { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
+ 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
+ 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
+ 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
+ 0x00A0, 0x0104, 0x02D8, 0x0141, 0x00A4, 0x013D, 0x015A, 0x00A7,
+ 0x00A8, 0x0160, 0x015E, 0x0164, 0x0179, 0x00AD, 0x017D, 0x017B,
+ 0x00B0, 0x0105, 0x02DB, 0x0142, 0x00B4, 0x013E, 0x015B, 0x02C7,
+ 0x00B8, 0x0161, 0x015F, 0x0165, 0x017A, 0x02DD, 0x017E, 0x017C,
+ 0x0154, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0139, 0x0106, 0x00C7,
+ 0x010C, 0x00C9, 0x0118, 0x00CB, 0x011A, 0x00CD, 0x00CE, 0x010E,
+ 0x0110, 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x00D7,
+ 0x0158, 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162, 0x00DF,
+ 0x0155, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7,
+ 0x010D, 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F,
+ 0x0111, 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7,
+ 0x0159, 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9} },
+ { "ISO-8859-3", { "latin3", "iso-ir-109", "csISOLatin3", 0 }, 6,
+ { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
+ 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
+ 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
+ 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
+ 0x00A0, 0x0126, 0x02D8, 0x00A3, 0x00A4, 0xFFFD, 0x0124, 0x00A7,
+ 0x00A8, 0x0130, 0x015E, 0x011E, 0x0134, 0x00AD, 0xFFFD, 0x017B,
+ 0x00B0, 0x0127, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x0125, 0x00B7,
+ 0x00B8, 0x0131, 0x015F, 0x011F, 0x0135, 0x00BD, 0xFFFD, 0x017C,
+ 0x00C0, 0x00C1, 0x00C2, 0xFFFD, 0x00C4, 0x010A, 0x0108, 0x00C7,
+ 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
+ 0xFFFD, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x0120, 0x00D6, 0x00D7,
+ 0x011C, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x016C, 0x015C, 0x00DF,
+ 0x00E0, 0x00E1, 0x00E2, 0xFFFD, 0x00E4, 0x010B, 0x0109, 0x00E7,
+ 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
+ 0xFFFD, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x0121, 0x00F6, 0x00F7,
+ 0x011D, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x016D, 0x015D, 0x02D9} },
+ { "ISO-8859-4", { "latin4", "iso-ir-110", "csISOLatin4", 0 }, 7,
+ { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
+ 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
+ 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
+ 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
+ 0x00A0, 0x0104, 0x0138, 0x0156, 0x00A4, 0x0128, 0x013B, 0x00A7,
+ 0x00A8, 0x0160, 0x0112, 0x0122, 0x0166, 0x00AD, 0x017D, 0x00AF,
+ 0x00B0, 0x0105, 0x02DB, 0x0157, 0x00B4, 0x0129, 0x013C, 0x02C7,
+ 0x00B8, 0x0161, 0x0113, 0x0123, 0x0167, 0x014A, 0x017E, 0x014B,
+ 0x0100, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x012E,
+ 0x010C, 0x00C9, 0x0118, 0x00CB, 0x0116, 0x00CD, 0x00CE, 0x012A,
+ 0x0110, 0x0145, 0x014C, 0x0136, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
+ 0x00D8, 0x0172, 0x00DA, 0x00DB, 0x00DC, 0x0168, 0x016A, 0x00DF,
+ 0x0101, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x012F,
+ 0x010D, 0x00E9, 0x0119, 0x00EB, 0x0117, 0x00ED, 0x00EE, 0x012B,
+ 0x0111, 0x0146, 0x014D, 0x0137, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
+ 0x00F8, 0x0173, 0x00FA, 0x00FB, 0x00FC, 0x0169, 0x016B, 0x02D9} },
+ { "ISO-8859-5", { "cyrillic", "iso-ir-144", "csISOLatinCyrillic", 0 }, 8,
+ { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
+ 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
+ 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
+ 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
+ 0x00A0, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407,
+ 0x0408, 0x0409, 0x040A, 0x040B, 0x040C, 0x00AD, 0x040E, 0x040F,
+ 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
+ 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
+ 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
+ 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
+ 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
+ 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
+ 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
+ 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F,
+ 0x2116, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457,
+ 0x0458, 0x0459, 0x045A, 0x045B, 0x045C, 0x00A7, 0x045E, 0x045F} },
+ { "ISO-8859-6", { "ISO-8859-6-I", "ECMA-114", "ASMO-708", "arabic", "iso-ir-127", "csISOLatinArabic", 0 }, 82,
+ { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
+ 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
+ 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
+ 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
+ 0x00A0, 0xFFFD, 0xFFFD, 0xFFFD, 0x00A4, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x060C, 0x00AD, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0xFFFD, 0xFFFD, 0x061B, 0xFFFD, 0xFFFD, 0xFFFD, 0x061F,
+ 0xFFFD, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627,
+ 0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F,
+ 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x0637,
+ 0x0638, 0x0639, 0x063A, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0x0640, 0x0641, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647,
+ 0x0648, 0x0649, 0x064A, 0x064B, 0x064C, 0x064D, 0x064E, 0x064F,
+ 0x0650, 0x0651, 0x0652, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD} },
+ { "ISO-8859-7", { "ECMA-118", "greek", "iso-ir-126", "csISOLatinGreek", 0 }, 10,
+ { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
+ 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
+ 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
+ 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
+ 0x00A0, 0x2018, 0x2019, 0x00A3, 0xFFFD, 0xFFFD, 0x00A6, 0x00A7,
+ 0x00A8, 0x00A9, 0xFFFD, 0x00AB, 0x00AC, 0x00AD, 0xFFFD, 0x2015,
+ 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x0384, 0x0385, 0x0386, 0x00B7,
+ 0x0388, 0x0389, 0x038A, 0x00BB, 0x038C, 0x00BD, 0x038E, 0x038F,
+ 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
+ 0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F,
+ 0x03A0, 0x03A1, 0xFFFD, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7,
+ 0x03A8, 0x03A9, 0x03AA, 0x03AB, 0x03AC, 0x03AD, 0x03AE, 0x03AF,
+ 0x03B0, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7,
+ 0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF,
+ 0x03C0, 0x03C1, 0x03C2, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7,
+ 0x03C8, 0x03C9, 0x03CA, 0x03CB, 0x03CC, 0x03CD, 0x03CE, 0xFFFD} },
+ { "ISO-8859-8", { "ISO 8859-8-I", "iso-ir-138", "hebrew", "csISOLatinHebrew", 0 }, 85,
+ { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
+ 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
+ 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
+ 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
+ 0x00A0, 0xFFFD, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
+ 0x00A8, 0x00A9, 0x00D7, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x203E,
+ 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
+ 0x00B8, 0x00B9, 0x00F7, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0xFFFD,
+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x2017,
+ 0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7,
+ 0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
+ 0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
+ 0x05E8, 0x05E9, 0x05EA, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD} },
+ { "ISO-8859-9", { "iso-ir-148", "latin5", "csISOLatin5", 0 }, 12,
+ { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
+ 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
+ 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
+ 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
+ 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
+ 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
+ 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
+ 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
+ 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
+ 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
+ 0x011E, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
+ 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x0130, 0x015E, 0x00DF,
+ 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
+ 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
+ 0x011F, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
+ 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x0131, 0x015F, 0x00FF} },
+ { "ISO-8859-10", { "iso-ir-157", "latin6", "ISO-8859-10:1992", "csISOLatin6", 0 }, 13,
+ { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
+ 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
+ 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
+ 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
+ 0x00A0, 0x0104, 0x0112, 0x0122, 0x012A, 0x0128, 0x0136, 0x00A7,
+ 0x013B, 0x0110, 0x0160, 0x0166, 0x017D, 0x00AD, 0x016A, 0x014A,
+ 0x00B0, 0x0105, 0x0113, 0x0123, 0x012B, 0x0129, 0x0137, 0x00B7,
+ 0x013C, 0x0111, 0x0161, 0x0167, 0x017E, 0x2015, 0x016B, 0x014B,
+ 0x0100, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x012E,
+ 0x010C, 0x00C9, 0x0118, 0x00CB, 0x0116, 0x00CD, 0x00CE, 0x00CF,
+ 0x00D0, 0x0145, 0x014C, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x0168,
+ 0x00D8, 0x0172, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
+ 0x0101, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x012F,
+ 0x010D, 0x00E9, 0x0119, 0x00EB, 0x0117, 0x00ED, 0x00EE, 0x00EF,
+ 0x00F0, 0x0146, 0x014D, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x0169,
+ 0x00F8, 0x0173, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x0138} },
+ { "ISO-8859-13", { 0 }, 109,
+ { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
+ 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
+ 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
+ 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
+ 0x00A0, 0x201D, 0x00A2, 0x00A3, 0x00A4, 0x201E, 0x00A6, 0x00A7,
+ 0x00D8, 0x00A9, 0x0156, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00C6,
+ 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x201C, 0x00B5, 0x00B6, 0x00B7,
+ 0x00F8, 0x00B9, 0x0157, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00E6,
+ 0x0104, 0x012E, 0x0100, 0x0106, 0x00C4, 0x00C5, 0x0118, 0x0112,
+ 0x010C, 0x00C9, 0x0179, 0x0116, 0x0122, 0x0136, 0x012A, 0x013B,
+ 0x0160, 0x0143, 0x0145, 0x00D3, 0x014C, 0x00D5, 0x00D6, 0x00D7,
+ 0x0172, 0x0141, 0x015A, 0x016A, 0x00DC, 0x017B, 0x017D, 0x00DF,
+ 0x0105, 0x012F, 0x0101, 0x0107, 0x00E4, 0x00E5, 0x0119, 0x0113,
+ 0x010D, 0x00E9, 0x017A, 0x0117, 0x0123, 0x0137, 0x012B, 0x013C,
+ 0x0161, 0x0144, 0x0146, 0x00F3, 0x014D, 0x00F5, 0x00F6, 0x00F7,
+ 0x0173, 0x0142, 0x015B, 0x016B, 0x00FC, 0x017C, 0x017E, 0x2019} },
+ { "ISO-8859-14", { "iso-ir-199", "latin8", "iso-celtic", 0 }, 110,
+ { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
+ 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
+ 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
+ 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
+ 0x00A0, 0x1E02, 0x1E03, 0x00A3, 0x010A, 0x010B, 0x1E0A, 0x00A7,
+ 0x1E80, 0x00A9, 0x1E82, 0x1E0B, 0x1EF2, 0x00AD, 0x00AE, 0x0178,
+ 0x1E1E, 0x1E1F, 0x0120, 0x0121, 0x1E40, 0x1E41, 0x00B6, 0x1E56,
+ 0x1E81, 0x1E57, 0x1E83, 0x1E60, 0x1EF3, 0x1E84, 0x1E85, 0x1E61,
+ 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
+ 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
+ 0x0174, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x1E6A,
+ 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x0176, 0x00DF,
+ 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
+ 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
+ 0x0175, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x1E6B,
+ 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x0177, 0x00FF} },
+#endif
+ { "ISO-8859-16", { "iso-ir-226", "latin10", 0 }, 112,
+ { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
+ 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
+ 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
+ 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
+ 0x00A0, 0x0104, 0x0105, 0x0141, 0x20AC, 0x201E, 0x0160, 0x00A7,
+ 0x0161, 0x00A9, 0x0218, 0x00AB, 0x0179, 0x00AD, 0x017A, 0x017B,
+ 0x00B0, 0x00B1, 0x010C, 0x0142, 0x017D, 0x201D, 0x00B6, 0x00B7,
+ 0x017E, 0x010D, 0x0219, 0x00BB, 0x0152, 0x0153, 0x0178, 0x017C,
+ 0x00C0, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0106, 0x00C6, 0x00C7,
+ 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
+ 0x0110, 0x0143, 0x00D2, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x015A,
+ 0x0170, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x0118, 0x021A, 0x00DF,
+ 0x00E0, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x0107, 0x00E6, 0x00E7,
+ 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
+ 0x0111, 0x0144, 0x00F2, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x015B,
+ 0x0171, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x0119, 0x021B, 0x00FF} },
+
+ // next bits generated again from tables on the Unicode 3.0 CD.
+
+ // $ for a in CP* ; do (awk '/^0x[89ABCDEF]/{ print $1, $2 }' < $a) | sort | sed -e 's/#UNDEF.*$/0xFFFD/' | cut -c6- | paste '-d ' - - - - - - - - | sed -e 's/ /, /g' -e 's/$/,/' -e '$ s/,$/} },/' -e '1 s/^/{ /' > ~/tmp/$a ; done
+#ifndef Q_OS_SYMBIAN
+ { "IBM850", { "CP850", "csPC850Multilingual", 0 }, 2009,
+ { 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
+ 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
+ 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
+ 0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192,
+ 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA,
+ 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
+ 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0,
+ 0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510,
+ 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3,
+ 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
+ 0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x0131, 0x00CD, 0x00CE,
+ 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580,
+ 0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE,
+ 0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4,
+ 0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8,
+ 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0} },
+ { "IBM874", { "CP874", 0 }, -874, //### what is the mib?
+ { 0x20AC, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x2026, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0x00A0, 0x0E01, 0x0E02, 0x0E03, 0x0E04, 0x0E05, 0x0E06, 0x0E07,
+ 0x0E08, 0x0E09, 0x0E0A, 0x0E0B, 0x0E0C, 0x0E0D, 0x0E0E, 0x0E0F,
+ 0x0E10, 0x0E11, 0x0E12, 0x0E13, 0x0E14, 0x0E15, 0x0E16, 0x0E17,
+ 0x0E18, 0x0E19, 0x0E1A, 0x0E1B, 0x0E1C, 0x0E1D, 0x0E1E, 0x0E1F,
+ 0x0E20, 0x0E21, 0x0E22, 0x0E23, 0x0E24, 0x0E25, 0x0E26, 0x0E27,
+ 0x0E28, 0x0E29, 0x0E2A, 0x0E2B, 0x0E2C, 0x0E2D, 0x0E2E, 0x0E2F,
+ 0x0E30, 0x0E31, 0x0E32, 0x0E33, 0x0E34, 0x0E35, 0x0E36, 0x0E37,
+ 0x0E38, 0x0E39, 0x0E3A, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x0E3F,
+ 0x0E40, 0x0E41, 0x0E42, 0x0E43, 0x0E44, 0x0E45, 0x0E46, 0x0E47,
+ 0x0E48, 0x0E49, 0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D, 0x0E4E, 0x0E4F,
+ 0x0E50, 0x0E51, 0x0E52, 0x0E53, 0x0E54, 0x0E55, 0x0E56, 0x0E57,
+ 0x0E58, 0x0E59, 0x0E5A, 0x0E5B, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD} },
+#endif //Q_OS_SYMBIAN
+ { "IBM866", { "CP866", "csIBM866", 0 }, 2086,
+ { 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
+ 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
+ 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
+ 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
+ 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
+ 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
+ 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
+ 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
+ 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
+ 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
+ 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
+ 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
+ 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
+ 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F,
+ 0x0401, 0x0451, 0x0404, 0x0454, 0x0407, 0x0457, 0x040E, 0x045E,
+ 0x00B0, 0x2219, 0x00B7, 0x221A, 0x2116, 0x00A4, 0x25A0, 0x00A0} },
+
+#ifndef Q_OS_SYMBIAN
+ { "windows-1250", { "CP1250", 0 }, 2250,
+ { 0x20AC, 0xFFFD, 0x201A, 0xFFFD, 0x201E, 0x2026, 0x2020, 0x2021,
+ 0xFFFD, 0x2030, 0x0160, 0x2039, 0x015A, 0x0164, 0x017D, 0x0179,
+ 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
+ 0xFFFD, 0x2122, 0x0161, 0x203A, 0x015B, 0x0165, 0x017E, 0x017A,
+ 0x00A0, 0x02C7, 0x02D8, 0x0141, 0x00A4, 0x0104, 0x00A6, 0x00A7,
+ 0x00A8, 0x00A9, 0x015E, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x017B,
+ 0x00B0, 0x00B1, 0x02DB, 0x0142, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
+ 0x00B8, 0x0105, 0x015F, 0x00BB, 0x013D, 0x02DD, 0x013E, 0x017C,
+ 0x0154, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0139, 0x0106, 0x00C7,
+ 0x010C, 0x00C9, 0x0118, 0x00CB, 0x011A, 0x00CD, 0x00CE, 0x010E,
+ 0x0110, 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x00D7,
+ 0x0158, 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162, 0x00DF,
+ 0x0155, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7,
+ 0x010D, 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F,
+ 0x0111, 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7,
+ 0x0159, 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9} },
+ { "windows-1251", { "CP1251", 0 }, 2251,
+ { 0x0402, 0x0403, 0x201A, 0x0453, 0x201E, 0x2026, 0x2020, 0x2021,
+ 0x20AC, 0x2030, 0x0409, 0x2039, 0x040A, 0x040C, 0x040B, 0x040F,
+ 0x0452, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
+ 0xFFFD, 0x2122, 0x0459, 0x203A, 0x045A, 0x045C, 0x045B, 0x045F,
+ 0x00A0, 0x040E, 0x045E, 0x0408, 0x00A4, 0x0490, 0x00A6, 0x00A7,
+ 0x0401, 0x00A9, 0x0404, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x0407,
+ 0x00B0, 0x00B1, 0x0406, 0x0456, 0x0491, 0x00B5, 0x00B6, 0x00B7,
+ 0x0451, 0x2116, 0x0454, 0x00BB, 0x0458, 0x0405, 0x0455, 0x0457,
+ 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
+ 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
+ 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
+ 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
+ 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
+ 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
+ 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
+ 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F} },
+ { "windows-1252", { "CP1252", 0 }, 2252,
+ { 0x20AC, 0xFFFD, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
+ 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0xFFFD, 0x017D, 0xFFFD,
+ 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
+ 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0xFFFD, 0x017E, 0x0178,
+ 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
+ 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
+ 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
+ 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
+ 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
+ 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
+ 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
+ 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
+ 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
+ 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
+ 0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
+ 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF} },
+ { "windows-1253", {"CP1253", 0 }, 2253,
+ { 0x20AC, 0xFFFD, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
+ 0xFFFD, 0x2030, 0xFFFD, 0x2039, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
+ 0xFFFD, 0x2122, 0xFFFD, 0x203A, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0x00A0, 0x0385, 0x0386, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
+ 0x00A8, 0x00A9, 0xFFFD, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x2015,
+ 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x0384, 0x00B5, 0x00B6, 0x00B7,
+ 0x0388, 0x0389, 0x038A, 0x00BB, 0x038C, 0x00BD, 0x038E, 0x038F,
+ 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
+ 0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F,
+ 0x03A0, 0x03A1, 0xFFFD, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7,
+ 0x03A8, 0x03A9, 0x03AA, 0x03AB, 0x03AC, 0x03AD, 0x03AE, 0x03AF,
+ 0x03B0, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7,
+ 0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF,
+ 0x03C0, 0x03C1, 0x03C2, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7,
+ 0x03C8, 0x03C9, 0x03CA, 0x03CB, 0x03CC, 0x03CD, 0x03CE, 0xFFFD} },
+ { "windows-1254", { "CP1254", 0 }, 2254,
+ { 0x20AC, 0xFFFD, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
+ 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
+ 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0xFFFD, 0xFFFD, 0x0178,
+ 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
+ 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
+ 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
+ 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
+ 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
+ 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
+ 0x011E, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
+ 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x0130, 0x015E, 0x00DF,
+ 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
+ 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
+ 0x011F, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
+ 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x0131, 0x015F, 0x00FF} },
+ { "windows-1255", { "CP1255", 0 }, 2255,
+ { 0x20AC, 0xFFFD, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
+ 0x02C6, 0x2030, 0xFFFD, 0x2039, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
+ 0x02DC, 0x2122, 0xFFFD, 0x203A, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x20AA, 0x00A5, 0x00A6, 0x00A7,
+ 0x00A8, 0x00A9, 0x00D7, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
+ 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
+ 0x00B8, 0x00B9, 0x00F7, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
+ 0x05B0, 0x05B1, 0x05B2, 0x05B3, 0x05B4, 0x05B5, 0x05B6, 0x05B7,
+ 0x05B8, 0x05B9, 0xFFFD, 0x05BB, 0x05BC, 0x05BD, 0x05BE, 0x05BF,
+ 0x05C0, 0x05C1, 0x05C2, 0x05C3, 0x05F0, 0x05F1, 0x05F2, 0x05F3,
+ 0x05F4, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7,
+ 0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
+ 0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
+ 0x05E8, 0x05E9, 0x05EA, 0xFFFD, 0xFFFD, 0x200E, 0x200F, 0xFFFD} },
+ { "windows-1256", { "CP1256", 0 }, 2256,
+ { 0x20AC, 0x067E, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
+ 0x02C6, 0x2030, 0x0679, 0x2039, 0x0152, 0x0686, 0x0698, 0x0688,
+ 0x06AF, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
+ 0x06A9, 0x2122, 0x0691, 0x203A, 0x0153, 0x200C, 0x200D, 0x06BA,
+ 0x00A0, 0x060C, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
+ 0x00A8, 0x00A9, 0x06BE, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
+ 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
+ 0x00B8, 0x00B9, 0x061B, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x061F,
+ 0x06C1, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627,
+ 0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F,
+ 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x00D7,
+ 0x0637, 0x0638, 0x0639, 0x063A, 0x0640, 0x0641, 0x0642, 0x0643,
+ 0x00E0, 0x0644, 0x00E2, 0x0645, 0x0646, 0x0647, 0x0648, 0x00E7,
+ 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0649, 0x064A, 0x00EE, 0x00EF,
+ 0x064B, 0x064C, 0x064D, 0x064E, 0x00F4, 0x064F, 0x0650, 0x00F7,
+ 0x0651, 0x00F9, 0x0652, 0x00FB, 0x00FC, 0x200E, 0x200F, 0x06D2} },
+ { "windows-1257", { "CP1257", 0 }, 2257,
+ { 0x20AC, 0xFFFD, 0x201A, 0xFFFD, 0x201E, 0x2026, 0x2020, 0x2021,
+ 0xFFFD, 0x2030, 0xFFFD, 0x2039, 0xFFFD, 0x00A8, 0x02C7, 0x00B8,
+ 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
+ 0xFFFD, 0x2122, 0xFFFD, 0x203A, 0xFFFD, 0x00AF, 0x02DB, 0xFFFD,
+ 0x00A0, 0xFFFD, 0x00A2, 0x00A3, 0x00A4, 0xFFFD, 0x00A6, 0x00A7,
+ 0x00D8, 0x00A9, 0x0156, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00C6,
+ 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
+ 0x00F8, 0x00B9, 0x0157, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00E6,
+ 0x0104, 0x012E, 0x0100, 0x0106, 0x00C4, 0x00C5, 0x0118, 0x0112,
+ 0x010C, 0x00C9, 0x0179, 0x0116, 0x0122, 0x0136, 0x012A, 0x013B,
+ 0x0160, 0x0143, 0x0145, 0x00D3, 0x014C, 0x00D5, 0x00D6, 0x00D7,
+ 0x0172, 0x0141, 0x015A, 0x016A, 0x00DC, 0x017B, 0x017D, 0x00DF,
+ 0x0105, 0x012F, 0x0101, 0x0107, 0x00E4, 0x00E5, 0x0119, 0x0113,
+ 0x010D, 0x00E9, 0x017A, 0x0117, 0x0123, 0x0137, 0x012B, 0x013C,
+ 0x0161, 0x0144, 0x0146, 0x00F3, 0x014D, 0x00F5, 0x00F6, 0x00F7,
+ 0x0173, 0x0142, 0x015B, 0x016B, 0x00FC, 0x017C, 0x017E, 0x02D9} },
+ { "windows-1258", { "CP1258", 0 }, 2258,
+ { 0x20AC, 0xFFFD, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
+ 0x02C6, 0x2030, 0xFFFD, 0x2039, 0x0152, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
+ 0x02DC, 0x2122, 0xFFFD, 0x203A, 0x0153, 0xFFFD, 0xFFFD, 0x0178,
+ 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
+ 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
+ 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
+ 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
+ 0x00C0, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
+ 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x0300, 0x00CD, 0x00CE, 0x00CF,
+ 0x0110, 0x00D1, 0x0309, 0x00D3, 0x00D4, 0x01A0, 0x00D6, 0x00D7,
+ 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x01AF, 0x0303, 0x00DF,
+ 0x00E0, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
+ 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0301, 0x00ED, 0x00EE, 0x00EF,
+ 0x0111, 0x00F1, 0x0323, 0x00F3, 0x00F4, 0x01A1, 0x00F6, 0x00F7,
+ 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x01B0, 0x20AB, 0x00FF} },
+
+#endif
+ { "Apple Roman", { "macintosh", "MacRoman", 0 }, -168,
+ { 0x00C4, 0x00C5, 0x00C7, 0x00C9, 0x00D1, 0x00D6, 0x00DC, 0x00E1,
+ 0x00E0, 0x00E2, 0x00E4, 0x00E3, 0x00E5, 0x00E7, 0x00E9, 0x00E8,
+ 0x00EA, 0x00EB, 0x00ED, 0x00EC, 0x00EE, 0x00EF, 0x00F1, 0x00F3,
+ 0x00F2, 0x00F4, 0x00F6, 0x00F5, 0x00FA, 0x00F9, 0x00FB, 0x00FC,
+ 0x2020, 0x00B0, 0x00A2, 0x00A3, 0x00A7, 0x2022, 0x00B6, 0x00DF,
+ 0x00AE, 0x00A9, 0x2122, 0x00B4, 0x00A8, 0x2260, 0x00C6, 0x00D8,
+ 0x221E, 0x00B1, 0x2264, 0x2265, 0x00A5, 0x00B5, 0x2202, 0x2211,
+ 0x220F, 0x03C0, 0x222B, 0x00AA, 0x00BA, 0x03A9, 0x00E6, 0x00F8,
+ 0x00BF, 0x00A1, 0x00AC, 0x221A, 0x0192, 0x2248, 0x2206, 0x00AB,
+ 0x00BB, 0x2026, 0x00A0, 0x00C0, 0x00C3, 0x00D5, 0x0152, 0x0153,
+ 0x2013, 0x2014, 0x201C, 0x201D, 0x2018, 0x2019, 0x00F7, 0x25CA,
+ 0x00FF, 0x0178, 0x2044, 0x20AC, 0x2039, 0x203A, 0xFB01, 0xFB02,
+ 0x2021, 0x00B7, 0x201A, 0x201E, 0x2030, 0x00C2, 0x00CA, 0x00C1,
+ 0x00CB, 0x00C8, 0x00CD, 0x00CE, 0x00CF, 0x00CC, 0x00D3, 0x00D4,
+ 0xF8FF, 0x00D2, 0x00DA, 0x00DB, 0x00D9, 0x0131, 0x02C6, 0x02DC,
+ 0x00AF, 0x02D8, 0x02D9, 0x02DA, 0x00B8, 0x02DD, 0x02DB, 0x02C7} },
+
+ // This one is based on the charmap file
+ // /usr/share/i18n/charmaps/SAMI-WS2.gz, which is manually adapted
+ // to this format by Boerre Gaup <boerre@subdimension.com>
+ { "WINSAMI2", { "WS2", 0 }, -165,
+ { 0x20AC, 0xFFFD, 0x010C, 0x0192, 0x010D, 0x01B7, 0x0292, 0x01EE,
+ 0x01EF, 0x0110, 0x0160, 0x2039, 0x0152, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
+ 0x0111, 0x01E6, 0x0161, 0x203A, 0x0153, 0xFFFD, 0xFFFD, 0x0178,
+ 0x00A0, 0x01E7, 0x01E4, 0x00A3, 0x00A4, 0x01E5, 0x00A6, 0x00A7,
+ 0x00A8, 0x00A9, 0x021E, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x021F,
+ 0x00B0, 0x00B1, 0x01E8, 0x01E9, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
+ 0x014A, 0x014B, 0x0166, 0x00BB, 0x0167, 0x00BD, 0x017D, 0x017E,
+ 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
+ 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
+ 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
+ 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
+ 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
+ 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
+ 0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
+ 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF} },
+
+#ifndef Q_OS_SYMBIAN
+ // this one is generated from the charmap file located in /usr/share/i18n/charmaps
+ // on most Linux distributions. The thai character set tis620 is byte by byte equivalent
+ // to iso8859-11, so we name it 8859-11 here, but recognise the name tis620 too.
+
+ // $ for A in 8 9 A B C D E F ; do for B in 0 1 2 3 4 5 6 7 8 9 A B C D E F ; do echo x${A}${B} 0xFFFD ; done ; done > /tmp/digits ; (cut -c25- < TIS-620 ; cat /tmp/digits) | awk '/^x[89ABCDEF]/{ print $1, $2 }' | sed -e 's/<U/0x/' -e 's/>//' | sort | uniq -w4 | cut -c5- | paste '-d ' - - - - - - - - | sed -e 's/ /, /g' -e 's/$/,/' -e '$ s/,$/} },/' -e '1 s/^/{ /' > ~/tmp/tis-620
+ { "TIS-620", { "ISO 8859-11", 0 }, 2259, // Thai character set mib enum taken from tis620 (which is byte by byte equivalent)
+ { 0x20AC, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x2026, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0x0E01, 0x0E02, 0x0E03, 0x0E04, 0x0E05, 0x0E06, 0x0E07,
+ 0x0E08, 0x0E09, 0x0E0A, 0x0E0B, 0x0E0C, 0x0E0D, 0x0E0E, 0x0E0F,
+ 0x0E10, 0x0E11, 0x0E12, 0x0E13, 0x0E14, 0x0E15, 0x0E16, 0x0E17,
+ 0x0E18, 0x0E19, 0x0E1A, 0x0E1B, 0x0E1C, 0x0E1D, 0x0E1E, 0x0E1F,
+ 0x0E20, 0x0E21, 0x0E22, 0x0E23, 0x0E24, 0x0E25, 0x0E26, 0x0E27,
+ 0x0E28, 0x0E29, 0x0E2A, 0x0E2B, 0x0E2C, 0x0E2D, 0x0E2E, 0x0E2F,
+ 0x0E30, 0x0E31, 0x0E32, 0x0E33, 0x0E34, 0x0E35, 0x0E36, 0x0E37,
+ 0x0E38, 0x0E39, 0x0E3A, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x0E3F,
+ 0x0E40, 0x0E41, 0x0E42, 0x0E43, 0x0E44, 0x0E45, 0x0E46, 0x0E47,
+ 0x0E48, 0x0E49, 0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D, 0x0E4E, 0x0E4F,
+ 0x0E50, 0x0E51, 0x0E52, 0x0E53, 0x0E54, 0x0E55, 0x0E56, 0x0E57,
+ 0x0E58, 0x0E59, 0x0E5A, 0x0E5B, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD } },
+
+#endif
+ /*
+ Name: hp-roman8 [HP-PCL5,RFC1345,KXS2]
+ MIBenum: 2004
+ Source: LaserJet IIP Printer User's Manual,
+ HP part no 33471-90901, Hewlet-Packard, June 1989.
+ Alias: roman8
+ Alias: r8
+ Alias: csHPRoman8
+ */
+ { "roman8", { "hp-roman8", "csHPRoman8", 0 }, 2004,
+ { 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+ 0x00A0, 0x00C0, 0x00C2, 0x00C8, 0x00CA, 0x00CB, 0x00CE, 0x00CF,
+ 0x00B4, 0x02CB, 0x02C6, 0x00A8, 0x02DC, 0x00D9, 0x00DB, 0x20A4,
+ 0x00AF, 0x00DD, 0x00FD, 0x00B0, 0x00C7, 0x00E7, 0x00D1, 0x00F1,
+ 0x00A1, 0x00BF, 0x00A4, 0x00A3, 0x00A5, 0x00A7, 0x0192, 0x00A2,
+ 0x00E2, 0x00EA, 0x00F4, 0x00FB, 0x00E1, 0x00E9, 0x00F3, 0x00FA,
+ 0x00E0, 0x00E8, 0x00F2, 0x00F9, 0x00E4, 0x00EB, 0x00F6, 0x00FC,
+ 0x00C5, 0x00EE, 0x00D8, 0x00C6, 0x00E5, 0x00ED, 0x00F8, 0x00E6,
+ 0x00C4, 0x00EC, 0x00D6, 0x00DC, 0x00C9, 0x00EF, 0x00DF, 0x00D4,
+ 0x00C1, 0x00C3, 0x00E3, 0x00D0, 0x00F0, 0x00CD, 0x00CC, 0x00D3,
+ 0x00D2, 0x00D5, 0x00F5, 0x0160, 0x0161, 0x00DA, 0x0178, 0x00FF,
+ 0x00DE, 0x00FE, 0x00B7, 0x00B5, 0x00B6, 0x00BE, 0x2014, 0x00BC,
+ 0x00BD, 0x00AA, 0x00BA, 0x00AB, 0x25A0, 0x00BB, 0x00B1, 0xFFFD } }
+
+ // if you add more chacater sets at the end, change LAST_MIB above
+};
+
+QSimpleTextCodec::QSimpleTextCodec(int i) : forwardIndex(i), reverseMap(0)
+{
+}
+
+
+QSimpleTextCodec::~QSimpleTextCodec()
+{
+ delete reverseMap;
+}
+
+static QByteArray *buildReverseMap(int forwardIndex)
+{
+ QByteArray *map = new QByteArray();
+ int m = 0;
+ int i = 0;
+ while(i < 128) {
+ if (unicodevalues[forwardIndex].values[i] > m &&
+ unicodevalues[forwardIndex].values[i] < 0xfffd)
+ m = unicodevalues[forwardIndex].values[i];
+ i++;
+ }
+ m++;
+ map->resize(m);
+ for(i = 0; i < 128 && i < m; i++)
+ (*map)[i] = (char)i;
+ for(;i < m; i++)
+ (*map)[i] = 0;
+ for(i=128; i<256; i++) {
+ int u = unicodevalues[forwardIndex].values[i-128];
+ if (u < m)
+ (*map)[u] = (char)(unsigned char)(i);
+ }
+ return map;
+}
+
+QString QSimpleTextCodec::convertToUnicode(const char* chars, int len, ConverterState *) const
+{
+ if (len <= 0 || chars == 0)
+ return QString();
+
+ const unsigned char * c = (const unsigned char *)chars;
+
+ QString r(len, Qt::Uninitialized);
+ QChar* uc = r.data();
+
+ for (int i = 0; i < len; i++) {
+ if (c[i] > 127)
+ uc[i] = unicodevalues[forwardIndex].values[c[i]-128];
+ else
+ uc[i] = QLatin1Char(c[i]);
+ }
+ return r;
+}
+
+QByteArray QSimpleTextCodec::convertFromUnicode(const QChar *in, int length, ConverterState *state) const
+{
+ const char replacement = (state && state->flags & ConvertInvalidToNull) ? 0 : '?';
+ int invalid = 0;
+
+ if (!reverseMap){
+ QByteArray *tmp = buildReverseMap(this->forwardIndex);
+ if (!reverseMap.testAndSetOrdered(0, tmp))
+ delete tmp;
+ }
+
+ QByteArray r(length, Qt::Uninitialized);
+ int i = length;
+ int u;
+ const QChar* ucp = in;
+ unsigned char* rp = (unsigned char *)r.data();
+ const unsigned char* rmp = (const unsigned char *)reverseMap->constData();
+ int rmsize = (int) reverseMap->size();
+ while(i--)
+ {
+ u = ucp->unicode();
+ if (u < 128) {
+ *rp = (char)u;
+ } else {
+ *rp = ((u < rmsize) ? (*(rmp+u)) : 0);
+ if (*rp == 0) {
+ *rp = replacement;
+ ++invalid;
+ }
+ }
+ rp++;
+ ucp++;
+ }
+
+ if (state) {
+ state->invalidChars += invalid;
+ }
+ return r;
+}
+
+QByteArray QSimpleTextCodec::name() const
+{
+ return unicodevalues[forwardIndex].mime;
+}
+
+QList<QByteArray> QSimpleTextCodec::aliases() const
+{
+ QList<QByteArray> list;
+ const char * const*a = unicodevalues[forwardIndex].aliases;
+ while (*a) {
+ list << *a;
+ ++a;
+ }
+ return list;
+}
+
+int QSimpleTextCodec::mibEnum() const
+{
+ return unicodevalues[forwardIndex].mib;
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_TEXTCODEC
diff --git a/src/corelib/codecs/qsimplecodec_p.h b/src/corelib/codecs/qsimplecodec_p.h
new file mode 100644
index 0000000000..ea771a68b7
--- /dev/null
+++ b/src/corelib/codecs/qsimplecodec_p.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSIMPLECODEC_P_H
+#define QSIMPLECODEC_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "QtCore/qtextcodec.h"
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_TEXTCODEC
+
+template <typename T> class QAtomicPointer;
+
+class QSimpleTextCodec: public QTextCodec
+{
+public:
+#ifdef Q_OS_SYMBIAN
+ enum { numSimpleCodecs = 5 };
+#else
+ enum { numSimpleCodecs = 30 };
+#endif
+ explicit QSimpleTextCodec(int);
+ ~QSimpleTextCodec();
+
+ QString convertToUnicode(const char *, int, ConverterState *) const;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+
+ QByteArray name() const;
+ QList<QByteArray> aliases() const;
+ int mibEnum() const;
+
+private:
+ int forwardIndex;
+ mutable QAtomicPointer<QByteArray> reverseMap;
+};
+
+#endif // QT_NO_TEXTCODEC
+
+QT_END_NAMESPACE
+
+#endif // QSIMPLECODEC_P_H
diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp
new file mode 100644
index 0000000000..3c3d39ed99
--- /dev/null
+++ b/src/corelib/codecs/qtextcodec.cpp
@@ -0,0 +1,1878 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qplatformdefs.h"
+#include "qtextcodec.h"
+#include "qtextcodec_p.h"
+
+#ifndef QT_NO_TEXTCODEC
+
+#include "qlist.h"
+#include "qfile.h"
+#ifndef QT_NO_LIBRARY
+# include "qcoreapplication.h"
+# include "qtextcodecplugin.h"
+# include "private/qfactoryloader_p.h"
+#endif
+#include "qstringlist.h"
+
+#ifdef Q_OS_UNIX
+# include "qiconvcodec_p.h"
+#endif
+
+#include "qutfcodec_p.h"
+#include "qsimplecodec_p.h"
+#include "qlatincodec_p.h"
+#ifndef QT_NO_CODECS
+# include "qtsciicodec_p.h"
+# include "qisciicodec_p.h"
+#if !defined(Q_OS_SYMBIAN) && !defined(Q_OS_INTEGRITY)
+# if defined(QT_NO_ICONV) && !defined(QT_BOOTSTRAPPED)
+// no iconv(3) support, must build all codecs into the library
+# include "../../plugins/codecs/cn/qgb18030codec.h"
+# include "../../plugins/codecs/jp/qeucjpcodec.h"
+# include "../../plugins/codecs/jp/qjiscodec.h"
+# include "../../plugins/codecs/jp/qsjiscodec.h"
+# include "../../plugins/codecs/kr/qeuckrcodec.h"
+# include "../../plugins/codecs/tw/qbig5codec.h"
+# endif // QT_NO_ICONV
+# if defined(Q_WS_X11) && !defined(QT_BOOTSTRAPPED)
+# include "qfontlaocodec_p.h"
+# include "../../plugins/codecs/jp/qfontjpcodec.h"
+# endif
+#endif // QT_NO_SYMBIAN
+#endif // QT_NO_CODECS
+#include "qlocale.h"
+#include "qmutex.h"
+#include "qhash.h"
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <locale.h>
+#if defined (_XOPEN_UNIX) && !defined(Q_OS_QNX) && !defined(Q_OS_OSF)
+#include <langinfo.h>
+#endif
+
+#if defined(Q_OS_WINCE)
+# define QT_NO_SETLOCALE
+#endif
+
+#ifdef Q_OS_SYMBIAN
+#include "qtextcodec_symbian.cpp"
+#endif
+
+
+// enabling this is not exception safe!
+// #define Q_DEBUG_TEXTCODEC
+
+QT_BEGIN_NAMESPACE
+
+#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_TEXTCODECPLUGIN)
+Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
+ (QTextCodecFactoryInterface_iid, QLatin1String("/codecs")))
+#endif
+
+//Cache for QTextCodec::codecForName and codecForMib.
+typedef QHash<QByteArray, QTextCodec *> QTextCodecCache;
+Q_GLOBAL_STATIC(QTextCodecCache, qTextCodecCache)
+
+
+static char qtolower(register char c)
+{ if (c >= 'A' && c <= 'Z') return c + 0x20; return c; }
+static bool qisalnum(register char c)
+{ return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); }
+
+static bool nameMatch(const QByteArray &name, const QByteArray &test)
+{
+ // if they're the same, return a perfect score
+ if (qstricmp(name, test) == 0)
+ return true;
+
+ const char *n = name.constData();
+ const char *h = test.constData();
+
+ // if the letters and numbers are the same, we have a match
+ while (*n != '\0') {
+ if (qisalnum(*n)) {
+ for (;;) {
+ if (*h == '\0')
+ return false;
+ if (qisalnum(*h))
+ break;
+ ++h;
+ }
+ if (qtolower(*n) != qtolower(*h))
+ return false;
+ ++h;
+ }
+ ++n;
+ }
+ while (*h && !qisalnum(*h))
+ ++h;
+ return (*h == '\0');
+}
+
+
+static QTextCodec *createForName(const QByteArray &name)
+{
+#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_TEXTCODECPLUGIN)
+ QFactoryLoader *l = loader();
+ QStringList keys = l->keys();
+ for (int i = 0; i < keys.size(); ++i) {
+ if (nameMatch(name, keys.at(i).toLatin1())) {
+ QString realName = keys.at(i);
+ if (QTextCodecFactoryInterface *factory
+ = qobject_cast<QTextCodecFactoryInterface*>(l->instance(realName))) {
+ return factory->create(realName);
+ }
+ }
+ }
+#else
+ Q_UNUSED(name);
+#endif
+ return 0;
+}
+
+static QTextCodec *createForMib(int mib)
+{
+#ifndef QT_NO_TEXTCODECPLUGIN
+ QString name = QLatin1String("MIB: ") + QString::number(mib);
+ if (QTextCodecFactoryInterface *factory
+ = qobject_cast<QTextCodecFactoryInterface*>(loader()->instance(name)))
+ return factory->create(name);
+#else
+ Q_UNUSED(mib);
+#endif
+ return 0;
+}
+
+static QList<QTextCodec*> *all = 0;
+#ifdef Q_DEBUG_TEXTCODEC
+static bool destroying_is_ok = false;
+#endif
+
+static QTextCodec *localeMapper = 0;
+QTextCodec *QTextCodec::cftr = 0;
+
+
+class QTextCodecCleanup
+{
+public:
+ ~QTextCodecCleanup();
+};
+
+/*
+ Deletes all the created codecs. This destructor is called just
+ before exiting to delete any QTextCodec objects that may be lying
+ around.
+*/
+QTextCodecCleanup::~QTextCodecCleanup()
+{
+ if (!all)
+ return;
+
+#ifdef Q_DEBUG_TEXTCODEC
+ destroying_is_ok = true;
+#endif
+
+ for (QList<QTextCodec *>::const_iterator it = all->constBegin()
+ ; it != all->constEnd(); ++it) {
+ delete *it;
+ }
+ delete all;
+ all = 0;
+ localeMapper = 0;
+
+#ifdef Q_DEBUG_TEXTCODEC
+ destroying_is_ok = false;
+#endif
+}
+
+Q_GLOBAL_STATIC(QTextCodecCleanup, createQTextCodecCleanup)
+
+bool QTextCodec::validCodecs()
+{
+#ifdef Q_OS_SYMBIAN
+ // If we don't have a trap handler, we're outside of the main() function,
+ // ie. in global constructors or destructors. Don't use codecs in this
+ // case as it would lead to crashes because we don't have a cleanup stack on Symbian
+ return (User::TrapHandler() != NULL);
+#else
+ return true;
+#endif
+}
+
+
+#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
+class QWindowsLocalCodec: public QTextCodec
+{
+public:
+ QWindowsLocalCodec();
+ ~QWindowsLocalCodec();
+
+ QString convertToUnicode(const char *, int, ConverterState *) const;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+ QString convertToUnicodeCharByChar(const char *chars, int length, ConverterState *state) const;
+
+ QByteArray name() const;
+ int mibEnum() const;
+
+};
+
+QWindowsLocalCodec::QWindowsLocalCodec()
+{
+}
+
+QWindowsLocalCodec::~QWindowsLocalCodec()
+{
+}
+
+QString QWindowsLocalCodec::convertToUnicode(const char *chars, int length, ConverterState *state) const
+{
+ const char *mb = chars;
+ int mblen = length;
+
+ if (!mb || !mblen)
+ return QString();
+
+ const int wclen_auto = 4096;
+ wchar_t wc_auto[wclen_auto];
+ int wclen = wclen_auto;
+ wchar_t *wc = wc_auto;
+ int len;
+ QString sp;
+ bool prepend = false;
+ char state_data = 0;
+ int remainingChars = 0;
+
+ //save the current state information
+ if (state) {
+ state_data = (char)state->state_data[0];
+ remainingChars = state->remainingChars;
+ }
+
+ //convert the pending charcter (if available)
+ if (state && remainingChars) {
+ char prev[3] = {0};
+ prev[0] = state_data;
+ prev[1] = mb[0];
+ remainingChars = 0;
+ len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
+ prev, 2, wc, wclen);
+ if (len) {
+ prepend = true;
+ sp.append(QChar(wc[0]));
+ mb++;
+ mblen--;
+ wc[0] = 0;
+ }
+ }
+
+ while (!(len=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
+ mb, mblen, wc, wclen))) {
+ int r = GetLastError();
+ if (r == ERROR_INSUFFICIENT_BUFFER) {
+ if (wc != wc_auto) {
+ qWarning("MultiByteToWideChar: Size changed");
+ break;
+ } else {
+ wclen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
+ mb, mblen, 0, 0);
+ wc = new wchar_t[wclen];
+ // and try again...
+ }
+ } else if (r == ERROR_NO_UNICODE_TRANSLATION) {
+ //find the last non NULL character
+ while (mblen > 1 && !(mb[mblen-1]))
+ mblen--;
+ //check whether, we hit an invalid character in the middle
+ if ((mblen <= 1) || (remainingChars && state_data))
+ return convertToUnicodeCharByChar(chars, length, state);
+ //Remove the last character and try again...
+ state_data = mb[mblen-1];
+ remainingChars = 1;
+ mblen--;
+ } else {
+ // Fail.
+ qWarning("MultiByteToWideChar: Cannot convert multibyte text");
+ break;
+ }
+ }
+ if (len <= 0)
+ return QString();
+ if (wc[len-1] == 0) // len - 1: we don't want terminator
+ --len;
+
+ //save the new state information
+ if (state) {
+ state->state_data[0] = (char)state_data;
+ state->remainingChars = remainingChars;
+ }
+ QString s((QChar*)wc, len);
+ if (wc != wc_auto)
+ delete [] wc;
+ if (prepend) {
+ return sp+s;
+ }
+ return s;
+}
+
+QString QWindowsLocalCodec::convertToUnicodeCharByChar(const char *chars, int length, ConverterState *state) const
+{
+ if (!chars || !length)
+ return QString();
+
+ int copyLocation = 0;
+ int extra = 2;
+ if (state && state->remainingChars) {
+ copyLocation = state->remainingChars;
+ extra += copyLocation;
+ }
+ int newLength = length + extra;
+ char *mbcs = new char[newLength];
+ //ensure that we have a NULL terminated string
+ mbcs[newLength-1] = 0;
+ mbcs[newLength-2] = 0;
+ memcpy(&(mbcs[copyLocation]), chars, length);
+ if (copyLocation) {
+ //copy the last character from the state
+ mbcs[0] = (char)state->state_data[0];
+ state->remainingChars = 0;
+ }
+ const char *mb = mbcs;
+#ifndef Q_OS_WINCE
+ const char *next = 0;
+ QString s;
+ while((next = CharNextExA(CP_ACP, mb, 0)) != mb) {
+ wchar_t wc[2] ={0};
+ int charlength = next - mb;
+ int len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS, mb, charlength, wc, 2);
+ if (len>0) {
+ s.append(QChar(wc[0]));
+ } else {
+ int r = GetLastError();
+ //check if the character being dropped is the last character
+ if (r == ERROR_NO_UNICODE_TRANSLATION && mb == (mbcs+newLength -3) && state) {
+ state->remainingChars = 1;
+ state->state_data[0] = (char)*mb;
+ }
+ }
+ mb = next;
+ }
+#else
+ QString s;
+ int size = mbstowcs(NULL, mb, length);
+ if (size < 0) {
+ Q_ASSERT("Error in CE TextCodec");
+ return QString();
+ }
+ wchar_t* ws = new wchar_t[size + 2];
+ ws[size +1] = 0;
+ ws[size] = 0;
+ size = mbstowcs(ws, mb, length);
+ for (int i=0; i< size; i++)
+ s.append(QChar(ws[i]));
+ delete [] ws;
+#endif
+ delete mbcs;
+ return s;
+}
+
+QByteArray QWindowsLocalCodec::convertFromUnicode(const QChar *ch, int uclen, ConverterState *) const
+{
+ if (!ch)
+ return QByteArray();
+ if (uclen == 0)
+ return QByteArray("");
+ BOOL used_def;
+ QByteArray mb(4096, 0);
+ int len;
+ while (!(len=WideCharToMultiByte(CP_ACP, 0, (const wchar_t*)ch, uclen,
+ mb.data(), mb.size()-1, 0, &used_def)))
+ {
+ int r = GetLastError();
+ if (r == ERROR_INSUFFICIENT_BUFFER) {
+ mb.resize(1+WideCharToMultiByte(CP_ACP, 0,
+ (const wchar_t*)ch, uclen,
+ 0, 0, 0, &used_def));
+ // and try again...
+ } else {
+#ifndef QT_NO_DEBUG
+ // Fail.
+ qWarning("WideCharToMultiByte: Cannot convert multibyte text (error %d): %s (UTF-8)",
+ r, QString(ch, uclen).toLocal8Bit().data());
+#endif
+ break;
+ }
+ }
+ mb.resize(len);
+ return mb;
+}
+
+
+QByteArray QWindowsLocalCodec::name() const
+{
+ return "System";
+}
+
+int QWindowsLocalCodec::mibEnum() const
+{
+ return 0;
+}
+
+#else
+
+/* locale names mostly copied from XFree86 */
+static const char * const iso8859_2locales[] = {
+ "croatian", "cs", "cs_CS", "cs_CZ","cz", "cz_CZ", "czech", "hr",
+ "hr_HR", "hu", "hu_HU", "hungarian", "pl", "pl_PL", "polish", "ro",
+ "ro_RO", "rumanian", "serbocroatian", "sh", "sh_SP", "sh_YU", "sk",
+ "sk_SK", "sl", "sl_CS", "sl_SI", "slovak", "slovene", "sr_SP", 0 };
+
+static const char * const iso8859_3locales[] = {
+ "eo", 0 };
+
+static const char * const iso8859_4locales[] = {
+ "ee", "ee_EE", 0 };
+
+static const char * const iso8859_5locales[] = {
+ "mk", "mk_MK", "sp", "sp_YU", 0 };
+
+static const char * const cp_1251locales[] = {
+ "be", "be_BY", "bg", "bg_BG", "bulgarian", 0 };
+
+static const char * const pt_154locales[] = {
+ "ba_RU", "ky", "ky_KG", "kk", "kk_KZ", 0 };
+
+static const char * const iso8859_6locales[] = {
+ "ar_AA", "ar_SA", "arabic", 0 };
+
+static const char * const iso8859_7locales[] = {
+ "el", "el_GR", "greek", 0 };
+
+static const char * const iso8859_8locales[] = {
+ "hebrew", "he", "he_IL", "iw", "iw_IL", 0 };
+
+static const char * const iso8859_9locales[] = {
+ "tr", "tr_TR", "turkish", 0 };
+
+static const char * const iso8859_13locales[] = {
+ "lt", "lt_LT", "lv", "lv_LV", 0 };
+
+static const char * const iso8859_15locales[] = {
+ "et", "et_EE",
+ // Euro countries
+ "br_FR", "ca_ES", "de", "de_AT", "de_BE", "de_DE", "de_LU", "en_IE",
+ "es", "es_ES", "eu_ES", "fi", "fi_FI", "finnish", "fr", "fr_FR",
+ "fr_BE", "fr_LU", "french", "ga_IE", "gl_ES", "it", "it_IT", "oc_FR",
+ "nl", "nl_BE", "nl_NL", "pt", "pt_PT", "sv_FI", "wa_BE",
+ 0 };
+
+static const char * const koi8_ulocales[] = {
+ "uk", "uk_UA", "ru_UA", "ukrainian", 0 };
+
+static const char * const tis_620locales[] = {
+ "th", "th_TH", "thai", 0 };
+
+// static const char * const tcvnlocales[] = {
+// "vi", "vi_VN", 0 };
+
+static bool try_locale_list(const char * const locale[], const QByteArray &lang)
+{
+ int i;
+ for(i=0; locale[i] && lang != locale[i]; i++)
+ ;
+ return locale[i] != 0;
+}
+
+// For the probably_koi8_locales we have to look. the standard says
+// these are 8859-5, but almost all Russian users use KOI8-R and
+// incorrectly set $LANG to ru_RU. We'll check tolower() to see what
+// it thinks ru_RU means.
+
+// If you read the history, it seems that many Russians blame ISO and
+// Perestroika for the confusion.
+//
+// The real bug is that some programs break if the user specifies
+// ru_RU.KOI8-R.
+
+static const char * const probably_koi8_rlocales[] = {
+ "ru", "ru_SU", "ru_RU", "russian", 0 };
+
+static QTextCodec * ru_RU_hack(const char * i) {
+ QTextCodec * ru_RU_codec = 0;
+
+#if !defined(QT_NO_SETLOCALE)
+ QByteArray origlocale(setlocale(LC_CTYPE, i));
+#else
+ QByteArray origlocale(i);
+#endif
+ // unicode koi8r latin5 name
+ // 0x044E 0xC0 0xEE CYRILLIC SMALL LETTER YU
+ // 0x042E 0xE0 0xCE CYRILLIC CAPITAL LETTER YU
+ int latin5 = tolower(0xCE);
+ int koi8r = tolower(0xE0);
+ if (koi8r == 0xC0 && latin5 != 0xEE) {
+ ru_RU_codec = QTextCodec::codecForName("KOI8-R");
+ } else if (koi8r != 0xC0 && latin5 == 0xEE) {
+ ru_RU_codec = QTextCodec::codecForName("ISO 8859-5");
+ } else {
+ // something else again... let's assume... *throws dice*
+ ru_RU_codec = QTextCodec::codecForName("KOI8-R");
+ qWarning("QTextCodec: Using KOI8-R, probe failed (%02x %02x %s)",
+ koi8r, latin5, i);
+ }
+#if !defined(QT_NO_SETLOCALE)
+ setlocale(LC_CTYPE, origlocale);
+#endif
+
+ return ru_RU_codec;
+}
+
+#endif
+
+#if !defined(Q_OS_WIN32) && !defined(Q_OS_WINCE)
+static QTextCodec *checkForCodec(const QByteArray &name) {
+ QTextCodec *c = QTextCodec::codecForName(name);
+ if (!c) {
+ const int index = name.indexOf('@');
+ if (index != -1) {
+ c = QTextCodec::codecForName(name.left(index));
+ }
+ }
+ return c;
+}
+#endif
+
+/* the next two functions are implicitely thread safe,
+ as they are only called by setup() which uses a mutex.
+*/
+static void setupLocaleMapper()
+{
+#ifdef Q_OS_SYMBIAN
+ localeMapper = QSymbianTextCodec::localeMapper;
+ if (localeMapper)
+ return;
+#endif
+
+#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
+ localeMapper = QTextCodec::codecForName("System");
+#else
+
+#ifndef QT_NO_ICONV
+ localeMapper = QTextCodec::codecForName("System");
+#endif
+
+#if defined (_XOPEN_UNIX) && !defined(Q_OS_QNX) && !defined(Q_OS_OSF)
+ if (!localeMapper) {
+ char *charset = nl_langinfo (CODESET);
+ if (charset)
+ localeMapper = QTextCodec::codecForName(charset);
+ }
+#endif
+
+ if (!localeMapper) {
+ // Very poorly defined and followed standards causes lots of
+ // code to try to get all the cases... This logic is
+ // duplicated in QIconvCodec, so if you change it here, change
+ // it there too.
+
+ // Try to determine locale codeset from locale name assigned to
+ // LC_CTYPE category.
+
+ // First part is getting that locale name. First try setlocale() which
+ // definitely knows it, but since we cannot fully trust it, get ready
+ // to fall back to environment variables.
+#if !defined(QT_NO_SETLOCALE)
+ const QByteArray ctype = setlocale(LC_CTYPE, 0);
+#else
+ const QByteArray ctype;
+#endif
+
+ // Get the first nonempty value from $LC_ALL, $LC_CTYPE, and $LANG
+ // environment variables.
+ QByteArray lang = qgetenv("LC_ALL");
+ if (lang.isEmpty() || lang == "C") {
+ lang = qgetenv("LC_CTYPE");
+ }
+ if (lang.isEmpty() || lang == "C") {
+ lang = qgetenv("LANG");
+ }
+
+ // Now try these in order:
+ // 1. CODESET from ctype if it contains a .CODESET part (e.g. en_US.ISO8859-15)
+ // 2. CODESET from lang if it contains a .CODESET part
+ // 3. ctype (maybe the locale is named "ISO-8859-1" or something)
+ // 4. locale (ditto)
+ // 5. check for "@euro"
+ // 6. guess locale from ctype unless ctype is "C"
+ // 7. guess locale from lang
+
+ // 1. CODESET from ctype if it contains a .CODESET part (e.g. en_US.ISO8859-15)
+ int indexOfDot = ctype.indexOf('.');
+ if (indexOfDot != -1)
+ localeMapper = checkForCodec( ctype.mid(indexOfDot + 1) );
+
+ // 2. CODESET from lang if it contains a .CODESET part
+ if (!localeMapper) {
+ indexOfDot = lang.indexOf('.');
+ if (indexOfDot != -1)
+ localeMapper = checkForCodec( lang.mid(indexOfDot + 1) );
+ }
+
+ // 3. ctype (maybe the locale is named "ISO-8859-1" or something)
+ if (!localeMapper && !ctype.isEmpty() && ctype != "C")
+ localeMapper = checkForCodec(ctype);
+
+ // 4. locale (ditto)
+ if (!localeMapper && !lang.isEmpty())
+ localeMapper = checkForCodec(lang);
+
+ // 5. "@euro"
+ if ((!localeMapper && ctype.contains("@euro")) || lang.contains("@euro"))
+ localeMapper = checkForCodec("ISO 8859-15");
+
+ // 6. guess locale from ctype unless ctype is "C"
+ // 7. guess locale from lang
+ const QByteArray &try_by_name = (!ctype.isEmpty() && ctype != "C") ? lang : ctype;
+
+ // Now do the guessing.
+ if (!lang.isEmpty() && !localeMapper && !try_by_name.isEmpty()) {
+ if (try_locale_list(iso8859_15locales, lang))
+ localeMapper = QTextCodec::codecForName("ISO 8859-15");
+ else if (try_locale_list(iso8859_2locales, lang))
+ localeMapper = QTextCodec::codecForName("ISO 8859-2");
+ else if (try_locale_list(iso8859_3locales, lang))
+ localeMapper = QTextCodec::codecForName("ISO 8859-3");
+ else if (try_locale_list(iso8859_4locales, lang))
+ localeMapper = QTextCodec::codecForName("ISO 8859-4");
+ else if (try_locale_list(iso8859_5locales, lang))
+ localeMapper = QTextCodec::codecForName("ISO 8859-5");
+ else if (try_locale_list(iso8859_6locales, lang))
+ localeMapper = QTextCodec::codecForName("ISO 8859-6");
+ else if (try_locale_list(iso8859_7locales, lang))
+ localeMapper = QTextCodec::codecForName("ISO 8859-7");
+ else if (try_locale_list(iso8859_8locales, lang))
+ localeMapper = QTextCodec::codecForName("ISO 8859-8-I");
+ else if (try_locale_list(iso8859_9locales, lang))
+ localeMapper = QTextCodec::codecForName("ISO 8859-9");
+ else if (try_locale_list(iso8859_13locales, lang))
+ localeMapper = QTextCodec::codecForName("ISO 8859-13");
+ else if (try_locale_list(tis_620locales, lang))
+ localeMapper = QTextCodec::codecForName("ISO 8859-11");
+ else if (try_locale_list(koi8_ulocales, lang))
+ localeMapper = QTextCodec::codecForName("KOI8-U");
+ else if (try_locale_list(cp_1251locales, lang))
+ localeMapper = QTextCodec::codecForName("CP 1251");
+ else if (try_locale_list(pt_154locales, lang))
+ localeMapper = QTextCodec::codecForName("PT 154");
+ else if (try_locale_list(probably_koi8_rlocales, lang))
+ localeMapper = ru_RU_hack(lang);
+ }
+
+ }
+
+ // If everything failed, we default to 8859-1
+ // We could perhaps default to 8859-15.
+ if (!localeMapper)
+ localeMapper = QTextCodec::codecForName("ISO 8859-1");
+#endif
+}
+
+#ifndef QT_NO_THREAD
+Q_GLOBAL_STATIC_WITH_ARGS(QMutex, textCodecsMutex, (QMutex::Recursive));
+#endif
+
+// textCodecsMutex need to be locked to enter this function
+static void setup()
+{
+ if (all)
+ return;
+
+#ifdef Q_OS_SYMBIAN
+ // If we don't have a trap handler, we're outside of the main() function,
+ // ie. in global constructors or destructors. Don't create codecs in this
+ // case as it would lead to crashes because of a missing cleanup stack on Symbian
+ if (User::TrapHandler() == NULL)
+ return;
+#endif
+
+#ifdef Q_DEBUG_TEXTCODEC
+ if (destroying_is_ok)
+ qWarning("QTextCodec: Creating new codec during codec cleanup");
+#endif
+ all = new QList<QTextCodec*>;
+ // create the cleanup object to cleanup all codecs on exit
+ (void) createQTextCodecCleanup();
+
+#ifndef QT_NO_CODECS
+ (void)new QTsciiCodec;
+ for (int i = 0; i < 9; ++i)
+ (void)new QIsciiCodec(i);
+
+ for (int i = 0; i < QSimpleTextCodec::numSimpleCodecs; ++i)
+ (void)new QSimpleTextCodec(i);
+
+#ifdef Q_OS_SYMBIAN
+ localeMapper = QSymbianTextCodec::init();
+#endif
+
+# if defined(Q_WS_X11) && !defined(QT_BOOTSTRAPPED)
+ // no font codecs when bootstrapping
+ (void)new QFontLaoCodec;
+# if defined(QT_NO_ICONV)
+ // no iconv(3) support, must build all codecs into the library
+ (void)new QFontGb2312Codec;
+ (void)new QFontGbkCodec;
+ (void)new QFontGb18030_0Codec;
+ (void)new QFontJis0208Codec;
+ (void)new QFontJis0201Codec;
+ (void)new QFontKsc5601Codec;
+ (void)new QFontBig5hkscsCodec;
+ (void)new QFontBig5Codec;
+# endif // QT_NO_ICONV && !QT_BOOTSTRAPPED
+# endif // Q_WS_X11
+
+
+#if !defined(Q_OS_SYMBIAN) && !defined(Q_OS_INTEGRITY)
+# if defined(QT_NO_ICONV) && !defined(QT_BOOTSTRAPPED)
+ // no asian codecs when bootstrapping, sorry
+ (void)new QGb18030Codec;
+ (void)new QGbkCodec;
+ (void)new QGb2312Codec;
+ (void)new QEucJpCodec;
+ (void)new QJisCodec;
+ (void)new QSjisCodec;
+ (void)new QEucKrCodec;
+ (void)new QCP949Codec;
+ (void)new QBig5Codec;
+ (void)new QBig5hkscsCodec;
+# endif // QT_NO_ICONV && !QT_BOOTSTRAPPED
+#endif //Q_OS_SYMBIAN
+#endif // QT_NO_CODECS
+
+#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
+ (void) new QWindowsLocalCodec;
+#endif // Q_OS_WIN32
+
+ (void)new QUtf16Codec;
+ (void)new QUtf16BECodec;
+ (void)new QUtf16LECodec;
+ (void)new QUtf32Codec;
+ (void)new QUtf32BECodec;
+ (void)new QUtf32LECodec;
+#ifndef Q_OS_SYMBIAN
+ (void)new QLatin15Codec;
+#endif
+ (void)new QLatin1Codec;
+ (void)new QUtf8Codec;
+
+#if !defined(Q_OS_SYMBIAN) && !defined(Q_OS_INTEGRITY)
+#if defined(Q_OS_UNIX) && !defined(QT_NO_ICONV) && !defined(QT_BOOTSTRAPPED)
+ // QIconvCodec depends on the UTF-16 codec, so it needs to be created last
+ (void) new QIconvCodec();
+#endif
+#endif
+
+ if (!localeMapper)
+ setupLocaleMapper();
+}
+
+/*!
+ \enum QTextCodec::ConversionFlag
+
+ \value DefaultConversion No flag is set.
+ \value ConvertInvalidToNull If this flag is set, each invalid input
+ character is output as a null character.
+ \value IgnoreHeader Ignore any Unicode byte-order mark and don't generate any.
+
+ \omitvalue FreeFunction
+*/
+
+/*!
+ \fn QTextCodec::ConverterState::ConverterState(ConversionFlags flags)
+
+ Constructs a ConverterState object initialized with the given \a flags.
+*/
+
+/*!
+ Destroys the ConverterState object.
+*/
+QTextCodec::ConverterState::~ConverterState()
+{
+ if (flags & FreeFunction)
+ (QTextCodecUnalignedPointer::decode(state_data))(this);
+ else if (d)
+ qFree(d);
+}
+
+/*!
+ \class QTextCodec
+ \brief The QTextCodec class provides conversions between text encodings.
+ \reentrant
+ \ingroup i18n
+
+ Qt uses Unicode to store, draw and manipulate strings. In many
+ situations you may wish to deal with data that uses a different
+ encoding. For example, most Japanese documents are still stored
+ in Shift-JIS or ISO 2022-JP, while Russian users often have their
+ documents in KOI8-R or Windows-1251.
+
+ Qt provides a set of QTextCodec classes to help with converting
+ non-Unicode formats to and from Unicode. You can also create your
+ own codec classes.
+
+ The supported encodings are:
+
+ \list
+ \o Apple Roman
+ \o \l{Big5 Text Codec}{Big5}
+ \o \l{Big5-HKSCS Text Codec}{Big5-HKSCS}
+ \o CP949
+ \o \l{EUC-JP Text Codec}{EUC-JP}
+ \o \l{EUC-KR Text Codec}{EUC-KR}
+ \o \l{GBK Text Codec}{GB18030-0}
+ \o IBM 850
+ \o IBM 866
+ \o IBM 874
+ \o \l{ISO 2022-JP (JIS) Text Codec}{ISO 2022-JP}
+ \o ISO 8859-1 to 10
+ \o ISO 8859-13 to 16
+ \o Iscii-Bng, Dev, Gjr, Knd, Mlm, Ori, Pnj, Tlg, and Tml
+ \o JIS X 0201
+ \o JIS X 0208
+ \o KOI8-R
+ \o KOI8-U
+ \o MuleLao-1
+ \o ROMAN8
+ \o \l{Shift-JIS Text Codec}{Shift-JIS}
+ \o TIS-620
+ \o \l{TSCII Text Codec}{TSCII}
+ \o UTF-8
+ \o UTF-16
+ \o UTF-16BE
+ \o UTF-16LE
+ \o UTF-32
+ \o UTF-32BE
+ \o UTF-32LE
+ \o Windows-1250 to 1258
+ \o WINSAMI2
+ \endlist
+
+ QTextCodecs can be used as follows to convert some locally encoded
+ string to Unicode. Suppose you have some string encoded in Russian
+ KOI8-R encoding, and want to convert it to Unicode. The simple way
+ to do it is like this:
+
+ \snippet doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp 0
+
+ After this, \c string holds the text converted to Unicode.
+ Converting a string from Unicode to the local encoding is just as
+ easy:
+
+ \snippet doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp 1
+
+ To read or write files in various encodings, use QTextStream and
+ its \l{QTextStream::setCodec()}{setCodec()} function. See the
+ \l{tools/codecs}{Codecs} example for an application of QTextCodec
+ to file I/O.
+
+ Some care must be taken when trying to convert the data in chunks,
+ for example, when receiving it over a network. In such cases it is
+ possible that a multi-byte character will be split over two
+ chunks. At best this might result in the loss of a character and
+ at worst cause the entire conversion to fail.
+
+ The approach to use in these situations is to create a QTextDecoder
+ object for the codec and use this QTextDecoder for the whole
+ decoding process, as shown below:
+
+ \snippet doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp 2
+
+ The QTextDecoder object maintains state between chunks and therefore
+ works correctly even if a multi-byte character is split between
+ chunks.
+
+ \section1 Creating Your Own Codec Class
+
+ Support for new text encodings can be added to Qt by creating
+ QTextCodec subclasses.
+
+ The pure virtual functions describe the encoder to the system and
+ the coder is used as required in the different text file formats
+ supported by QTextStream, and under X11, for the locale-specific
+ character input and output.
+
+ To add support for another encoding to Qt, make a subclass of
+ QTextCodec and implement the functions listed in the table below.
+
+ \table
+ \header \o Function \o Description
+
+ \row \o name()
+ \o Returns the official name for the encoding. If the
+ encoding is listed in the
+ \l{IANA character-sets encoding file}, the name
+ should be the preferred MIME name for the encoding.
+
+ \row \o aliases()
+ \o Returns a list of alternative names for the encoding.
+ QTextCodec provides a default implementation that returns
+ an empty list. For example, "ISO-8859-1" has "latin1",
+ "CP819", "IBM819", and "iso-ir-100" as aliases.
+
+ \row \o mibEnum()
+ \o Return the MIB enum for the encoding if it is listed in
+ the \l{IANA character-sets encoding file}.
+
+ \row \o convertToUnicode()
+ \o Converts an 8-bit character string to Unicode.
+
+ \row \o convertFromUnicode()
+ \o Converts a Unicode string to an 8-bit character string.
+ \endtable
+
+ You may find it more convenient to make your codec class
+ available as a plugin; see \l{How to Create Qt Plugins} for
+ details.
+
+ \sa QTextStream, QTextDecoder, QTextEncoder, {Codecs Example}
+*/
+
+/*!
+ Constructs a QTextCodec, and gives it the highest precedence. The
+ QTextCodec should always be constructed on the heap (i.e. with \c
+ new). Qt takes ownership and will delete it when the application
+ terminates.
+*/
+QTextCodec::QTextCodec()
+{
+#ifndef QT_NO_THREAD
+ QMutexLocker locker(textCodecsMutex());
+#endif
+ setup();
+ all->prepend(this);
+}
+
+
+/*!
+ \nonreentrant
+
+ Destroys the QTextCodec. Note that you should not delete codecs
+ yourself: once created they become Qt's responsibility.
+*/
+QTextCodec::~QTextCodec()
+{
+#ifdef Q_DEBUG_TEXTCODEC
+ if (!destroying_is_ok)
+ qWarning("QTextCodec::~QTextCodec: Called by application");
+#endif
+ if (all) {
+#ifndef QT_NO_THREAD
+ QMutexLocker locker(textCodecsMutex());
+#endif
+ all->removeAll(this);
+ QTextCodecCache *cache = qTextCodecCache();
+ if (cache)
+ cache->clear();
+ }
+}
+
+/*!
+ \fn QTextCodec *QTextCodec::codecForName(const char *name)
+
+ Searches all installed QTextCodec objects and returns the one
+ which best matches \a name; the match is case-insensitive. Returns
+ 0 if no codec matching the name \a name could be found.
+*/
+
+/*!
+ Searches all installed QTextCodec objects and returns the one
+ which best matches \a name; the match is case-insensitive. Returns
+ 0 if no codec matching the name \a name could be found.
+*/
+QTextCodec *QTextCodec::codecForName(const QByteArray &name)
+{
+ if (name.isEmpty())
+ return 0;
+
+#ifndef QT_NO_THREAD
+ QMutexLocker locker(textCodecsMutex());
+#endif
+ setup();
+
+ if (!validCodecs())
+ return 0;
+
+ QTextCodecCache *cache = qTextCodecCache();
+ QTextCodec *codec;
+ if (cache) {
+ codec = cache->value(name);
+ if (codec)
+ return codec;
+ }
+
+ for (int i = 0; i < all->size(); ++i) {
+ QTextCodec *cursor = all->at(i);
+ if (nameMatch(cursor->name(), name)) {
+ if (cache)
+ cache->insert(name, cursor);
+ return cursor;
+ }
+ QList<QByteArray> aliases = cursor->aliases();
+ for (int y = 0; y < aliases.size(); ++y)
+ if (nameMatch(aliases.at(y), name)) {
+ if (cache)
+ cache->insert(name, cursor);
+ return cursor;
+ }
+ }
+
+ codec = createForName(name);
+ if (codec && cache)
+ cache->insert(name, codec);
+ return codec;
+}
+
+
+/*!
+ Returns the QTextCodec which matches the \link
+ QTextCodec::mibEnum() MIBenum\endlink \a mib.
+*/
+QTextCodec* QTextCodec::codecForMib(int mib)
+{
+#ifndef QT_NO_THREAD
+ QMutexLocker locker(textCodecsMutex());
+#endif
+ setup();
+
+ if (!validCodecs())
+ return 0;
+
+ QByteArray key = "MIB: " + QByteArray::number(mib);
+ QTextCodecCache *cache = qTextCodecCache();
+ QTextCodec *codec;
+ if (cache) {
+ codec = cache->value(key);
+ if (codec)
+ return codec;
+ }
+
+ QList<QTextCodec*>::ConstIterator i;
+ for (int i = 0; i < all->size(); ++i) {
+ QTextCodec *cursor = all->at(i);
+ if (cursor->mibEnum() == mib) {
+ if (cache)
+ cache->insert(key, cursor);
+ return cursor;
+ }
+ }
+
+ codec = createForMib(mib);
+
+ // Qt 3 used 1000 (mib for UCS2) as its identifier for the utf16 codec. Map
+ // this correctly for compatibility.
+ if (!codec && mib == 1000)
+ return codecForMib(1015);
+
+ if (codec && cache)
+ cache->insert(key, codec);
+ return codec;
+}
+
+/*!
+ Returns the list of all available codecs, by name. Call
+ QTextCodec::codecForName() to obtain the QTextCodec for the name.
+
+ The list may contain many mentions of the same codec
+ if the codec has aliases.
+
+ \sa availableMibs(), name(), aliases()
+*/
+QList<QByteArray> QTextCodec::availableCodecs()
+{
+#ifndef QT_NO_THREAD
+ QMutexLocker locker(textCodecsMutex());
+#endif
+ setup();
+
+ QList<QByteArray> codecs;
+
+ if (!validCodecs())
+ return codecs;
+
+ for (int i = 0; i < all->size(); ++i) {
+ codecs += all->at(i)->name();
+ codecs += all->at(i)->aliases();
+ }
+
+#ifndef QT_NO_THREAD
+ locker.unlock();
+#endif
+
+#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_TEXTCODECPLUGIN)
+ QFactoryLoader *l = loader();
+ QStringList keys = l->keys();
+ for (int i = 0; i < keys.size(); ++i) {
+ if (!keys.at(i).startsWith(QLatin1String("MIB: "))) {
+ QByteArray name = keys.at(i).toLatin1();
+ if (!codecs.contains(name))
+ codecs += name;
+ }
+ }
+#endif
+
+ return codecs;
+}
+
+/*!
+ Returns the list of MIBs for all available codecs. Call
+ QTextCodec::codecForMib() to obtain the QTextCodec for the MIB.
+
+ \sa availableCodecs(), mibEnum()
+*/
+QList<int> QTextCodec::availableMibs()
+{
+#ifndef QT_NO_THREAD
+ QMutexLocker locker(textCodecsMutex());
+#endif
+ setup();
+
+ QList<int> codecs;
+
+ if (!validCodecs())
+ return codecs;
+
+ for (int i = 0; i < all->size(); ++i)
+ codecs += all->at(i)->mibEnum();
+
+#ifndef QT_NO_THREAD
+ locker.unlock();
+#endif
+
+#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_TEXTCODECPLUGIN)
+ QFactoryLoader *l = loader();
+ QStringList keys = l->keys();
+ for (int i = 0; i < keys.size(); ++i) {
+ if (keys.at(i).startsWith(QLatin1String("MIB: "))) {
+ int mib = keys.at(i).mid(5).toInt();
+ if (!codecs.contains(mib))
+ codecs += mib;
+ }
+ }
+#endif
+
+ return codecs;
+}
+
+/*!
+ Set the codec to \a c; this will be returned by
+ codecForLocale(). If \a c is a null pointer, the codec is reset to
+ the default.
+
+ This might be needed for some applications that want to use their
+ own mechanism for setting the locale.
+
+ \sa codecForLocale()
+*/
+void QTextCodec::setCodecForLocale(QTextCodec *c)
+{
+#ifndef QT_NO_THREAD
+ QMutexLocker locker(textCodecsMutex());
+#endif
+ localeMapper = c;
+ if (!localeMapper)
+ setupLocaleMapper();
+}
+
+/*!
+ Returns a pointer to the codec most suitable for this locale.
+
+ On Windows, the codec will be based on a system locale. On Unix
+ systems, starting with Qt 4.2, the codec will be using the \e
+ iconv library. Note that in both cases the codec's name will be
+ "System".
+*/
+
+QTextCodec* QTextCodec::codecForLocale()
+{
+ if (!validCodecs())
+ return 0;
+
+ if (localeMapper)
+ return localeMapper;
+
+#ifndef QT_NO_THREAD
+ QMutexLocker locker(textCodecsMutex());
+#endif
+ setup();
+
+ return localeMapper;
+}
+
+
+/*!
+ \fn QByteArray QTextCodec::name() const
+
+ QTextCodec subclasses must reimplement this function. It returns
+ the name of the encoding supported by the subclass.
+
+ If the codec is registered as a character set in the
+ \l{IANA character-sets encoding file} this method should
+ return the preferred mime name for the codec if defined,
+ otherwise its name.
+*/
+
+/*!
+ \fn int QTextCodec::mibEnum() const
+
+ Subclasses of QTextCodec must reimplement this function. It
+ returns the MIBenum (see \l{IANA character-sets encoding file}
+ for more information). It is important that each QTextCodec
+ subclass returns the correct unique value for this function.
+*/
+
+/*!
+ Subclasses can return a number of aliases for the codec in question.
+
+ Standard aliases for codecs can be found in the
+ \l{IANA character-sets encoding file}.
+*/
+QList<QByteArray> QTextCodec::aliases() const
+{
+ return QList<QByteArray>();
+}
+
+/*!
+ \fn QString QTextCodec::convertToUnicode(const char *chars, int len,
+ ConverterState *state) const
+
+ QTextCodec subclasses must reimplement this function.
+
+ Converts the first \a len characters of \a chars from the
+ encoding of the subclass to Unicode, and returns the result in a
+ QString.
+
+ \a state can be 0, in which case the conversion is stateless and
+ default conversion rules should be used. If state is not 0, the
+ codec should save the state after the conversion in \a state, and
+ adjust the remainingChars and invalidChars members of the struct.
+*/
+
+/*!
+ \fn QByteArray QTextCodec::convertFromUnicode(const QChar *input, int number,
+ ConverterState *state) const
+
+ QTextCodec subclasses must reimplement this function.
+
+ Converts the first \a number of characters from the \a input array
+ from Unicode to the encoding of the subclass, and returns the result
+ in a QByteArray.
+
+ \a state can be 0 in which case the conversion is stateless and
+ default conversion rules should be used. If state is not 0, the
+ codec should save the state after the conversion in \a state, and
+ adjust the remainingChars and invalidChars members of the struct.
+*/
+
+/*!
+ Creates a QTextDecoder which stores enough state to decode chunks
+ of \c{char *} data to create chunks of Unicode data.
+
+ The caller is responsible for deleting the returned object.
+*/
+QTextDecoder* QTextCodec::makeDecoder() const
+{
+ return new QTextDecoder(this);
+}
+
+/*!
+ Creates a QTextDecoder with a specified \a flags to decode chunks
+ of \c{char *} data to create chunks of Unicode data.
+
+ The caller is responsible for deleting the returned object.
+
+ \since 4.7
+*/
+QTextDecoder* QTextCodec::makeDecoder(QTextCodec::ConversionFlags flags) const
+{
+ return new QTextDecoder(this, flags);
+}
+
+
+/*!
+ Creates a QTextEncoder which stores enough state to encode chunks
+ of Unicode data as \c{char *} data.
+
+ The caller is responsible for deleting the returned object.
+*/
+QTextEncoder* QTextCodec::makeEncoder() const
+{
+ return new QTextEncoder(this);
+}
+
+/*!
+ Creates a QTextEncoder with a specified \a flags to encode chunks
+ of Unicode data as \c{char *} data.
+
+ The caller is responsible for deleting the returned object.
+
+ \since 4.7
+*/
+QTextEncoder* QTextCodec::makeEncoder(QTextCodec::ConversionFlags flags) const
+{
+ return new QTextEncoder(this, flags);
+}
+
+/*!
+ \fn QByteArray QTextCodec::fromUnicode(const QChar *input, int number,
+ ConverterState *state) const
+
+ Converts the first \a number of characters from the \a input array
+ from Unicode to the encoding of this codec, and returns the result
+ in a QByteArray.
+
+ The \a state of the convertor used is updated.
+*/
+
+/*!
+ Converts \a str from Unicode to the encoding of this codec, and
+ returns the result in a QByteArray.
+*/
+QByteArray QTextCodec::fromUnicode(const QString& str) const
+{
+ return convertFromUnicode(str.constData(), str.length(), 0);
+}
+
+/*!
+ \fn QString QTextCodec::toUnicode(const char *input, int size,
+ ConverterState *state) const
+
+ Converts the first \a size characters from the \a input from the
+ encoding of this codec to Unicode, and returns the result in a
+ QString.
+
+ The \a state of the convertor used is updated.
+*/
+
+/*!
+ Converts \a a from the encoding of this codec to Unicode, and
+ returns the result in a QString.
+*/
+QString QTextCodec::toUnicode(const QByteArray& a) const
+{
+ return convertToUnicode(a.constData(), a.length(), 0);
+}
+
+/*!
+ Returns true if the Unicode character \a ch can be fully encoded
+ with this codec; otherwise returns false.
+*/
+bool QTextCodec::canEncode(QChar ch) const
+{
+ ConverterState state;
+ state.flags = ConvertInvalidToNull;
+ convertFromUnicode(&ch, 1, &state);
+ return (state.invalidChars == 0);
+}
+
+/*!
+ \overload
+
+ \a s contains the string being tested for encode-ability.
+*/
+bool QTextCodec::canEncode(const QString& s) const
+{
+ ConverterState state;
+ state.flags = ConvertInvalidToNull;
+ convertFromUnicode(s.constData(), s.length(), &state);
+ return (state.invalidChars == 0);
+}
+
+#ifdef QT3_SUPPORT
+/*!
+ Returns a string representing the current language and
+ sublanguage, e.g. "pt" for Portuguese, or "pt_br" for Portuguese/Brazil.
+
+ \sa QLocale
+*/
+const char *QTextCodec::locale()
+{
+ static char locale[6];
+ QByteArray l = QLocale::system().name().toLatin1();
+ int len = qMin(l.length(), 5);
+ memcpy(locale, l.constData(), len);
+ locale[len] = '\0';
+
+ return locale;
+}
+
+/*!
+ \overload
+*/
+
+QByteArray QTextCodec::fromUnicode(const QString& uc, int& lenInOut) const
+{
+ QByteArray result = convertFromUnicode(uc.constData(), lenInOut, 0);
+ lenInOut = result.length();
+ return result;
+}
+
+/*!
+ \overload
+
+ \a a contains the source characters; \a len contains the number of
+ characters in \a a to use.
+*/
+QString QTextCodec::toUnicode(const QByteArray& a, int len) const
+{
+ len = qMin(a.size(), len);
+ return convertToUnicode(a.constData(), len, 0);
+}
+#endif
+
+/*!
+ \overload
+
+ \a chars contains the source characters.
+*/
+QString QTextCodec::toUnicode(const char *chars) const
+{
+ int len = qstrlen(chars);
+ return convertToUnicode(chars, len, 0);
+}
+
+
+/*!
+ \class QTextEncoder
+ \brief The QTextEncoder class provides a state-based encoder.
+ \reentrant
+ \ingroup i18n
+
+ A text encoder converts text from Unicode into an encoded text format
+ using a specific codec.
+
+ The encoder converts Unicode into another format, remembering any
+ state that is required between calls.
+
+ \sa QTextCodec::makeEncoder(), QTextDecoder
+*/
+
+/*!
+ \fn QTextEncoder::QTextEncoder(const QTextCodec *codec)
+
+ Constructs a text encoder for the given \a codec.
+*/
+
+/*!
+ Constructs a text encoder for the given \a codec and conversion \a flags.
+
+ \since 4.7
+*/
+QTextEncoder::QTextEncoder(const QTextCodec *codec, QTextCodec::ConversionFlags flags)
+ : c(codec), state()
+{
+ state.flags = flags;
+}
+
+/*!
+ Destroys the encoder.
+*/
+QTextEncoder::~QTextEncoder()
+{
+}
+
+/*! \internal
+ \since 4.5
+ Determines whether the eecoder encountered a failure while decoding the input. If
+ an error was encountered, the produced result is undefined, and gets converted as according
+ to the conversion flags.
+ */
+bool QTextEncoder::hasFailure() const
+{
+ return state.invalidChars != 0;
+}
+
+/*!
+ Converts the Unicode string \a str into an encoded QByteArray.
+*/
+QByteArray QTextEncoder::fromUnicode(const QString& str)
+{
+ QByteArray result = c->fromUnicode(str.constData(), str.length(), &state);
+ return result;
+}
+
+/*!
+ \overload
+
+ Converts \a len characters (not bytes) from \a uc, and returns the
+ result in a QByteArray.
+*/
+QByteArray QTextEncoder::fromUnicode(const QChar *uc, int len)
+{
+ QByteArray result = c->fromUnicode(uc, len, &state);
+ return result;
+}
+
+#ifdef QT3_SUPPORT
+/*!
+ \overload
+
+ Converts \a lenInOut characters (not bytes) from \a uc, and returns the
+ result in a QByteArray. The number of characters read is returned in
+ the \a lenInOut parameter.
+*/
+QByteArray QTextEncoder::fromUnicode(const QString& uc, int& lenInOut)
+{
+ QByteArray result = c->fromUnicode(uc.constData(), lenInOut, &state);
+ lenInOut = result.length();
+ return result;
+}
+#endif
+
+/*!
+ \class QTextDecoder
+ \brief The QTextDecoder class provides a state-based decoder.
+ \reentrant
+ \ingroup i18n
+
+ A text decoder converts text from an encoded text format into Unicode
+ using a specific codec.
+
+ The decoder converts text in this format into Unicode, remembering any
+ state that is required between calls.
+
+ \sa QTextCodec::makeDecoder(), QTextEncoder
+*/
+
+/*!
+ \fn QTextDecoder::QTextDecoder(const QTextCodec *codec)
+
+ Constructs a text decoder for the given \a codec.
+*/
+
+/*!
+ Constructs a text decoder for the given \a codec and conversion \a flags.
+
+ \since 4.7
+*/
+
+QTextDecoder::QTextDecoder(const QTextCodec *codec, QTextCodec::ConversionFlags flags)
+ : c(codec), state()
+{
+ state.flags = flags;
+}
+
+/*!
+ Destroys the decoder.
+*/
+QTextDecoder::~QTextDecoder()
+{
+}
+
+/*!
+ \fn QString QTextDecoder::toUnicode(const char *chars, int len)
+
+ Converts the first \a len bytes in \a chars to Unicode, returning
+ the result.
+
+ If not all characters are used (e.g. if only part of a multi-byte
+ encoding is at the end of the characters), the decoder remembers
+ enough state to continue with the next call to this function.
+*/
+QString QTextDecoder::toUnicode(const char *chars, int len)
+{
+ return c->toUnicode(chars, len, &state);
+}
+
+
+/*! \overload
+
+ The converted string is returned in \a target.
+ */
+void QTextDecoder::toUnicode(QString *target, const char *chars, int len)
+{
+ Q_ASSERT(target);
+ switch (c->mibEnum()) {
+ case 106: // utf8
+ static_cast<const QUtf8Codec*>(c)->convertToUnicode(target, chars, len, &state);
+ break;
+ case 4: { // latin1
+ target->resize(len);
+ ushort *data = (ushort*)target->data();
+ for (int i = len; i >=0; --i)
+ data[i] = (uchar) chars[i];
+ } break;
+ default:
+ *target = c->toUnicode(chars, len, &state);
+ }
+}
+
+
+/*!
+ \overload
+
+ Converts the bytes in the byte array specified by \a ba to Unicode
+ and returns the result.
+*/
+QString QTextDecoder::toUnicode(const QByteArray &ba)
+{
+ return c->toUnicode(ba.constData(), ba.length(), &state);
+}
+
+
+/*!
+ \fn QTextCodec* QTextCodec::codecForTr()
+
+ Returns the codec used by QObject::tr() on its argument. If this
+ function returns 0 (the default), tr() assumes Latin-1.
+
+ \sa setCodecForTr()
+*/
+
+/*!
+ \fn void QTextCodec::setCodecForTr(QTextCodec *c)
+ \nonreentrant
+
+ Sets the codec used by QObject::tr() on its argument to \a c. If
+ \a c is 0 (the default), tr() assumes Latin-1.
+
+ If the literal quoted text in the program is not in the Latin-1
+ encoding, this function can be used to set the appropriate
+ encoding. For example, software developed by Korean programmers
+ might use eucKR for all the text in the program, in which case the
+ main() function might look like this:
+
+ \snippet doc/src/snippets/code/src_corelib_codecs_qtextcodec.cpp 3
+
+ Note that this is not the way to select the encoding that the \e
+ user has chosen. For example, to convert an application containing
+ literal English strings to Korean, all that is needed is for the
+ English strings to be passed through tr() and for translation
+ files to be loaded. For details of internationalization, see
+ \l{Internationalization with Qt}.
+
+ \sa codecForTr(), setCodecForCStrings()
+*/
+
+
+/*!
+ \fn QTextCodec* QTextCodec::codecForCStrings()
+
+ Returns the codec used by QString to convert to and from \c{const
+ char *} and QByteArrays. If this function returns 0 (the default),
+ QString assumes Latin-1.
+
+ \sa setCodecForCStrings()
+*/
+
+/*!
+ \fn void QTextCodec::setCodecForCStrings(QTextCodec *codec)
+ \nonreentrant
+
+ Sets the codec used by QString to convert to and from \c{const
+ char *} and QByteArrays. If the \a codec is 0 (the default),
+ QString assumes Latin-1.
+
+ \warning Some codecs do not preserve the characters in the ASCII
+ range (0x00 to 0x7F). For example, the Japanese Shift-JIS
+ encoding maps the backslash character (0x5A) to the Yen
+ character. To avoid undesirable side-effects, we recommend
+ avoiding such codecs with setCodecsForCString().
+
+ \sa codecForCStrings(), setCodecForTr()
+*/
+
+/*!
+ \since 4.4
+
+ Tries to detect the encoding of the provided snippet of HTML in
+ the given byte array, \a ba, by checking the BOM (Byte Order Mark)
+ and the content-type meta header and returns a QTextCodec instance
+ that is capable of decoding the html to unicode. If the codec
+ cannot be detected from the content provided, \a defaultCodec is
+ returned.
+
+ \sa codecForUtfText()
+*/
+QTextCodec *QTextCodec::codecForHtml(const QByteArray &ba, QTextCodec *defaultCodec)
+{
+ // determine charset
+ int pos;
+ QTextCodec *c = 0;
+
+ c = QTextCodec::codecForUtfText(ba, c);
+ if (!c) {
+ QByteArray header = ba.left(512).toLower();
+ if ((pos = header.indexOf("http-equiv=")) != -1) {
+ if ((pos = header.lastIndexOf("meta ", pos)) != -1) {
+ pos = header.indexOf("charset=", pos) + int(strlen("charset="));
+ if (pos != -1) {
+ int pos2 = header.indexOf('\"', pos+1);
+ QByteArray cs = header.mid(pos, pos2-pos);
+ // qDebug("found charset: %s", cs.data());
+ c = QTextCodec::codecForName(cs);
+ }
+ }
+ }
+ }
+ if (!c)
+ c = defaultCodec;
+
+ return c;
+}
+
+/*!
+ \overload
+
+ Tries to detect the encoding of the provided snippet of HTML in
+ the given byte array, \a ba, by checking the BOM (Byte Order Mark)
+ and the content-type meta header and returns a QTextCodec instance
+ that is capable of decoding the html to unicode. If the codec cannot
+ be detected, this overload returns a Latin-1 QTextCodec.
+*/
+QTextCodec *QTextCodec::codecForHtml(const QByteArray &ba)
+{
+ return codecForHtml(ba, QTextCodec::codecForMib(/*Latin 1*/ 4));
+}
+
+/*!
+ \since 4.6
+
+ Tries to detect the encoding of the provided snippet \a ba by
+ using the BOM (Byte Order Mark) and returns a QTextCodec instance
+ that is capable of decoding the text to unicode. If the codec
+ cannot be detected from the content provided, \a defaultCodec is
+ returned.
+
+ \sa codecForHtml()
+*/
+QTextCodec *QTextCodec::codecForUtfText(const QByteArray &ba, QTextCodec *defaultCodec)
+{
+ const int arraySize = ba.size();
+
+ if (arraySize > 3) {
+ if ((uchar)ba[0] == 0x00
+ && (uchar)ba[1] == 0x00
+ && (uchar)ba[2] == 0xFE
+ && (uchar)ba[3] == 0xFF)
+ return QTextCodec::codecForMib(1018); // utf-32 be
+ else if ((uchar)ba[0] == 0xFF
+ && (uchar)ba[1] == 0xFE
+ && (uchar)ba[2] == 0x00
+ && (uchar)ba[3] == 0x00)
+ return QTextCodec::codecForMib(1019); // utf-32 le
+ }
+
+ if (arraySize < 2)
+ return defaultCodec;
+ if ((uchar)ba[0] == 0xfe && (uchar)ba[1] == 0xff)
+ return QTextCodec::codecForMib(1013); // utf16 be
+ else if ((uchar)ba[0] == 0xff && (uchar)ba[1] == 0xfe)
+ return QTextCodec::codecForMib(1014); // utf16 le
+
+ if (arraySize < 3)
+ return defaultCodec;
+ if ((uchar)ba[0] == 0xef
+ && (uchar)ba[1] == 0xbb
+ && (uchar)ba[2] == 0xbf)
+ return QTextCodec::codecForMib(106); // utf-8
+
+ return defaultCodec;
+}
+
+/*!
+ \overload
+
+ Tries to detect the encoding of the provided snippet \a ba by
+ using the BOM (Byte Order Mark) and returns a QTextCodec instance
+ that is capable of decoding the text to unicode. If the codec
+ cannot be detected, this overload returns a Latin-1 QTextCodec.
+
+ \sa codecForHtml()
+*/
+QTextCodec *QTextCodec::codecForUtfText(const QByteArray &ba)
+{
+ return codecForUtfText(ba, QTextCodec::codecForMib(/*Latin 1*/ 4));
+}
+
+
+/*! \internal
+ \since 4.3
+ Determines whether the decoder encountered a failure while decoding the input. If
+ an error was encountered, the produced result is undefined, and gets converted as according
+ to the conversion flags.
+ */
+bool QTextDecoder::hasFailure() const
+{
+ return state.invalidChars != 0;
+}
+
+/*!
+ \fn QTextCodec *QTextCodec::codecForContent(const char *str, int size)
+
+ This functionality is no longer provided by Qt. This
+ compatibility function always returns a null pointer.
+*/
+
+/*!
+ \fn QTextCodec *QTextCodec::codecForName(const char *hint, int accuracy)
+
+ Use the codecForName(const QByteArray &) overload instead.
+*/
+
+/*!
+ \fn QTextCodec *QTextCodec::codecForIndex(int i)
+
+ Use availableCodecs() or availableMibs() instead and iterate
+ through the resulting list.
+*/
+
+
+/*!
+ \fn QByteArray QTextCodec::mimeName() const
+
+ Use name() instead.
+*/
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_TEXTCODEC
diff --git a/src/corelib/codecs/qtextcodec.h b/src/corelib/codecs/qtextcodec.h
new file mode 100644
index 0000000000..759a59b66a
--- /dev/null
+++ b/src/corelib/codecs/qtextcodec.h
@@ -0,0 +1,198 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QTEXTCODEC_H
+#define QTEXTCODEC_H
+
+#include <QtCore/qstring.h>
+#include <QtCore/qlist.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+#ifndef QT_NO_TEXTCODEC
+
+class QTextCodec;
+class QIODevice;
+
+class QTextDecoder;
+class QTextEncoder;
+
+class Q_CORE_EXPORT QTextCodec
+{
+ Q_DISABLE_COPY(QTextCodec)
+public:
+ static QTextCodec* codecForName(const QByteArray &name);
+ static QTextCodec* codecForName(const char *name) { return codecForName(QByteArray(name)); }
+ static QTextCodec* codecForMib(int mib);
+
+ static QList<QByteArray> availableCodecs();
+ static QList<int> availableMibs();
+
+ static QTextCodec* codecForLocale();
+ static void setCodecForLocale(QTextCodec *c);
+
+ static QTextCodec* codecForTr();
+ static void setCodecForTr(QTextCodec *c);
+
+ static QTextCodec* codecForCStrings();
+ static void setCodecForCStrings(QTextCodec *c);
+
+ static QTextCodec *codecForHtml(const QByteArray &ba);
+ static QTextCodec *codecForHtml(const QByteArray &ba, QTextCodec *defaultCodec);
+
+ static QTextCodec *codecForUtfText(const QByteArray &ba);
+ static QTextCodec *codecForUtfText(const QByteArray &ba, QTextCodec *defaultCodec);
+
+ bool canEncode(QChar) const;
+ bool canEncode(const QString&) const;
+
+ QString toUnicode(const QByteArray&) const;
+ QString toUnicode(const char* chars) const;
+ QByteArray fromUnicode(const QString& uc) const;
+ enum ConversionFlag {
+ DefaultConversion,
+ ConvertInvalidToNull = 0x80000000,
+ IgnoreHeader = 0x1,
+ FreeFunction = 0x2
+ };
+ Q_DECLARE_FLAGS(ConversionFlags, ConversionFlag)
+
+ struct Q_CORE_EXPORT ConverterState {
+ ConverterState(ConversionFlags f = DefaultConversion)
+ : flags(f), remainingChars(0), invalidChars(0), d(0) { state_data[0] = state_data[1] = state_data[2] = 0; }
+ ~ConverterState();
+ ConversionFlags flags;
+ int remainingChars;
+ int invalidChars;
+ uint state_data[3];
+ void *d;
+ private:
+ Q_DISABLE_COPY(ConverterState)
+ };
+
+ QString toUnicode(const char *in, int length, ConverterState *state = 0) const
+ { return convertToUnicode(in, length, state); }
+ QByteArray fromUnicode(const QChar *in, int length, ConverterState *state = 0) const
+ { return convertFromUnicode(in, length, state); }
+
+ // ### Qt 5: merge these functions.
+ QTextDecoder* makeDecoder() const;
+ QTextDecoder* makeDecoder(ConversionFlags flags) const;
+ QTextEncoder* makeEncoder() const;
+ QTextEncoder* makeEncoder(ConversionFlags flags) const;
+
+ virtual QByteArray name() const = 0;
+ virtual QList<QByteArray> aliases() const;
+ virtual int mibEnum() const = 0;
+
+protected:
+ virtual QString convertToUnicode(const char *in, int length, ConverterState *state) const = 0;
+ virtual QByteArray convertFromUnicode(const QChar *in, int length, ConverterState *state) const = 0;
+
+ QTextCodec();
+ virtual ~QTextCodec();
+
+public:
+#ifdef QT3_SUPPORT
+ static QT3_SUPPORT QTextCodec* codecForContent(const char*, int) { return 0; }
+ static QT3_SUPPORT const char* locale();
+ static QT3_SUPPORT QTextCodec* codecForName(const char* hint, int) { return codecForName(QByteArray(hint)); }
+ QT3_SUPPORT QByteArray fromUnicode(const QString& uc, int& lenInOut) const;
+ QT3_SUPPORT QString toUnicode(const QByteArray&, int len) const;
+ QT3_SUPPORT QByteArray mimeName() const { return name(); }
+ static QT3_SUPPORT QTextCodec *codecForIndex(int i) { return codecForName(availableCodecs().value(i)); }
+#endif
+
+private:
+ friend class QTextCodecCleanup;
+ static QTextCodec *cftr;
+ static bool validCodecs();
+};
+Q_DECLARE_OPERATORS_FOR_FLAGS(QTextCodec::ConversionFlags)
+
+ inline QTextCodec* QTextCodec::codecForTr() { return validCodecs() ? cftr : 0; }
+inline void QTextCodec::setCodecForTr(QTextCodec *c) { cftr = c; }
+inline QTextCodec* QTextCodec::codecForCStrings() { return validCodecs() ? QString::codecForCStrings : 0; }
+inline void QTextCodec::setCodecForCStrings(QTextCodec *c) { QString::codecForCStrings = c; }
+
+class Q_CORE_EXPORT QTextEncoder {
+ Q_DISABLE_COPY(QTextEncoder)
+public:
+ explicit QTextEncoder(const QTextCodec *codec) : c(codec), state() {}
+ QTextEncoder(const QTextCodec *codec, QTextCodec::ConversionFlags flags);
+ ~QTextEncoder();
+ QByteArray fromUnicode(const QString& str);
+ QByteArray fromUnicode(const QChar *uc, int len);
+#ifdef QT3_SUPPORT
+ QT3_SUPPORT QByteArray fromUnicode(const QString& uc, int& lenInOut);
+#endif
+ bool hasFailure() const;
+private:
+ const QTextCodec *c;
+ QTextCodec::ConverterState state;
+};
+
+class Q_CORE_EXPORT QTextDecoder {
+ Q_DISABLE_COPY(QTextDecoder)
+public:
+ explicit QTextDecoder(const QTextCodec *codec) : c(codec), state() {}
+ QTextDecoder(const QTextCodec *codec, QTextCodec::ConversionFlags flags);
+ ~QTextDecoder();
+ QString toUnicode(const char* chars, int len);
+ QString toUnicode(const QByteArray &ba);
+ void toUnicode(QString *target, const char *chars, int len);
+ bool hasFailure() const;
+private:
+ const QTextCodec *c;
+ QTextCodec::ConverterState state;
+};
+
+#endif // QT_NO_TEXTCODEC
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QTEXTCODEC_H
diff --git a/src/corelib/codecs/qtextcodec_p.h b/src/corelib/codecs/qtextcodec_p.h
new file mode 100644
index 0000000000..fbf5c1255a
--- /dev/null
+++ b/src/corelib/codecs/qtextcodec_p.h
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QTEXTCODEC_P_H
+#define QTEXTCODEC_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of the QTextCodec class. This header file may change from
+// version to version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qtextcodec.h"
+#include <string.h>
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_TEXTCODEC
+
+typedef void (*QTextCodecStateFreeFunction)(QTextCodec::ConverterState*);
+
+struct QTextCodecUnalignedPointer
+{
+ static inline QTextCodecStateFreeFunction decode(const uint *src)
+ {
+ quintptr data;
+ memcpy(&data, src, sizeof(data));
+ return reinterpret_cast<QTextCodecStateFreeFunction>(data);
+ }
+ static inline void encode(uint *dst, QTextCodecStateFreeFunction fn)
+ {
+ quintptr data = reinterpret_cast<quintptr>(fn);
+ memcpy(dst, &data, sizeof(data));
+ }
+};
+
+#else
+
+class QTextCodec
+{
+public:
+ enum ConversionFlag {
+ DefaultConversion,
+ ConvertInvalidToNull = 0x80000000,
+ IgnoreHeader = 0x1,
+ FreeFunction = 0x2
+ };
+ Q_DECLARE_FLAGS(ConversionFlags, ConversionFlag)
+
+ struct ConverterState {
+ ConverterState(ConversionFlags f = DefaultConversion)
+ : flags(f), remainingChars(0), invalidChars(0), d(0) { state_data[0] = state_data[1] = state_data[2] = 0; }
+ ~ConverterState() { }
+ ConversionFlags flags;
+ int remainingChars;
+ int invalidChars;
+ uint state_data[3];
+ void *d;
+ private:
+ Q_DISABLE_COPY(ConverterState)
+ };
+};
+
+#endif //QT_NO_TEXTCODEC
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/corelib/codecs/qtextcodec_symbian.cpp b/src/corelib/codecs/qtextcodec_symbian.cpp
new file mode 100644
index 0000000000..9ad8ccae1b
--- /dev/null
+++ b/src/corelib/codecs/qtextcodec_symbian.cpp
@@ -0,0 +1,689 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qtextcodec_p.h"
+
+#include <private/qcore_symbian_p.h>
+#include <QThreadStorage>
+#include <QScopedPointer>
+
+#include <charconv.h>
+
+struct QSymbianCodecInitData {
+ uint charsetId;
+ int mib;
+ const char *aliases;
+};
+
+/* This table contains the known Symbian codecs aliases.
+ It is required because symbian does not provide aliases for codecs.
+ It is also faster to have a name here than asking the system.
+ It is ordered by charsetId to allow binary search lookup
+ */
+static const QSymbianCodecInitData codecsData[] = {
+ { /*268439485*/ KCharacterSetIdentifierShiftJis, 17, "Shift_JIS\0MS_Kanji\0csShiftJIS\0SJIS\0" },
+ { /*268439486*/ KCharacterSetIdentifierGb2312, 57, "GB2312\0csGB2312\0CN-GB\0EUC-CN\0" }, // Note: ConvertCharacterSetIdentifierToMibEnumL returns Mib 0 instaead of 57
+ { /*268439487*/ KCharacterSetIdentifierBig5, 2026, "Big5\0csBig5\0Big5-ETen\0CP950\0BIG-FIVE\0CN-BIG5\0" },
+ { /*268440246*/ KCharacterSetIdentifierCodePage1252, 2252, "windows-1252\0Code Page 1252\0CP1252\0MS-ANSI\0" },
+// { /*268450576*/ KCharacterSetIdentifierIso88591, 4, "ISO-8859-1\0ISO_8859-1:1987\0iso-ir-100\0ISO_8859-1\0latin1\0l1\0IBM819\0CP819\0csISOLatin1\0ISO-IR-100\0ISO8859-1\0L1\0LATIN1\0CSISOLATIN1\0" },
+ { /*268451531*/ KCharacterSetIdentifierGbk, 113, "GBK\0MS936\0windows-936\0CP936\0" },
+ { /*268451866*/ KCharacterSetIdentifierGb12345, 0, "GB12345\0" },
+ { /*268455110*/ KCharacterSetIdentifierAscii, 3, "US-ASCII\0ANSI_X3.4-1968\0iso-ir-6\0ANSI_X3.4-1986\0ISO_646.irv:1991\0ASCII\0ISO646-US\0us\0IBM367\0cp367\0csASCII\0ISO-IR-6\0ISO_646.IRV:1991\0"},
+ { /*268456062*/ KCharacterSetIdentifierIso88592, 5, "ISO-8859-2\0ISO_8859-2:1987\0iso-ir-101\0latin2\0l2\0csISOLatin2\0" },
+ { /*268456063*/ KCharacterSetIdentifierIso88594, 7, "ISO-8859-4\0ISO_8859-4:1988\0iso-ir-110\0latin4\0l4\0csISOLatin4\0" },
+ { /*268456064*/ KCharacterSetIdentifierIso88595, 8, "ISO-8859-5\0ISO_8859-5:1988\0iso-ir-144\0cyrillic\0csISOLatinCyrillic\0" },
+ { /*268456065*/ KCharacterSetIdentifierIso88597, 10, "ISO-8859-7\0ISO_8859-7:1987\0iso-ir-126\0ELOT_928\0ECMA-118\0greek\0greek8\0csISOLatinGreek\0" },
+ { /*268456066*/ KCharacterSetIdentifierIso88599, 12, "ISO-8859-9\0ISO_8859-9:1989\0iso-ir-148\0latin5\0l5\0csISOLatin5\0" },
+ { /*268456875*/ KCharacterSetIdentifierSms7Bit, 0, "SMS 7-bit\0" },
+ { /*268458028*/ KCharacterSetIdentifierUtf7, 103, "UTF-7\0UNICODE-1-1-UTF-7\0CSUNICODE11UTF7\0" },
+// { /*268458029*/ KCharacterSetIdentifierUtf8, 106, "UTF-8\0" },
+ { /*268458030*/ KCharacterSetIdentifierImapUtf7, 0, "IMAP UTF-7\0" },
+ { /*268458031*/ KCharacterSetIdentifierJavaConformantUtf8, 0, "JAVA UTF-8\0" },
+ { /*268458454*/ 268458454, 2250, "Windows-1250\0CP1250\0MS-EE\0" },
+ { /*268458455*/ 268458455, 2251, "Windows-1251\0CP1251\0MS-CYRL\0" },
+ { /*268458456*/ 268458456, 2253, "Windows-1253\0CP1253\0MS-GREEK\0" },
+ { /*268458457*/ 268458457, 2254, "Windows-1254\0CP1254\0MS-TURK\0" },
+ { /*268458458*/ 268458458, 2257, "Windows-1257\0CP1257\0WINBALTRIM\0" },
+ { /*268460133*/ KCharacterSetIdentifierHz, 2085, "HZ-GB-2312\0HZ\0" },
+ { /*268460134*/ KCharacterSetIdentifierJis, 16, "JIS_Encoding\0JIS\0" },
+ { /*268460135*/ KCharacterSetIdentifierEucJpPacked, 18, "EUC-JP\0Extended_UNIX_Code_Packed_Format_for_Japanese\0csEUCPkdFmtJapanese\0EUCJP_PACKED\0" },
+ { /*268461728*/ KCharacterSetIdentifierIso2022Jp, 39, "ISO-2022-JP\0csISO2022JP\0JIS7\0" },
+ { /*268461731*/ KCharacterSetIdentifierIso2022Jp1, 0, "ISO2022JP1\0" },
+ { /*268470824*/ KCharacterSetIdentifierIso88593, 6, "ISO-8859-3\0ISO_8859-3:1988\0iso-ir-109\0latin3\0l3\0csISOLatin3\0" },
+ { /*268470825*/ KCharacterSetIdentifierIso88596, 9, "ISO-8859-6\0ISO_8859-6:1987\0iso-ir-127\0ECMA-114\0ASMO-708\0arabic\0ISO88596\0csISOLatinArabic\0ARABIC\0" },
+ { /*268470826*/ KCharacterSetIdentifierIso88598, 11, "ISO-8859-8\0ISO_8859-8:1988\0iso-ir-138\0hebrew\0csISOLatinHebrew\0" },
+ { /*268470827*/ KCharacterSetIdentifierIso885910, 13, "ISO-8859-10\0iso-ir-157\0l6\0ISO_8859-10:1992\0csISOLatin6\0latin6\0" },
+ { /*268470828*/ KCharacterSetIdentifierIso885913, 109, "ISO-8859-13\0ISO885913\0ISO-IR-179\0ISO8859-13\0L7\0LATIN7\0CSISOLATIN7\0" },
+ { /*268470829*/ KCharacterSetIdentifierIso885914, 110, "ISO-8859-14\0iso-ir-199\0ISO_8859-14:1998\0latin8\0iso-celtic\0l8\0" },
+ { /*268470830*/ KCharacterSetIdentifierIso885915, 111, "ISO-8859-15\0latin-9\0ISO-IR-203\0" },
+// { /*270483374*/ KCharacterSetIdentifierUnicodeLittle, 1014, "UTF-16LE\0Little-Endian UNICODE\0" },
+// { /*270483538*/ KCharacterSetIdentifierUnicodeBig, 1013, "UTF-16BE\0Big-Endian UNICODE\0" },
+ { /*270501191*/ 270501191, 2255, "Windows-1255\0CP1255\0MS-HEBR\0" },
+ { /*270501192*/ 270501192, 2256, "Windows-1256\0CP1256\0MS-ARAB\0" },
+ { /*270501193*/ 270501193, 2259, "TIS-620\0ISO-IR-166\0TIS620-0\0TIS620.2529-1\0TIS620.2533-0\0TIS620.2533-1\0" },
+ { /*270501194*/ 270501194, 0, "windows-874\0CP874\0IBM874\0" },
+ { /*270501325*/ 270501325, 0, "SmsStrict\0" },
+ { /*270501521*/ 270501521, 0, "ShiftJisDirectmap\0" },
+ { /*270501542*/ 270501542, 0, "EucJpDirectmap\0" },
+ /* 270501691 (duplicate) Windows-1252 | windows-1252 |Windows-1252 |Code Page 1252 |CP1252 |MS-ANSI |WINDOWS-1252 |2252 */
+ { /*270501729*/ 270501729, 2088, "KOI8-U\0" },
+ { /*270501752*/ 270501752, 2084, "KOI8-R\0csKOI8R\0" },
+ { /*270529682*/ 270529682, 1000, "ISO-10646-UCS-2\0UCS-2\0CSUNICODE\0" },
+ { /*270562232*/ 270562232, 2258, "Windows-1258\0CP1258\0WINDOWS-1258\0" },
+ { /*270586888*/ 270586888, 0, "J5\0" },
+ { /*271011982*/ 271011982, 0, "ISCII\0" },
+ { /*271066541*/ 271066541, 2009, "CP850\0IBM850\0""850\0csPC850Multilingual\0" }, // Note: ConvertCharacterSetIdentifierToMibEnumL returns Mib 0 instead of 2009
+ { /*271082493*/ 271082493, 0, "EXTENDED_SMS_7BIT\0" },
+ { /*271082494*/ 271082494, 0, "gsm7_turkish_single\0" },
+ { /*271082495*/ 271082495, 0, "turkish_locking_gsm7ext\0" },
+ { /*271082496*/ 271082496, 0, "turkish_locking_single\0" },
+ { /*271082503*/ 271082503, 0, "portuguese_gsm7_single\0" },
+ { /*271082504*/ 271082504, 0, "portuguese_locking_gsm7ext\0" },
+ { /*271082505*/ 271082505, 0, "portuguese_locking_single\0" },
+ { /*271082506*/ 271082506, 0, "spanish_gsm7_single\0" },
+ { /*271085624*/ 271085624, 114, "GB18030\0" },
+ { /*536929574*/ 536929574, 38, "EUC-KR\0" },
+ { /*536936703*/ 536936703, 0, "CP949\0" },
+ { /*536936705*/ 536936705, 37, "ISO-2022-KR\0csISO2022KR\0" },
+ { /*536941517*/ 536941517, 36, "KS_C_5601-1987\0iso-ir-149\0KS_C_5601-1989\0KSC_5601\0Korean\0csKSC56011987\0" }
+ };
+
+
+class QSymbianTextCodec : public QTextCodec
+{
+public:
+ QString convertToUnicode(const char*, int, ConverterState*) const;
+ QByteArray convertFromUnicode(const QChar*, int, ConverterState*) const;
+ QList<QByteArray> aliases() const;
+ QByteArray name() const;
+ int mibEnum() const;
+
+ explicit QSymbianTextCodec(uint charsetId, int staticIndex = -1) : m_charsetId(charsetId), m_staticIndex(staticIndex) { }
+
+ static QSymbianTextCodec *init();
+ static QSymbianTextCodec *localeMapper;
+private:
+ static CCnvCharacterSetConverter *converter();
+ static uint getLanguageDependentCharacterSet();
+ uint m_charsetId;
+ int m_staticIndex;
+};
+
+QSymbianTextCodec *QSymbianTextCodec::localeMapper = 0;
+
+class QSymbianTextCodecWithName : public QSymbianTextCodec
+{
+public:
+ QSymbianTextCodecWithName(uint charsetId, const QByteArray &name)
+ : QSymbianTextCodec(charsetId) , m_name(name) { }
+ QByteArray name() const { return m_name; }
+ QList<QByteArray> aliases() const { return QList<QByteArray>(); }
+private:
+ QByteArray m_name;
+};
+
+Q_GLOBAL_STATIC(QThreadStorage<CCnvCharacterSetConverter *>,gs_converterStore);
+
+CCnvCharacterSetConverter *QSymbianTextCodec::converter()
+{
+ CCnvCharacterSetConverter *&conv = gs_converterStore()->localData();
+ if (!conv)
+ QT_TRAP_THROWING(conv = CCnvCharacterSetConverter::NewL())
+ return conv;
+}
+
+
+QByteArray QSymbianTextCodec::name() const
+{
+ if (m_staticIndex >= 0)
+ return QByteArray(codecsData[m_staticIndex].aliases);
+ QScopedPointer<HBufC8> buf;
+ QT_TRAP_THROWING(buf.reset(converter()->ConvertCharacterSetIdentifierToStandardNameL(m_charsetId, qt_s60GetRFs())))
+ if (buf)
+ return QByteArray(reinterpret_cast<const char *>(buf->Ptr()), buf->Length());
+ return QByteArray();
+}
+
+int QSymbianTextCodec::mibEnum() const
+{
+ if (m_staticIndex >= 0)
+ return codecsData[m_staticIndex].mib;
+ int mib;
+ QT_TRAP_THROWING(mib = converter()->ConvertCharacterSetIdentifierToMibEnumL(m_charsetId, qt_s60GetRFs()))
+ return mib;
+}
+
+QList<QByteArray> QSymbianTextCodec::aliases() const
+{
+ QList<QByteArray> result;
+ if (m_staticIndex >= 0) {
+ const char *aliases = codecsData[m_staticIndex].aliases;
+ aliases += strlen(aliases) + 1;
+ while (*aliases) {
+ int len = strlen(aliases);
+ result += QByteArray(aliases, len);
+ aliases += len + 1;
+ }
+ }
+ return result;
+}
+
+
+QString QSymbianTextCodec::convertToUnicode(const char *str, int len, ConverterState *state) const
+{
+ uint charsetId = m_charsetId;
+
+ // no support for utf7 with state
+ if (state && (charsetId == KCharacterSetIdentifierUtf7 ||
+ charsetId == KCharacterSetIdentifierImapUtf7)) {
+ return QString();
+ }
+ CCnvCharacterSetConverter *converter = QSymbianTextCodec::converter();
+ if (!str) {
+ return QString();
+ }
+
+ //Search the character set array containing all of the character sets for which conversion is available
+ CCnvCharacterSetConverter::TAvailability av;
+ QT_TRAP_THROWING(av = converter->PrepareToConvertToOrFromL(charsetId, qt_s60GetRFs()))
+ if (av == CCnvCharacterSetConverter::ENotAvailable) {
+ return QString();
+ }
+
+ char *str2;
+ int len2;
+ QByteArray helperBA;
+ if (state && (state->remainingChars > 0)) {
+ // we should prepare the input string ourselves
+ // the real size
+ len2 = len + state->remainingChars;
+ helperBA.resize(len2);
+ str2 = helperBA.data();
+ if (state->remainingChars > 3) { // doesn't happen usually
+ memcpy(str2, state->d, state->remainingChars);
+ qFree(state->d);
+ state->d = 0;
+ } else {
+ char charTbl[3];
+ charTbl[0] = state->state_data[0];
+ charTbl[1] = state->state_data[1];
+ charTbl[2] = state->state_data[2];
+ memcpy(str2, charTbl, state->remainingChars);
+ }
+ memcpy(str2+state->remainingChars, str, len);
+ }
+ else {
+ len2 = len;
+ str2 = const_cast<char*>(str);
+ }
+
+ QString UnicodeText(len2, Qt::Uninitialized);
+ TPtrC8 remainderOfForeignText;
+ remainderOfForeignText.Set(reinterpret_cast<const unsigned char *>(str2), len2);
+
+ int numberOfUnconvertibleCharacters = 0;
+ int indexOfFirstUnconvertibleCharacter;
+
+ // Use null character as replacement, if it is asked
+ bool convertToNull = (state && (state->flags & QTextCodec::ConvertInvalidToNull));
+ if (convertToNull) {
+ _LIT8(KReplacement, "\x00");
+ QT_TRAP_THROWING(converter->SetReplacementForUnconvertibleUnicodeCharactersL(KReplacement))
+ }
+ // use state->invalidChars for keeping symbian state
+ int sState = CCnvCharacterSetConverter::KStateDefault;
+ if (state && (state->invalidChars != CCnvCharacterSetConverter::KStateDefault)) {
+ sState = state->invalidChars;
+ }
+ //Convert text encoded in a non-Unicode character set into the Unicode character set (UCS-2).
+ int remainingChars = -1;
+ int initial_size=0;
+ while (1) {
+ TPtr16 UnicodePtr(reinterpret_cast<unsigned short *>(UnicodeText.data()+initial_size), UnicodeText.size());
+ QT_TRAP_THROWING(remainingChars = converter->ConvertToUnicode(UnicodePtr,
+ remainderOfForeignText,
+ sState,
+ numberOfUnconvertibleCharacters,
+ indexOfFirstUnconvertibleCharacter))
+
+ initial_size += UnicodePtr.Length();
+ // replace 0xFFFD with 0x0000 and only if state set to convert to it
+ if (numberOfUnconvertibleCharacters>0 && convertToNull) {
+ int len2 = UnicodePtr.Length();
+ for (int i = indexOfFirstUnconvertibleCharacter; i < len2; i++) {
+ UnicodePtr[i] = 0x0000;
+ }
+ }
+ // success
+ if (remainingChars==KErrNone) {
+ break;
+ }
+ // if ConvertToUnicode could not consume the foreign text at all
+ // UTF-8: EErrorIllFormedInput = KErrCorrupt
+ // UCS-2: KErrNotFound
+ if (remainingChars == CCnvCharacterSetConverter::EErrorIllFormedInput ||
+ remainingChars == KErrNotFound) {
+ remainingChars = remainderOfForeignText.Size();
+ break;
+ }
+ else {
+ if (remainingChars < 0) {
+ return QString();
+ }
+ }
+ //
+ UnicodeText.resize(UnicodeText.size() + remainingChars*2);
+ remainderOfForeignText.Set(reinterpret_cast<const unsigned char *>(str2+len2-remainingChars), remainingChars);
+ }
+ // save symbian state
+ if (state) {
+ state->invalidChars = sState;
+ }
+
+ if (remainingChars > 0) {
+ if (!state) {
+ // No way to signal, if there is still remaining chars, for ex. UTF-8 still can have
+ // some characters hanging around.
+ return QString();
+ }
+ const unsigned char *charPtr = remainderOfForeignText.Right(remainingChars).Ptr();
+ if (remainingChars > 3) { // doesn't happen usually
+ state->d = (void*)qMalloc(remainingChars);
+ if (!state->d)
+ return QString();
+ // copy characters there
+ memcpy(state->d, charPtr, remainingChars);
+ }
+ else {
+ // fallthru is correct
+ switch (remainingChars) {
+ case 3:
+ state->state_data[2] = charPtr[2];
+ case 2:
+ state->state_data[1] = charPtr[1];
+ case 1:
+ state->state_data[0] = charPtr[0];
+ }
+ }
+ state->remainingChars = remainingChars;
+ }
+ else {
+ if (state) {
+ // If we continued from an earlier iteration
+ state->remainingChars = 0;
+ }
+ }
+ // check if any ORIGINAL headers should be left
+ if (initial_size > 0) {
+ if (!state || (state && !(state->flags & QTextCodec::IgnoreHeader))) {
+ // always skip headers on following state loops
+ if (state) {
+ state->flags |= QTextCodec::IgnoreHeader;
+ }
+ const TUint16 *ptr = reinterpret_cast<const TUint16 *>(UnicodeText.data());
+ if (ptr[0] == QChar::ByteOrderMark || ptr[0] == QChar::ByteOrderSwapped) {
+ return UnicodeText.mid(1, initial_size - 1);
+ }
+ }
+ }
+ if (initial_size >= 0) {
+ UnicodeText.resize(initial_size);
+ return UnicodeText;
+ }
+ else {
+ return QString();
+ }
+}
+
+
+QByteArray QSymbianTextCodec::convertFromUnicode(const QChar *str, int len, ConverterState *state) const
+{
+ uint charsetId = m_charsetId;
+ CCnvCharacterSetConverter *converter = QSymbianTextCodec::converter();
+ if (!str)
+ return QByteArray();
+
+ if (len == 0)
+ return QByteArray();
+
+ // no support for utf7 with state
+ if (state && (charsetId == KCharacterSetIdentifierUtf7 ||
+ charsetId == KCharacterSetIdentifierImapUtf7))
+ return QByteArray();
+
+ //Get reference file session from backend
+ RFs &fileSession = qt_s60GetRFs();
+
+ //Search the character set array containing all of the character sets for which conversion is available
+ CCnvCharacterSetConverter::TAvailability av = CCnvCharacterSetConverter::ENotAvailable;
+ QT_TRAP_THROWING(av = converter->PrepareToConvertToOrFromL(charsetId, fileSession))
+ if (av == CCnvCharacterSetConverter::ENotAvailable)
+ return QByteArray();
+
+ // Use null character as replacement, if it is asked
+ if (state && (state->flags & QTextCodec::ConvertInvalidToNull)) {
+ _LIT8(KReplacement, "\x00");
+ QT_TRAP_THROWING(converter->SetReplacementForUnconvertibleUnicodeCharactersL(KReplacement))
+ }
+ else {
+ _LIT8(KReplacement, "?");
+ QT_TRAP_THROWING(converter->SetReplacementForUnconvertibleUnicodeCharactersL(KReplacement))
+ }
+ QByteArray outputBuffer;
+
+ // add header if no state (one run), or if no ignoreheader (from first state)
+ int bomofs = 0;
+ if (!state || (state && !(state->flags & QTextCodec::IgnoreHeader))) {
+
+ QChar bom(QChar::ByteOrderMark);
+
+ if (state)
+ state->flags |= QTextCodec::IgnoreHeader; // bom handling only on first state
+
+ switch (charsetId) {
+ case KCharacterSetIdentifierUcs2:
+ outputBuffer.append(bom.row());
+ outputBuffer.append(bom.cell());
+ bomofs = 2;
+ break;
+
+ case KCharacterSetIdentifierUtf8: // we don't add bom for UTF-8
+ case KCharacterSetIdentifierJavaConformantUtf8:
+ /*outputBuffer.append("\xef\xbb\xbf");
+ bomofs = 3;
+ */
+ break;
+
+ case KCharacterSetIdentifierUnicodeLittle:
+ outputBuffer.append(bom.cell());
+ outputBuffer.append(bom.row());
+ bomofs = 2;
+ break;
+
+ case KCharacterSetIdentifierUnicodeBig:
+ outputBuffer.append(bom.row());
+ outputBuffer.append(bom.cell());
+ bomofs = 2;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ // len is 16bit chars, reserve 3 8bit chars for each input char
+ // jsz - it could be differentiated, to allocate less
+ outputBuffer.resize(len * 3 + bomofs);
+
+ // loop for too short output buffer
+ int unconverted;
+ int numberOfUnconvertibleCharacters = len;
+ int indexOfFirstUnconvertibleCharacter;
+ int convertedSize;
+ int lastUnconverted = 0;
+ int initial_size=0;
+ int remainderToConvert = len;
+ while (1) {
+ TPtr8 outputPtr(reinterpret_cast<unsigned char *>(outputBuffer.data() + bomofs + initial_size), outputBuffer.size() - bomofs);
+
+ TPtrC16 UnicodeText(reinterpret_cast<const unsigned short *>(str+len-remainderToConvert), remainderToConvert);
+
+ //Convert text encoded in the Unicode character set (UCS-2) into other character sets
+ unconverted = -1;
+ QT_TRAP_THROWING( unconverted = converter->ConvertFromUnicode(outputPtr,
+ UnicodeText,
+ numberOfUnconvertibleCharacters,
+ indexOfFirstUnconvertibleCharacter))
+ initial_size += outputPtr.Length();
+ if (unconverted < 0) {
+ return QByteArray();
+ }
+
+
+ if (unconverted == 0 ) {
+ convertedSize = initial_size;
+ break;
+ }
+
+ // check what means unconverted > 0
+ if (indexOfFirstUnconvertibleCharacter<0) {
+ // 8859-6 and 8859-8 break with certain input (string of \xc0 - \xd9 converted to unicode and back)
+ if (unconverted == lastUnconverted) {
+ return QByteArray();
+ }
+ lastUnconverted = unconverted;
+ }
+ else {
+ // were some character not possible to convert
+
+ }
+ remainderToConvert = unconverted; // len - indexOfFirstUnconvertibleCharacter;
+ // resize output buffer, use =op for the null check
+ outputBuffer.resize(outputBuffer.size() + remainderToConvert * 3 + bomofs);
+ };
+
+ // shorten output
+ outputBuffer.resize(convertedSize + bomofs);
+
+ if (state) {
+ state->invalidChars = numberOfUnconvertibleCharacters;
+
+ // check if any Symbian CONVERTED headers should be removed
+ if (state->flags & QTextCodec::IgnoreHeader && state->state_data[0] == 0) {
+
+ state->state_data[0] = 0xff; // bom handling only on first state
+
+ if (charsetId == KCharacterSetIdentifierUcs2 && outputBuffer.size() > 1) {
+
+ QChar bom(QChar::ByteOrderMark);
+ if (outputBuffer.at(0) == bom.row() && outputBuffer.at(1) == bom.cell()) {
+ outputBuffer.remove(0, 2);
+ } else if (outputBuffer.at(0) == bom.cell() && outputBuffer.at(1) == bom.row()) {
+ outputBuffer.remove(0, 2);
+ }
+
+ } else if ((charsetId == KCharacterSetIdentifierUtf8 ||
+ charsetId == KCharacterSetIdentifierJavaConformantUtf8) &&
+ outputBuffer.size() > 2) {
+ if (outputBuffer.at(0) == 0xef && outputBuffer.at(1) == 0xbb && outputBuffer.at(2) == 0xbf) {
+ outputBuffer.remove(0, 3);
+ }
+
+ } else if (charsetId == KCharacterSetIdentifierUnicodeLittle &&
+ outputBuffer.size() > 1) {
+
+ QChar bom(QChar::ByteOrderMark);
+ if (outputBuffer.at(0) == bom.row() && outputBuffer.at(1) == bom.cell()) {
+ outputBuffer.remove(0, 2);
+ }
+
+ } else if (charsetId == KCharacterSetIdentifierUnicodeBig &&
+ outputBuffer.size() > 1) {
+
+ QChar bom(QChar::ByteOrderSwapped);
+ if (outputBuffer.at(0) == bom.row() && outputBuffer.at(1) == bom.cell()) {
+ outputBuffer.remove(0, 2);
+ }
+ }
+
+ }
+ }
+
+ return outputBuffer;
+}
+
+
+uint QSymbianTextCodec::getLanguageDependentCharacterSet()
+{
+ TLanguage lang = User::Language();
+
+ uint langIndex = 0;
+
+ switch (lang) {
+ case 14: //ELangTurkish
+ langIndex = KCharacterSetIdentifierIso88599; break;
+ case 16: //ELangRussian
+ langIndex = KCharacterSetIdentifierIso88595; break;
+ case 17: //ELangHungarian
+ langIndex = KCharacterSetIdentifierIso88592; break;
+ case 25: //ELangCzec
+ case 26: //ELangSlovak
+ case 27: //ELangPolish
+ case 28: //ELangSlovenian
+ langIndex = KCharacterSetIdentifierIso88592; break;
+ case 29: //ELangTaiwanChinese
+ case 30: //ELangHongKongChinese
+ langIndex = KCharacterSetIdentifierBig5; break;
+ case 31: //ELangPrcChinese
+ langIndex = KCharacterSetIdentifierGbk; break;
+ case 32: //ELangJapanese
+ langIndex = KCharacterSetIdentifierShiftJis; break;
+ case 33: //ELangThai
+ langIndex = 270501193 /*KCharacterSetIdentifierTis620*/; break;
+ case 37: //ELangArabic
+ langIndex = KCharacterSetIdentifierIso88596; break;
+ case 40: //ELangBelarussian
+ case 42: //ELangBulgarian
+ langIndex = KCharacterSetIdentifierIso88595; break;
+ case 45: //ELangCroatian
+ langIndex = KCharacterSetIdentifierIso88592; break;
+ case 49: //ELangEstonian
+ langIndex = KCharacterSetIdentifierIso88594; break;
+ case 54: //ELangGreek
+ case 55: //ELangCyprusGreek
+ langIndex = KCharacterSetIdentifierIso88597; break;
+ case 57: //ELangHebrew
+ langIndex = KCharacterSetIdentifierIso88598; break;
+ case 58: //ELangHindi
+ langIndex = 271011982/*KCharacterSetIdentifierIscii*/; break;
+ case 67: //ELangLatvian
+ case 68: //ELangLithuanian
+ langIndex = KCharacterSetIdentifierIso88594; break;
+ case 69: //ELangMacedonian
+ langIndex = KCharacterSetIdentifierIso88595; break;
+ case 78: //ELangRomanian
+ langIndex = KCharacterSetIdentifierIso88592; break;
+ case 79: //ELangSerbian
+ langIndex = KCharacterSetIdentifierIso88592; break;
+ case 91: //ELangCyprusTurkish
+ langIndex = KCharacterSetIdentifierIso88599; break;
+ case 93: //ELangUkrainian
+ langIndex = KCharacterSetIdentifierIso88595; break;
+ case 94: //ELangUrdu
+ langIndex = KCharacterSetIdentifierIso88596; break;
+ case 157: //ELangEnglish_Taiwan
+ case 158: //ELangEnglish_HongKong
+ langIndex = KCharacterSetIdentifierBig5; break;
+ case 159: //ELangEnglish_Prc
+ langIndex = KCharacterSetIdentifierGbk; break;
+ case 160:
+ langIndex = KCharacterSetIdentifierShiftJis; break;
+ case 161: //ELangEnglish_Thailand
+ langIndex = 270501193/*KCharacterSetIdentifierTis620*/; break;
+ }
+
+ if (langIndex > 0) {
+ return langIndex;
+ }
+ return KCharacterSetIdentifierCodePage1252;
+}
+
+/* Create the codecs that have aliases and return the locale mapper*/
+QSymbianTextCodec *QSymbianTextCodec::init()
+{
+ const uint localeMapperId = getLanguageDependentCharacterSet();
+ QScopedPointer<CArrayFix<CCnvCharacterSetConverter::SCharacterSet> > array;
+ QT_TRAP_THROWING(array.reset(CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableL(qt_s60GetRFs())))
+ CCnvCharacterSetConverter *converter = QSymbianTextCodec::converter();
+ int count = array->Count();
+ for (int i = 0; i < count; i++) {
+ int charsetId = array->At(i).Identifier();
+
+ // skip builtin Qt codecs
+ if (charsetId == KCharacterSetIdentifierUtf8 || charsetId == KCharacterSetIdentifierUnicodeLittle
+ || charsetId == KCharacterSetIdentifierUnicodeLittle || charsetId == KCharacterSetIdentifierUnicodeBig
+ || charsetId == KCharacterSetIdentifierIso88591
+ || charsetId == 270501691 /* skip Windows-1252 duplicate*/) {
+ continue;
+ }
+
+ int begin = 0;
+ int n = sizeof(codecsData) / sizeof(codecsData[0]);
+ int half;
+
+ while (n > 0) {
+ half = n >> 1;
+ int middle = begin + half;
+ if (codecsData[middle].charsetId < charsetId) {
+ begin = middle + 1;
+ n -= half + 1;
+ } else {
+ n = half;
+ }
+ }
+ if (codecsData[begin].charsetId == charsetId) {
+ QSymbianTextCodec *c = new QSymbianTextCodec(charsetId, begin);
+ if (charsetId == localeMapperId)
+ localeMapper = c;
+ } else {
+ // We did not find the charsetId in our codecsData[], therefore we ask
+ // the OS for the codec name. We first try to get a "standard name" and fall
+ // back to array->At(i).Name(), if really needed. array->At(i).Name() is not
+ // guaranteed to be a correct name for QTextCodec::codecFromName().
+ QScopedPointer<HBufC8> buf;
+ QT_TRAP_THROWING(buf.reset(converter->ConvertCharacterSetIdentifierToStandardNameL(charsetId, qt_s60GetRFs())))
+ QByteArray name;
+ if (buf && buf->Length()) {
+ name = QByteArray(reinterpret_cast<const char *>(buf->Ptr()), buf->Length());
+ } else {
+ TPtrC charSetName = array->At(i).NameIsFileName() ? TParsePtrC(array->At(i).Name()).Name() : array->At(i).Name();
+ int len = charSetName.Length();
+ QString str;
+ str.setUnicode(reinterpret_cast<const QChar*>(charSetName.Ptr()), len);
+ name = str.toLatin1();
+ }
+ if (!name.isEmpty())
+ new QSymbianTextCodecWithName(charsetId, name);
+ }
+
+ }
+ return localeMapper;
+}
diff --git a/src/corelib/codecs/qtextcodecplugin.cpp b/src/corelib/codecs/qtextcodecplugin.cpp
new file mode 100644
index 0000000000..aac98f4362
--- /dev/null
+++ b/src/corelib/codecs/qtextcodecplugin.cpp
@@ -0,0 +1,161 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qtextcodecplugin.h"
+#include "qstringlist.h"
+
+#ifndef QT_NO_TEXTCODECPLUGIN
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QTextCodecPlugin
+ \brief The QTextCodecPlugin class provides an abstract base for custom QTextCodec plugins.
+ \reentrant
+ \ingroup plugins
+
+ The text codec plugin is a simple plugin interface that makes it
+ easy to create custom text codecs that can be loaded dynamically
+ into applications.
+
+ Writing a text codec plugin is achieved by subclassing this base
+ class, reimplementing the pure virtual functions names(),
+ aliases(), createForName(), mibEnums() and createForMib(), and
+ exporting the class with the Q_EXPORT_PLUGIN2() macro. See \l{How
+ to Create Qt Plugins} for details.
+
+ See the \l{http://www.iana.org/assignments/character-sets}{IANA
+ character-sets encoding file} for more information on mime
+ names and mib enums.
+*/
+
+/*!
+ \fn QStringList QTextCodecPlugin::names() const
+
+ Returns the list of MIME names supported by this plugin.
+
+ If a codec has several names, the extra names are returned by aliases().
+
+ \sa createForName(), aliases()
+*/
+
+/*!
+ \fn QList<QByteArray> QTextCodecPlugin::aliases() const
+
+ Returns the list of aliases supported by this plugin.
+*/
+
+/*!
+ \fn QTextCodec *QTextCodecPlugin::createForName(const QByteArray &name)
+
+ Creates a QTextCodec object for the codec called \a name. The \a name
+ must come from the list of encodings returned by names(). Encoding
+ names are case sensitive.
+
+ Example:
+
+ \snippet doc/src/snippets/code/src_corelib_codecs_qtextcodecplugin.cpp 0
+
+ \sa names()
+*/
+
+
+/*!
+ \fn QList<int> QTextCodecPlugin::mibEnums() const
+
+ Returns the list of mib enums supported by this plugin.
+
+ \sa createForMib()
+*/
+
+/*!
+ \fn QTextCodec *QTextCodecPlugin::createForMib(int mib);
+
+ Creates a QTextCodec object for the mib enum \a mib.
+
+ See \l{http://www.iana.org/assignments/character-sets}{the
+ IANA character-sets encoding file} for more information.
+
+ \sa mibEnums()
+*/
+
+/*!
+ Constructs a text codec plugin with the given \a parent. This is
+ invoked automatically by the Q_EXPORT_PLUGIN2() macro.
+*/
+QTextCodecPlugin::QTextCodecPlugin(QObject *parent)
+ : QObject(parent)
+{
+}
+
+/*!
+ Destroys the text codec plugin.
+
+ You never have to call this explicitly. Qt destroys a plugin
+ automatically when it is no longer used.
+*/
+QTextCodecPlugin::~QTextCodecPlugin()
+{
+}
+
+QStringList QTextCodecPlugin::keys() const
+{
+ QStringList keys;
+ QList<QByteArray> list = names();
+ list += aliases();
+ for (int i = 0; i < list.size(); ++i)
+ keys += QString::fromLatin1(list.at(i));
+ QList<int> mibs = mibEnums();
+ for (int i = 0; i < mibs.count(); ++i)
+ keys += QLatin1String("MIB: ") + QString::number(mibs.at(i));
+ return keys;
+}
+
+QTextCodec *QTextCodecPlugin::create(const QString &name)
+{
+ if (name.startsWith(QLatin1String("MIB: ")))
+ return createForMib(name.mid(4).toInt());
+ return createForName(name.toLatin1());
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_TEXTCODECPLUGIN
diff --git a/src/corelib/codecs/qtextcodecplugin.h b/src/corelib/codecs/qtextcodecplugin.h
new file mode 100644
index 0000000000..80c1d17344
--- /dev/null
+++ b/src/corelib/codecs/qtextcodecplugin.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QTEXTCODECPLUGIN_H
+#define QTEXTCODECPLUGIN_H
+
+#include <QtCore/qplugin.h>
+#include <QtCore/qfactoryinterface.h>
+#include <QtCore/qlist.h>
+#include <QtCore/qbytearray.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Core)
+
+#ifndef QT_NO_TEXTCODECPLUGIN
+
+class QTextCodec;
+
+struct Q_CORE_EXPORT QTextCodecFactoryInterface : public QFactoryInterface
+{
+ virtual QTextCodec *create(const QString &key) = 0;
+};
+
+#define QTextCodecFactoryInterface_iid "com.trolltech.Qt.QTextCodecFactoryInterface"
+
+Q_DECLARE_INTERFACE(QTextCodecFactoryInterface, QTextCodecFactoryInterface_iid)
+
+
+class Q_CORE_EXPORT QTextCodecPlugin : public QObject, public QTextCodecFactoryInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(QTextCodecFactoryInterface:QFactoryInterface)
+public:
+ explicit QTextCodecPlugin(QObject *parent = 0);
+ ~QTextCodecPlugin();
+
+ virtual QList<QByteArray> names() const = 0;
+ virtual QList<QByteArray> aliases() const = 0;
+ virtual QTextCodec *createForName(const QByteArray &name) = 0;
+
+ virtual QList<int> mibEnums() const = 0;
+ virtual QTextCodec *createForMib(int mib) = 0;
+
+private:
+ QStringList keys() const;
+ QTextCodec *create(const QString &name);
+};
+
+#endif // QT_NO_TEXTCODECPLUGIN
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QTEXTCODECPLUGIN_H
diff --git a/src/corelib/codecs/qtsciicodec.cpp b/src/corelib/codecs/qtsciicodec.cpp
new file mode 100644
index 0000000000..2550b07eb5
--- /dev/null
+++ b/src/corelib/codecs/qtsciicodec.cpp
@@ -0,0 +1,498 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// Most of the code here was originally written by Hans Petter Bieker,
+// and is included in Qt with the author's permission, and the grateful
+// thanks of the Qt team.
+
+#include "qtsciicodec_p.h"
+#include "qlist.h"
+
+#ifndef QT_NO_CODECS
+
+QT_BEGIN_NAMESPACE
+
+static unsigned char qt_UnicodeToTSCII(ushort u1, ushort u2, ushort u3);
+static unsigned int qt_TSCIIToUnicode(unsigned int code, uint *s);
+
+#define IsTSCIIChar(c) (((c) >= 0x80) && ((c) <= 0xfd))
+
+/*! \class QTsciiCodec
+ \reentrant
+ \internal
+*/
+
+/*!
+ Destroys the text codec object.
+*/
+QTsciiCodec::~QTsciiCodec()
+{
+}
+
+/*!
+ Converts the first \a len characters in \a uc from Unicode to this
+ encoding, and returns the result in a byte array. The \a state contains
+ some conversion flags, and is used by the codec to maintain state
+ information.
+*/
+QByteArray QTsciiCodec::convertFromUnicode(const QChar *uc, int len, ConverterState *state) const
+{
+ char replacement = '?';
+ if (state) {
+ if (state->flags & ConvertInvalidToNull)
+ replacement = 0;
+ }
+ int invalid = 0;
+
+ QByteArray rstr(len, Qt::Uninitialized);
+ uchar* cursor = (uchar*)rstr.data();
+ for (int i = 0; i < len; i++) {
+ QChar ch = uc[i];
+ uchar j;
+ if (ch.row() == 0x00 && ch.cell() < 0x80) {
+ // ASCII
+ j = ch.cell();
+ } else if ((j = qt_UnicodeToTSCII(uc[i].unicode(),
+ uc[i + 1].unicode(),
+ uc[i + 2].unicode()))) {
+ // We have to check the combined chars first!
+ i += 2;
+ } else if ((j = qt_UnicodeToTSCII(uc[i].unicode(),
+ uc[i + 1].unicode(), 0))) {
+ i++;
+ } else if ((j = qt_UnicodeToTSCII(uc[i].unicode(), 0, 0))) {
+ } else {
+ // Error
+ j = replacement;
+ ++invalid;
+ }
+ *cursor++ = j;
+ }
+ rstr.resize(cursor - (const uchar*)rstr.constData());
+
+ if (state) {
+ state->invalidChars += invalid;
+ }
+ return rstr;
+}
+
+/*!
+ Converts the first \a len characters in \a chars from this encoding
+ to Unicode, and returns the result in a QString. The \a state contains
+ some conversion flags, and is used by the codec to maintain state
+ information.
+*/
+QString QTsciiCodec::convertToUnicode(const char* chars, int len, ConverterState *state) const
+{
+ QChar replacement = QChar::ReplacementCharacter;
+ if (state) {
+ if (state->flags & ConvertInvalidToNull)
+ replacement = QChar::Null;
+ }
+ int invalid = 0;
+
+ QString result;
+ for (int i = 0; i < len; i++) {
+ uchar ch = chars[i];
+ if (ch < 0x80) {
+ // ASCII
+ result += QLatin1Char(ch);
+ } else if (IsTSCIIChar(ch)) {
+ // TSCII
+ uint s[3];
+ uint u = qt_TSCIIToUnicode(ch, s);
+ uint *p = s;
+ while (u--) {
+ uint c = *p++;
+ if (c)
+ result += QChar(c);
+ else {
+ result += replacement;
+ ++invalid;
+ }
+ }
+ } else {
+ // Invalid
+ result += replacement;
+ ++invalid;
+ }
+ }
+
+ if (state) {
+ state->invalidChars += invalid;
+ }
+ return result;
+}
+
+/*!
+ Returns the official name for the encoding that is handled by the codec.
+
+ \sa QTextCodec::name()
+*/
+QByteArray QTsciiCodec::name() const
+{
+ return "TSCII";
+}
+
+/*!
+ Returns the MIB enum for the encoding.
+
+ \sa QTextCodec::mibEnum()
+*/
+int QTsciiCodec::mibEnum() const
+{
+ return 2107;
+}
+
+static const int UnToTsLast = 124; // 125 items -- so the last will be 124
+static const ushort UnToTs [][4] = {
+ // *Sorted* list of TSCII maping for unicode chars
+ //FIRST SECOND THIRD TSCII
+ {0x00A0, 0x0000, 0x0000, 0xA0},
+ {0x00A9, 0x0000, 0x0000, 0xA9},
+ {0x0B83, 0x0000, 0x0000, 0xB7},
+ {0x0B85, 0x0000, 0x0000, 0xAB},
+ {0x0B86, 0x0000, 0x0000, 0xAC},
+ {0x0B87, 0x0000, 0x0000, 0xAD},
+ {0x0B88, 0x0000, 0x0000, 0xAE},
+ {0x0B89, 0x0000, 0x0000, 0xAF},
+ {0x0B8A, 0x0000, 0x0000, 0xB0},
+ {0x0B8E, 0x0000, 0x0000, 0xB1},
+ {0x0B8F, 0x0000, 0x0000, 0xB2},
+ {0x0B90, 0x0000, 0x0000, 0xB3},
+ {0x0B92, 0x0000, 0x0000, 0xB4},
+ {0x0B93, 0x0000, 0x0000, 0xB5},
+ {0x0B94, 0x0000, 0x0000, 0xB6},
+ {0x0B95, 0x0000, 0x0000, 0xB8},
+ {0x0B95, 0x0B82, 0x0000, 0xEC},
+ {0x0B95, 0x0BC1, 0x0000, 0xCC},
+ {0x0B95, 0x0BC2, 0x0000, 0xDC},
+ {0x0B99, 0x0000, 0x0000, 0xB9},
+ {0x0B99, 0x0B82, 0x0000, 0xED},
+ {0x0B99, 0x0BC1, 0x0000, 0x99},
+ {0x0B99, 0x0BC2, 0x0000, 0x9B},
+ {0x0B9A, 0x0000, 0x0000, 0xBA},
+ {0x0B9A, 0x0B82, 0x0000, 0xEE},
+ {0x0B9A, 0x0BC1, 0x0000, 0xCD},
+ {0x0B9A, 0x0BC2, 0x0000, 0xDD},
+ {0x0B9C, 0x0000, 0x0000, 0x83},
+ {0x0B9C, 0x0B82, 0x0000, 0x88},
+ {0x0B9E, 0x0000, 0x0000, 0xBB},
+ {0x0B9E, 0x0B82, 0x0000, 0xEF},
+ {0x0B9E, 0x0BC1, 0x0000, 0x9A},
+ {0x0B9E, 0x0BC2, 0x0000, 0x9C},
+ {0x0B9F, 0x0000, 0x0000, 0xBC},
+ {0x0B9F, 0x0B82, 0x0000, 0xF0},
+ {0x0B9F, 0x0BBF, 0x0000, 0xCA},
+ {0x0B9F, 0x0BC0, 0x0000, 0xCB},
+ {0x0B9F, 0x0BC1, 0x0000, 0xCE},
+ {0x0B9F, 0x0BC2, 0x0000, 0xDE},
+ {0x0BA1, 0x0B82, 0x0000, 0xF2},
+ {0x0BA3, 0x0000, 0x0000, 0xBD},
+ {0x0BA3, 0x0B82, 0x0000, 0xF1},
+ {0x0BA3, 0x0BC1, 0x0000, 0xCF},
+ {0x0BA3, 0x0BC2, 0x0000, 0xDF},
+ {0x0BA4, 0x0000, 0x0000, 0xBE},
+ {0x0BA4, 0x0BC1, 0x0000, 0xD0},
+ {0x0BA4, 0x0BC2, 0x0000, 0xE0},
+ {0x0BA8, 0x0000, 0x0000, 0xBF},
+ {0x0BA8, 0x0B82, 0x0000, 0xF3},
+ {0x0BA8, 0x0BC1, 0x0000, 0xD1},
+ {0x0BA8, 0x0BC2, 0x0000, 0xE1},
+ {0x0BA9, 0x0000, 0x0000, 0xC9},
+ {0x0BA9, 0x0B82, 0x0000, 0xFD},
+ {0x0BA9, 0x0BC1, 0x0000, 0xDB},
+ {0x0BA9, 0x0BC2, 0x0000, 0xEB},
+ {0x0BAA, 0x0000, 0x0000, 0xC0},
+ {0x0BAA, 0x0B82, 0x0000, 0xF4},
+ {0x0BAA, 0x0BC1, 0x0000, 0xD2},
+ {0x0BAA, 0x0BC2, 0x0000, 0xE2},
+ {0x0BAE, 0x0000, 0x0000, 0xC1},
+ {0x0BAE, 0x0B82, 0x0000, 0xF5},
+ {0x0BAE, 0x0BC1, 0x0000, 0xD3},
+ {0x0BAE, 0x0BC2, 0x0000, 0xE3},
+ {0x0BAF, 0x0000, 0x0000, 0xC2},
+ {0x0BAF, 0x0B82, 0x0000, 0xF6},
+ {0x0BAF, 0x0BC1, 0x0000, 0xD4},
+ {0x0BAF, 0x0BC2, 0x0000, 0xE4},
+ {0x0BB0, 0x0000, 0x0000, 0xC3},
+ {0x0BB0, 0x0B82, 0x0000, 0xF7},
+ {0x0BB0, 0x0BC1, 0x0000, 0xD5},
+ {0x0BB0, 0x0BC2, 0x0000, 0xE5},
+ {0x0BB1, 0x0000, 0x0000, 0xC8},
+ {0x0BB1, 0x0B82, 0x0000, 0xFC},
+ {0x0BB1, 0x0BC1, 0x0000, 0xDA},
+ {0x0BB1, 0x0BC2, 0x0000, 0xEA},
+ {0x0BB2, 0x0000, 0x0000, 0xC4},
+ {0x0BB2, 0x0B82, 0x0000, 0xF8},
+ {0x0BB2, 0x0BC1, 0x0000, 0xD6},
+ {0x0BB2, 0x0BC2, 0x0000, 0xE6},
+ {0x0BB3, 0x0000, 0x0000, 0xC7},
+ {0x0BB3, 0x0B82, 0x0000, 0xFB},
+ {0x0BB3, 0x0BC1, 0x0000, 0xD9},
+ {0x0BB3, 0x0BC2, 0x0000, 0xE9},
+ {0x0BB4, 0x0000, 0x0000, 0xC6},
+ {0x0BB4, 0x0B82, 0x0000, 0xFA},
+ {0x0BB4, 0x0BC1, 0x0000, 0xD8},
+ {0x0BB4, 0x0BC2, 0x0000, 0xE8},
+ {0x0BB5, 0x0000, 0x0000, 0xC5},
+ {0x0BB5, 0x0B82, 0x0000, 0xF9},
+ {0x0BB5, 0x0BC1, 0x0000, 0xD7},
+ {0x0BB5, 0x0BC2, 0x0000, 0xE7},
+ {0x0BB7, 0x0000, 0x0000, 0x84},
+ {0x0BB7, 0x0B82, 0x0000, 0x89},
+ {0x0BB8, 0x0000, 0x0000, 0x85},
+ {0x0BB8, 0x0B82, 0x0000, 0x8A},
+ {0x0BB9, 0x0000, 0x0000, 0x86},
+ {0x0BB9, 0x0B82, 0x0000, 0x8B},
+ {0x0BBE, 0x0000, 0x0000, 0xA1},
+ {0x0BBF, 0x0000, 0x0000, 0xA2},
+ {0x0BC0, 0x0000, 0x0000, 0xA3},
+ {0x0BC1, 0x0000, 0x0000, 0xA4},
+ {0x0BC2, 0x0000, 0x0000, 0xA5},
+ {0x0BC6, 0x0000, 0x0000, 0xA6},
+ {0x0BC7, 0x0000, 0x0000, 0xA7},
+ {0x0BC8, 0x0000, 0x0000, 0xA8},
+ {0x0BCC, 0x0000, 0x0000, 0xAA},
+ {0x0BE6, 0x0000, 0x0000, 0x80},
+ {0x0BE7, 0x0000, 0x0000, 0x81},
+ {0x0BE7, 0x0BB7, 0x0000, 0x87},
+ {0x0BE7, 0x0BB7, 0x0B82, 0x8C},
+ {0x0BE8, 0x0000, 0x0000, 0x8D},
+ {0x0BE9, 0x0000, 0x0000, 0x8E},
+ {0x0BEA, 0x0000, 0x0000, 0x8F},
+ {0x0BEB, 0x0000, 0x0000, 0x90},
+ {0x0BEC, 0x0000, 0x0000, 0x95},
+ {0x0BED, 0x0000, 0x0000, 0x96},
+ {0x0BEE, 0x0000, 0x0000, 0x97},
+ {0x0BEF, 0x0000, 0x0000, 0x98},
+ {0x0BF0, 0x0000, 0x0000, 0x9D},
+ {0x0BF1, 0x0000, 0x0000, 0x9E},
+ {0x0BF2, 0x0000, 0x0000, 0x9F},
+ {0x2018, 0x0000, 0x0000, 0x91},
+ {0x2019, 0x0000, 0x0000, 0x92},
+ {0x201C, 0x0000, 0x0000, 0x93},
+ {0x201C, 0x0000, 0x0000, 0x94}
+};
+
+static const ushort TsToUn [][3] = {
+ // Starting at 0x80
+ {0x0BE6, 0x0000, 0x0000},
+ {0x0BE7, 0x0000, 0x0000},
+ {0x0000, 0x0000, 0x0000}, // unknown
+ {0x0B9C, 0x0000, 0x0000},
+ {0x0BB7, 0x0000, 0x0000},
+ {0x0BB8, 0x0000, 0x0000},
+ {0x0BB9, 0x0000, 0x0000},
+ {0x0BE7, 0x0BB7, 0x0000},
+ {0x0B9C, 0x0B82, 0x0000},
+ {0x0BB7, 0x0B82, 0x0000},
+ {0x0BB8, 0x0B82, 0x0000},
+ {0x0BB9, 0x0B82, 0x0000},
+ {0x0BE7, 0x0BB7, 0x0B82},
+ {0x0BE8, 0x0000, 0x0000},
+ {0x0BE9, 0x0000, 0x0000},
+ {0x0BEA, 0x0000, 0x0000},
+ {0x0BEB, 0x0000, 0x0000},
+ {0x2018, 0x0000, 0x0000},
+ {0x2019, 0x0000, 0x0000},
+ {0x201C, 0x0000, 0x0000},
+ {0x201C, 0x0000, 0x0000}, // two of the same??
+ {0x0BEC, 0x0000, 0x0000},
+ {0x0BED, 0x0000, 0x0000},
+ {0x0BEE, 0x0000, 0x0000},
+ {0x0BEF, 0x0000, 0x0000},
+ {0x0B99, 0x0BC1, 0x0000},
+ {0x0B9E, 0x0BC1, 0x0000},
+ {0x0B99, 0x0BC2, 0x0000},
+ {0x0B9E, 0x0BC2, 0x0000},
+ {0x0BF0, 0x0000, 0x0000},
+ {0x0BF1, 0x0000, 0x0000},
+ {0x0BF2, 0x0000, 0x0000},
+ {0x00A0, 0x0000, 0x0000},
+ {0x0BBE, 0x0000, 0x0000},
+ {0x0BBF, 0x0000, 0x0000},
+ {0x0BC0, 0x0000, 0x0000},
+ {0x0BC1, 0x0000, 0x0000},
+ {0x0BC2, 0x0000, 0x0000},
+ {0x0BC6, 0x0000, 0x0000},
+ {0x0BC7, 0x0000, 0x0000},
+ {0x0BC8, 0x0000, 0x0000},
+ {0x00A9, 0x0000, 0x0000},
+ {0x0BCC, 0x0000, 0x0000},
+ {0x0B85, 0x0000, 0x0000},
+ {0x0B86, 0x0000, 0x0000},
+ {0x0B87, 0x0000, 0x0000},
+ {0x0B88, 0x0000, 0x0000},
+ {0x0B89, 0x0000, 0x0000},
+ {0x0B8A, 0x0000, 0x0000},
+ {0x0B8E, 0x0000, 0x0000},
+ {0x0B8F, 0x0000, 0x0000},
+ {0x0B90, 0x0000, 0x0000},
+ {0x0B92, 0x0000, 0x0000},
+ {0x0B93, 0x0000, 0x0000},
+ {0x0B94, 0x0000, 0x0000},
+ {0x0B83, 0x0000, 0x0000},
+ {0x0B95, 0x0000, 0x0000},
+ {0x0B99, 0x0000, 0x0000},
+ {0x0B9A, 0x0000, 0x0000},
+ {0x0B9E, 0x0000, 0x0000},
+ {0x0B9F, 0x0000, 0x0000},
+ {0x0BA3, 0x0000, 0x0000},
+ {0x0BA4, 0x0000, 0x0000},
+ {0x0BA8, 0x0000, 0x0000},
+ {0x0BAA, 0x0000, 0x0000},
+ {0x0BAE, 0x0000, 0x0000},
+ {0x0BAF, 0x0000, 0x0000},
+ {0x0BB0, 0x0000, 0x0000},
+ {0x0BB2, 0x0000, 0x0000},
+ {0x0BB5, 0x0000, 0x0000},
+ {0x0BB4, 0x0000, 0x0000},
+ {0x0BB3, 0x0000, 0x0000},
+ {0x0BB1, 0x0000, 0x0000},
+ {0x0BA9, 0x0000, 0x0000},
+ {0x0B9F, 0x0BBF, 0x0000},
+ {0x0B9F, 0x0BC0, 0x0000},
+ {0x0B95, 0x0BC1, 0x0000},
+ {0x0B9A, 0x0BC1, 0x0000},
+ {0x0B9F, 0x0BC1, 0x0000},
+ {0x0BA3, 0x0BC1, 0x0000},
+ {0x0BA4, 0x0BC1, 0x0000},
+ {0x0BA8, 0x0BC1, 0x0000},
+ {0x0BAA, 0x0BC1, 0x0000},
+ {0x0BAE, 0x0BC1, 0x0000},
+ {0x0BAF, 0x0BC1, 0x0000},
+ {0x0BB0, 0x0BC1, 0x0000},
+ {0x0BB2, 0x0BC1, 0x0000},
+ {0x0BB5, 0x0BC1, 0x0000},
+ {0x0BB4, 0x0BC1, 0x0000},
+ {0x0BB3, 0x0BC1, 0x0000},
+ {0x0BB1, 0x0BC1, 0x0000},
+ {0x0BA9, 0x0BC1, 0x0000},
+ {0x0B95, 0x0BC2, 0x0000},
+ {0x0B9A, 0x0BC2, 0x0000},
+ {0x0B9F, 0x0BC2, 0x0000},
+ {0x0BA3, 0x0BC2, 0x0000},
+ {0x0BA4, 0x0BC2, 0x0000},
+ {0x0BA8, 0x0BC2, 0x0000},
+ {0x0BAA, 0x0BC2, 0x0000},
+ {0x0BAE, 0x0BC2, 0x0000},
+ {0x0BAF, 0x0BC2, 0x0000},
+ {0x0BB0, 0x0BC2, 0x0000},
+ {0x0BB2, 0x0BC2, 0x0000},
+ {0x0BB5, 0x0BC2, 0x0000},
+ {0x0BB4, 0x0BC2, 0x0000},
+ {0x0BB3, 0x0BC2, 0x0000},
+ {0x0BB1, 0x0BC2, 0x0000},
+ {0x0BA9, 0x0BC2, 0x0000},
+ {0x0B95, 0x0B82, 0x0000},
+ {0x0B99, 0x0B82, 0x0000},
+ {0x0B9A, 0x0B82, 0x0000},
+ {0x0B9E, 0x0B82, 0x0000},
+ {0x0B9F, 0x0B82, 0x0000},
+ {0x0BA3, 0x0B82, 0x0000},
+ {0x0BA1, 0x0B82, 0x0000},
+ {0x0BA8, 0x0B82, 0x0000},
+ {0x0BAA, 0x0B82, 0x0000},
+ {0x0BAE, 0x0B82, 0x0000},
+ {0x0BAF, 0x0B82, 0x0000},
+ {0x0BB0, 0x0B82, 0x0000},
+ {0x0BB2, 0x0B82, 0x0000},
+ {0x0BB5, 0x0B82, 0x0000},
+ {0x0BB4, 0x0B82, 0x0000},
+ {0x0BB3, 0x0B82, 0x0000},
+ {0x0BB1, 0x0B82, 0x0000},
+ {0x0BA9, 0x0B82, 0x0000}
+};
+
+static int cmp(const ushort *s1, const ushort *s2, size_t len)
+{
+ int diff = 0;
+
+ while (len-- && (diff = *s1++ - *s2++) == 0)
+ ;
+
+ return diff;
+}
+
+static unsigned char qt_UnicodeToTSCII(ushort u1, ushort u2, ushort u3)
+{
+ ushort s[3];
+ s[0] = u1;
+ s[1] = u2;
+ s[2] = u3;
+
+ int a = 0; // start pos
+ int b = UnToTsLast; // end pos
+
+ // do a binary search for the composed unicode in the list
+ while (a <= b) {
+ int w = (a + b) / 2;
+ int j = cmp(UnToTs[w], s, 3);
+
+ if (j == 0)
+ // found it
+ return UnToTs[w][3];
+
+ if (j < 0)
+ a = w + 1;
+ else
+ b = w - 1;
+ }
+
+ return 0;
+}
+
+static unsigned int qt_TSCIIToUnicode(uint code, uint *s)
+{
+ int len = 0;
+ for (int i = 0; i < 3; i++) {
+ uint u = TsToUn[code & 0x7f][i];
+ s[i] = u;
+ if (s[i]) len = i + 1;
+ }
+
+ return len;
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_CODECS
diff --git a/src/corelib/codecs/qtsciicodec_p.h b/src/corelib/codecs/qtsciicodec_p.h
new file mode 100644
index 0000000000..7e2bed4e64
--- /dev/null
+++ b/src/corelib/codecs/qtsciicodec_p.h
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// Most of the code here was originally written by Hans Petter Bieker,
+// and is included in Qt with the author's permission, and the grateful
+// thanks of the Qt team.
+
+/*
+ * Copyright (C) 2000 Hans Petter Bieker. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef QTSCIICODEC_P_H
+#define QTSCIICODEC_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "QtCore/qtextcodec.h"
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_CODECS
+
+class QTsciiCodec : public QTextCodec {
+public:
+ ~QTsciiCodec();
+
+ QByteArray name() const;
+ int mibEnum() const;
+
+ QString convertToUnicode(const char *, int, ConverterState *) const;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+};
+
+#endif // QT_NO_CODECS
+
+QT_END_NAMESPACE
+
+#endif // QTSCIICODEC_P_H
diff --git a/src/corelib/codecs/qutfcodec.cpp b/src/corelib/codecs/qutfcodec.cpp
new file mode 100644
index 0000000000..c44832936d
--- /dev/null
+++ b/src/corelib/codecs/qutfcodec.cpp
@@ -0,0 +1,670 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qutfcodec_p.h"
+#include "qlist.h"
+#include "qendian.h"
+#include "qchar.h"
+
+QT_BEGIN_NAMESPACE
+
+enum { Endian = 0, Data = 1 };
+
+static inline bool isUnicodeNonCharacter(uint ucs4)
+{
+ // Unicode has a couple of "non-characters" that one can use internally,
+ // but are not allowed to be used for text interchange.
+ //
+ // Those are the last two entries each Unicode Plane (U+FFFE, U+FFFF,
+ // U+1FFFE, U+1FFFF, etc.) as well as the entries between U+FDD0 and
+ // U+FDEF (inclusive)
+
+ return (ucs4 & 0xfffe) == 0xfffe
+ || (ucs4 - 0xfdd0U) < 16;
+}
+
+QByteArray QUtf8::convertFromUnicode(const QChar *uc, int len, QTextCodec::ConverterState *state)
+{
+ uchar replacement = '?';
+ int rlen = 3*len;
+ int surrogate_high = -1;
+ if (state) {
+ if (state->flags & QTextCodec::ConvertInvalidToNull)
+ replacement = 0;
+ if (!(state->flags & QTextCodec::IgnoreHeader))
+ rlen += 3;
+ if (state->remainingChars)
+ surrogate_high = state->state_data[0];
+ }
+
+ QByteArray rstr;
+ rstr.resize(rlen);
+ uchar* cursor = (uchar*)rstr.data();
+ const QChar *ch = uc;
+ int invalid = 0;
+ if (state && !(state->flags & QTextCodec::IgnoreHeader)) {
+ *cursor++ = 0xef;
+ *cursor++ = 0xbb;
+ *cursor++ = 0xbf;
+ }
+
+ const QChar *end = ch + len;
+ while (ch < end) {
+ uint u = ch->unicode();
+ if (surrogate_high >= 0) {
+ if (u >= 0xdc00 && u < 0xe000) {
+ u = (surrogate_high - 0xd800)*0x400 + (u - 0xdc00) + 0x10000;
+ surrogate_high = -1;
+ } else {
+ // high surrogate without low
+ *cursor = replacement;
+ ++ch;
+ ++invalid;
+ surrogate_high = -1;
+ continue;
+ }
+ } else if (u >= 0xdc00 && u < 0xe000) {
+ // low surrogate without high
+ *cursor = replacement;
+ ++ch;
+ ++invalid;
+ continue;
+ } else if (u >= 0xd800 && u < 0xdc00) {
+ surrogate_high = u;
+ ++ch;
+ continue;
+ }
+
+ if (u < 0x80) {
+ *cursor++ = (uchar)u;
+ } else {
+ if (u < 0x0800) {
+ *cursor++ = 0xc0 | ((uchar) (u >> 6));
+ } else {
+ // is it one of the Unicode non-characters?
+ if (isUnicodeNonCharacter(u)) {
+ *cursor++ = replacement;
+ ++ch;
+ ++invalid;
+ continue;
+ }
+
+ if (u > 0xffff) {
+ *cursor++ = 0xf0 | ((uchar) (u >> 18));
+ *cursor++ = 0x80 | (((uchar) (u >> 12)) & 0x3f);
+ } else {
+ *cursor++ = 0xe0 | (((uchar) (u >> 12)) & 0x3f);
+ }
+ *cursor++ = 0x80 | (((uchar) (u >> 6)) & 0x3f);
+ }
+ *cursor++ = 0x80 | ((uchar) (u&0x3f));
+ }
+ ++ch;
+ }
+
+ rstr.resize(cursor - (const uchar*)rstr.constData());
+ if (state) {
+ state->invalidChars += invalid;
+ state->flags |= QTextCodec::IgnoreHeader;
+ state->remainingChars = 0;
+ if (surrogate_high >= 0) {
+ state->remainingChars = 1;
+ state->state_data[0] = surrogate_high;
+ }
+ }
+ return rstr;
+}
+
+QString QUtf8::convertToUnicode(const char *chars, int len, QTextCodec::ConverterState *state)
+{
+ bool headerdone = false;
+ ushort replacement = QChar::ReplacementCharacter;
+ int need = 0;
+ int error = -1;
+ uint uc = 0;
+ uint min_uc = 0;
+ if (state) {
+ if (state->flags & QTextCodec::IgnoreHeader)
+ headerdone = true;
+ if (state->flags & QTextCodec::ConvertInvalidToNull)
+ replacement = QChar::Null;
+ need = state->remainingChars;
+ if (need) {
+ uc = state->state_data[0];
+ min_uc = state->state_data[1];
+ }
+ }
+ if (!headerdone && len > 3
+ && (uchar)chars[0] == 0xef && (uchar)chars[1] == 0xbb && (uchar)chars[2] == 0xbf) {
+ // starts with a byte order mark
+ chars += 3;
+ len -= 3;
+ headerdone = true;
+ }
+
+ QString result(need + len + 1, Qt::Uninitialized); // worst case
+ ushort *qch = (ushort *)result.unicode();
+ uchar ch;
+ int invalid = 0;
+
+ for (int i = 0; i < len; ++i) {
+ ch = chars[i];
+ if (need) {
+ if ((ch&0xc0) == 0x80) {
+ uc = (uc << 6) | (ch & 0x3f);
+ --need;
+ if (!need) {
+ // utf-8 bom composes into 0xfeff code point
+ bool nonCharacter;
+ if (!headerdone && uc == 0xfeff) {
+ // don't do anything, just skip the BOM
+ } else if (!(nonCharacter = isUnicodeNonCharacter(uc)) && uc > 0xffff && uc < 0x110000) {
+ // surrogate pair
+ Q_ASSERT((qch - (ushort*)result.unicode()) + 2 < result.length());
+ *qch++ = QChar::highSurrogate(uc);
+ *qch++ = QChar::lowSurrogate(uc);
+ } else if ((uc < min_uc) || (uc >= 0xd800 && uc <= 0xdfff) || nonCharacter || uc >= 0x110000) {
+ // error: overlong sequence, UTF16 surrogate or non-character
+ *qch++ = replacement;
+ ++invalid;
+ } else {
+ *qch++ = uc;
+ }
+ headerdone = true;
+ }
+ } else {
+ // error
+ i = error;
+ *qch++ = replacement;
+ ++invalid;
+ need = 0;
+ headerdone = true;
+ }
+ } else {
+ if (ch < 128) {
+ *qch++ = ushort(ch);
+ headerdone = true;
+ } else if ((ch & 0xe0) == 0xc0) {
+ uc = ch & 0x1f;
+ need = 1;
+ error = i;
+ min_uc = 0x80;
+ headerdone = true;
+ } else if ((ch & 0xf0) == 0xe0) {
+ uc = ch & 0x0f;
+ need = 2;
+ error = i;
+ min_uc = 0x800;
+ } else if ((ch&0xf8) == 0xf0) {
+ uc = ch & 0x07;
+ need = 3;
+ error = i;
+ min_uc = 0x10000;
+ headerdone = true;
+ } else {
+ // error
+ *qch++ = replacement;
+ ++invalid;
+ headerdone = true;
+ }
+ }
+ }
+ if (!state && need > 0) {
+ // unterminated UTF sequence
+ for (int i = error; i < len; ++i) {
+ *qch++ = replacement;
+ ++invalid;
+ }
+ }
+ result.truncate(qch - (ushort *)result.unicode());
+ if (state) {
+ state->invalidChars += invalid;
+ state->remainingChars = need;
+ if (headerdone)
+ state->flags |= QTextCodec::IgnoreHeader;
+ state->state_data[0] = need ? uc : 0;
+ state->state_data[1] = need ? min_uc : 0;
+ }
+ return result;
+}
+
+QByteArray QUtf16::convertFromUnicode(const QChar *uc, int len, QTextCodec::ConverterState *state, DataEndianness e)
+{
+ DataEndianness endian = e;
+ int length = 2*len;
+ if (!state || (!(state->flags & QTextCodec::IgnoreHeader))) {
+ length += 2;
+ }
+ if (e == DetectEndianness) {
+ endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? BigEndianness : LittleEndianness;
+ }
+
+ QByteArray d;
+ d.resize(length);
+ char *data = d.data();
+ if (!state || !(state->flags & QTextCodec::IgnoreHeader)) {
+ QChar bom(QChar::ByteOrderMark);
+ if (endian == BigEndianness) {
+ data[0] = bom.row();
+ data[1] = bom.cell();
+ } else {
+ data[0] = bom.cell();
+ data[1] = bom.row();
+ }
+ data += 2;
+ }
+ if (endian == BigEndianness) {
+ for (int i = 0; i < len; ++i) {
+ *(data++) = uc[i].row();
+ *(data++) = uc[i].cell();
+ }
+ } else {
+ for (int i = 0; i < len; ++i) {
+ *(data++) = uc[i].cell();
+ *(data++) = uc[i].row();
+ }
+ }
+
+ if (state) {
+ state->remainingChars = 0;
+ state->flags |= QTextCodec::IgnoreHeader;
+ }
+ return d;
+}
+
+QString QUtf16::convertToUnicode(const char *chars, int len, QTextCodec::ConverterState *state, DataEndianness e)
+{
+ DataEndianness endian = e;
+ bool half = false;
+ uchar buf = 0;
+ bool headerdone = false;
+ if (state) {
+ headerdone = state->flags & QTextCodec::IgnoreHeader;
+ if (endian == DetectEndianness)
+ endian = (DataEndianness)state->state_data[Endian];
+ if (state->remainingChars) {
+ half = true;
+ buf = state->state_data[Data];
+ }
+ }
+ if (headerdone && endian == DetectEndianness)
+ endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? BigEndianness : LittleEndianness;
+
+ QString result(len, Qt::Uninitialized); // worst case
+ QChar *qch = (QChar *)result.unicode();
+ while (len--) {
+ if (half) {
+ QChar ch;
+ if (endian == LittleEndianness) {
+ ch.setRow(*chars++);
+ ch.setCell(buf);
+ } else {
+ ch.setRow(buf);
+ ch.setCell(*chars++);
+ }
+ if (!headerdone) {
+ headerdone = true;
+ if (endian == DetectEndianness) {
+ if (ch == QChar::ByteOrderSwapped) {
+ endian = LittleEndianness;
+ } else if (ch == QChar::ByteOrderMark) {
+ endian = BigEndianness;
+ } else {
+ if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
+ endian = BigEndianness;
+ } else {
+ endian = LittleEndianness;
+ ch = QChar((ch.unicode() >> 8) | ((ch.unicode() & 0xff) << 8));
+ }
+ *qch++ = ch;
+ }
+ } else if (ch != QChar::ByteOrderMark) {
+ *qch++ = ch;
+ }
+ } else {
+ *qch++ = ch;
+ }
+ half = false;
+ } else {
+ buf = *chars++;
+ half = true;
+ }
+ }
+ result.truncate(qch - result.unicode());
+
+ if (state) {
+ if (headerdone)
+ state->flags |= QTextCodec::IgnoreHeader;
+ state->state_data[Endian] = endian;
+ if (half) {
+ state->remainingChars = 1;
+ state->state_data[Data] = buf;
+ } else {
+ state->remainingChars = 0;
+ state->state_data[Data] = 0;
+ }
+ }
+ return result;
+}
+
+QByteArray QUtf32::convertFromUnicode(const QChar *uc, int len, QTextCodec::ConverterState *state, DataEndianness e)
+{
+ DataEndianness endian = e;
+ int length = 4*len;
+ if (!state || (!(state->flags & QTextCodec::IgnoreHeader))) {
+ length += 4;
+ }
+ if (e == DetectEndianness) {
+ endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? BigEndianness : LittleEndianness;
+ }
+
+ QByteArray d(length, Qt::Uninitialized);
+ char *data = d.data();
+ if (!state || !(state->flags & QTextCodec::IgnoreHeader)) {
+ if (endian == BigEndianness) {
+ data[0] = 0;
+ data[1] = 0;
+ data[2] = (char)0xfe;
+ data[3] = (char)0xff;
+ } else {
+ data[0] = (char)0xff;
+ data[1] = (char)0xfe;
+ data[2] = 0;
+ data[3] = 0;
+ }
+ data += 4;
+ }
+ if (endian == BigEndianness) {
+ for (int i = 0; i < len; ++i) {
+ uint cp = uc[i].unicode();
+ if (uc[i].isHighSurrogate() && i < len - 1)
+ cp = QChar::surrogateToUcs4(cp, uc[++i].unicode());
+ *(data++) = cp >> 24;
+ *(data++) = (cp >> 16) & 0xff;
+ *(data++) = (cp >> 8) & 0xff;
+ *(data++) = cp & 0xff;
+ }
+ } else {
+ for (int i = 0; i < len; ++i) {
+ uint cp = uc[i].unicode();
+ if (uc[i].isHighSurrogate() && i < len - 1)
+ cp = QChar::surrogateToUcs4(cp, uc[++i].unicode());
+ *(data++) = cp & 0xff;
+ *(data++) = (cp >> 8) & 0xff;
+ *(data++) = (cp >> 16) & 0xff;
+ *(data++) = cp >> 24;
+ }
+ }
+
+ if (state) {
+ state->remainingChars = 0;
+ state->flags |= QTextCodec::IgnoreHeader;
+ }
+ return d;
+}
+
+QString QUtf32::convertToUnicode(const char *chars, int len, QTextCodec::ConverterState *state, DataEndianness e)
+{
+ DataEndianness endian = e;
+ uchar tuple[4];
+ int num = 0;
+ bool headerdone = false;
+ if (state) {
+ headerdone = state->flags & QTextCodec::IgnoreHeader;
+ if (endian == DetectEndianness) {
+ endian = (DataEndianness)state->state_data[Endian];
+ }
+ num = state->remainingChars;
+ memcpy(tuple, &state->state_data[Data], 4);
+ }
+ if (headerdone && endian == DetectEndianness)
+ endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? BigEndianness : LittleEndianness;
+
+ QString result;
+ result.resize((num + len) >> 2 << 1); // worst case
+ QChar *qch = (QChar *)result.unicode();
+
+ const char *end = chars + len;
+ while (chars < end) {
+ tuple[num++] = *chars++;
+ if (num == 4) {
+ if (!headerdone) {
+ if (endian == DetectEndianness) {
+ if (endian == DetectEndianness) {
+ if (tuple[0] == 0xff && tuple[1] == 0xfe && tuple[2] == 0 && tuple[3] == 0 && endian != BigEndianness) {
+ endian = LittleEndianness;
+ num = 0;
+ continue;
+ } else if (tuple[0] == 0 && tuple[1] == 0 && tuple[2] == 0xfe && tuple[3] == 0xff && endian != LittleEndianness) {
+ endian = BigEndianness;
+ num = 0;
+ continue;
+ } else if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
+ endian = BigEndianness;
+ } else {
+ endian = LittleEndianness;
+ }
+ }
+ } else if (((endian == BigEndianness) ? qFromBigEndian<quint32>(tuple) : qFromLittleEndian<quint32>(tuple)) == QChar::ByteOrderMark) {
+ num = 0;
+ continue;
+ }
+ }
+ uint code = (endian == BigEndianness) ? qFromBigEndian<quint32>(tuple) : qFromLittleEndian<quint32>(tuple);
+ if (code >= 0x10000) {
+ *qch++ = QChar::highSurrogate(code);
+ *qch++ = QChar::lowSurrogate(code);
+ } else {
+ *qch++ = code;
+ }
+ num = 0;
+ }
+ }
+ result.truncate(qch - result.unicode());
+
+ if (state) {
+ if (headerdone)
+ state->flags |= QTextCodec::IgnoreHeader;
+ state->state_data[Endian] = endian;
+ state->remainingChars = num;
+ memcpy(&state->state_data[Data], tuple, 4);
+ }
+ return result;
+}
+
+
+#ifndef QT_NO_TEXTCODEC
+
+QUtf8Codec::~QUtf8Codec()
+{
+}
+
+QByteArray QUtf8Codec::convertFromUnicode(const QChar *uc, int len, ConverterState *state) const
+{
+ return QUtf8::convertFromUnicode(uc, len, state);
+}
+
+void QUtf8Codec::convertToUnicode(QString *target, const char *chars, int len, ConverterState *state) const
+{
+ *target += QUtf8::convertToUnicode(chars, len, state);
+}
+
+QString QUtf8Codec::convertToUnicode(const char *chars, int len, ConverterState *state) const
+{
+ return QUtf8::convertToUnicode(chars, len, state);
+}
+
+QByteArray QUtf8Codec::name() const
+{
+ return "UTF-8";
+}
+
+int QUtf8Codec::mibEnum() const
+{
+ return 106;
+}
+
+QUtf16Codec::~QUtf16Codec()
+{
+}
+
+QByteArray QUtf16Codec::convertFromUnicode(const QChar *uc, int len, ConverterState *state) const
+{
+ return QUtf16::convertFromUnicode(uc, len, state, e);
+}
+
+QString QUtf16Codec::convertToUnicode(const char *chars, int len, ConverterState *state) const
+{
+ return QUtf16::convertToUnicode(chars, len, state, e);
+}
+
+int QUtf16Codec::mibEnum() const
+{
+ return 1015;
+}
+
+QByteArray QUtf16Codec::name() const
+{
+ return "UTF-16";
+}
+
+QList<QByteArray> QUtf16Codec::aliases() const
+{
+ return QList<QByteArray>();
+}
+
+int QUtf16BECodec::mibEnum() const
+{
+ return 1013;
+}
+
+QByteArray QUtf16BECodec::name() const
+{
+ return "UTF-16BE";
+}
+
+QList<QByteArray> QUtf16BECodec::aliases() const
+{
+ QList<QByteArray> list;
+ return list;
+}
+
+int QUtf16LECodec::mibEnum() const
+{
+ return 1014;
+}
+
+QByteArray QUtf16LECodec::name() const
+{
+ return "UTF-16LE";
+}
+
+QList<QByteArray> QUtf16LECodec::aliases() const
+{
+ QList<QByteArray> list;
+ return list;
+}
+
+QUtf32Codec::~QUtf32Codec()
+{
+}
+
+QByteArray QUtf32Codec::convertFromUnicode(const QChar *uc, int len, ConverterState *state) const
+{
+ return QUtf32::convertFromUnicode(uc, len, state, e);
+}
+
+QString QUtf32Codec::convertToUnicode(const char *chars, int len, ConverterState *state) const
+{
+ return QUtf32::convertToUnicode(chars, len, state, e);
+}
+
+int QUtf32Codec::mibEnum() const
+{
+ return 1017;
+}
+
+QByteArray QUtf32Codec::name() const
+{
+ return "UTF-32";
+}
+
+QList<QByteArray> QUtf32Codec::aliases() const
+{
+ QList<QByteArray> list;
+ return list;
+}
+
+int QUtf32BECodec::mibEnum() const
+{
+ return 1018;
+}
+
+QByteArray QUtf32BECodec::name() const
+{
+ return "UTF-32BE";
+}
+
+QList<QByteArray> QUtf32BECodec::aliases() const
+{
+ QList<QByteArray> list;
+ return list;
+}
+
+int QUtf32LECodec::mibEnum() const
+{
+ return 1019;
+}
+
+QByteArray QUtf32LECodec::name() const
+{
+ return "UTF-32LE";
+}
+
+QList<QByteArray> QUtf32LECodec::aliases() const
+{
+ QList<QByteArray> list;
+ return list;
+}
+
+#endif //QT_NO_TEXTCODEC
+
+QT_END_NAMESPACE
diff --git a/src/corelib/codecs/qutfcodec_p.h b/src/corelib/codecs/qutfcodec_p.h
new file mode 100644
index 0000000000..89d27909ae
--- /dev/null
+++ b/src/corelib/codecs/qutfcodec_p.h
@@ -0,0 +1,170 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QUTFCODEC_P_H
+#define QUTFCODEC_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "QtCore/qtextcodec.h"
+#include "private/qtextcodec_p.h"
+
+QT_BEGIN_NAMESPACE
+
+enum DataEndianness
+{
+ DetectEndianness,
+ BigEndianness,
+ LittleEndianness
+};
+
+struct QUtf8
+{
+ static QString convertToUnicode(const char *, int, QTextCodec::ConverterState *);
+ static QByteArray convertFromUnicode(const QChar *, int, QTextCodec::ConverterState *);
+};
+
+struct QUtf16
+{
+ static QString convertToUnicode(const char *, int, QTextCodec::ConverterState *, DataEndianness = DetectEndianness);
+ static QByteArray convertFromUnicode(const QChar *, int, QTextCodec::ConverterState *, DataEndianness = DetectEndianness);
+};
+
+struct QUtf32
+{
+ static QString convertToUnicode(const char *, int, QTextCodec::ConverterState *, DataEndianness = DetectEndianness);
+ static QByteArray convertFromUnicode(const QChar *, int, QTextCodec::ConverterState *, DataEndianness = DetectEndianness);
+};
+
+#ifndef QT_NO_TEXTCODEC
+
+class QUtf8Codec : public QTextCodec {
+public:
+ ~QUtf8Codec();
+
+ QByteArray name() const;
+ int mibEnum() const;
+
+ QString convertToUnicode(const char *, int, ConverterState *) const;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+ void convertToUnicode(QString *target, const char *, int, ConverterState *) const;
+};
+
+class QUtf16Codec : public QTextCodec {
+protected:
+public:
+ QUtf16Codec() { e = DetectEndianness; }
+ ~QUtf16Codec();
+
+ QByteArray name() const;
+ QList<QByteArray> aliases() const;
+ int mibEnum() const;
+
+ QString convertToUnicode(const char *, int, ConverterState *) const;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+
+protected:
+ DataEndianness e;
+};
+
+class QUtf16BECodec : public QUtf16Codec {
+public:
+ QUtf16BECodec() : QUtf16Codec() { e = BigEndianness; }
+ QByteArray name() const;
+ QList<QByteArray> aliases() const;
+ int mibEnum() const;
+};
+
+class QUtf16LECodec : public QUtf16Codec {
+public:
+ QUtf16LECodec() : QUtf16Codec() { e = LittleEndianness; }
+ QByteArray name() const;
+ QList<QByteArray> aliases() const;
+ int mibEnum() const;
+};
+
+class QUtf32Codec : public QTextCodec {
+public:
+ QUtf32Codec() { e = DetectEndianness; }
+ ~QUtf32Codec();
+
+ QByteArray name() const;
+ QList<QByteArray> aliases() const;
+ int mibEnum() const;
+
+ QString convertToUnicode(const char *, int, ConverterState *) const;
+ QByteArray convertFromUnicode(const QChar *, int, ConverterState *) const;
+
+protected:
+ DataEndianness e;
+};
+
+class QUtf32BECodec : public QUtf32Codec {
+public:
+ QUtf32BECodec() : QUtf32Codec() { e = BigEndianness; }
+ QByteArray name() const;
+ QList<QByteArray> aliases() const;
+ int mibEnum() const;
+};
+
+class QUtf32LECodec : public QUtf32Codec {
+public:
+ QUtf32LECodec() : QUtf32Codec() { e = LittleEndianness; }
+ QByteArray name() const;
+ QList<QByteArray> aliases() const;
+ int mibEnum() const;
+};
+
+
+#endif // QT_NO_TEXTCODEC
+
+QT_END_NAMESPACE
+
+#endif // QUTFCODEC_P_H