24 #include "kentities.c"
31 #include <QtCore/QDir>
32 #include <QtCore/QRegExp>
33 #include <QtCore/QCharRef>
34 #include <QtCore/QMutableStringListIterator>
35 #include <QtCore/QTextCodec>
155 I18N_NOOP2(
"@item Text character set",
"Western European")
"\0"
161 I18N_NOOP2(
"@item Text character set",
"Central European")
"\0"
164 I18N_NOOP2(
"@item Text character set",
"Baltic")
"\0"
167 I18N_NOOP2(
"@item Text character set",
"South-Eastern Europe")
"\0"
170 I18N_NOOP2(
"@item Text character set",
"Turkish")
"\0"
173 I18N_NOOP2(
"@item Text character set",
"Cyrillic")
"\0"
179 I18N_NOOP2(
"@item Text character set",
"Chinese Traditional")
"\0"
182 I18N_NOOP2(
"@item Text character set",
"Chinese Simplified")
"\0"
186 I18N_NOOP2(
"@item Text character set",
"Korean")
"\0"
188 I18N_NOOP2(
"@item Text character set",
"Japanese")
"\0"
192 I18N_NOOP2(
"@item Text character set",
"Greek")
"\0"
195 I18N_NOOP2(
"@item Text character set",
"Arabic")
"\0"
198 I18N_NOOP2(
"@item Text character set",
"Hebrew")
"\0"
203 I18N_NOOP2(
"@item Text character set",
"Thai")
"\0"
206 I18N_NOOP2(
"@item Text character set",
"Unicode")
"\0"
212 I18N_NOOP2(
"@item Text character set",
"Northern Saami")
"\0"
214 I18N_NOOP2(
"@item Text character set",
"Other")
"\0"
220 0, 11, 28, 11, 40, 11, 52, 11,
221 60, 11, 67, 78, 95, 78, 106, 117,
222 124, 117, 136, 148, 169, 78, 177, 185,
223 193, 117, 201, 208, 217, 208, 228, 208,
224 236, 208, 243, 208, 250, 255, 275, 255,
225 286, 294, 313, 294, 317, 294, 324, 331,
226 338, 343, 352, 343, 357, 343, 364, 375,
227 381, 375, 389, 400, 407, 400, 415, 426,
228 433, 426, 446, 426, 454, 185, 465, 472,
229 477, 472, 489, 495, 503, 495, 510, 495,
230 515, 495, 520, 495, 536, 545, 560, 573,
231 579, 573, 586, 573, -1
342 "unicode-1-1-utf-7\0"
395 0, 11, 18, 11, 30, 39, 50, 39,
396 58, 39, 64, 82, 88, 93, 109, 93,
397 120, 135, 143, 135, 158, 164, 168, 164,
398 175, 164, 189, 196, 201, 208, 214, 221,
399 227, 221, 243, 221, 259, 221, 275, 221,
400 291, 221, 307, 221, 323, 221, 339, 349,
401 354, 349, 349, 349, 364, 376, 381, 392,
402 399, 410, 417, 392, 429, 410, 441, 450,
403 462, 474, 486, 498, 505, 498, 516, 498,
404 523, 208, 538, 208, 553, 450, 563, 450,
405 573, 450, 577, 364, -1
445 0, 7, 18, 25, 36, 18, 43, 50,
454 for (
int i = 0; indices[i] != -1; i += 2)
455 if (qstrcmp(start + indices[i], entry) == 0)
456 return start + indices[i + 1];
461 class KCharsetsPrivate
467 codecForNameDict.reserve( 43 );
470 QHash<QByteArray,QTextCodec*> codecForNameDict;
474 QList<QStringList> encodingsByScript;
480 :d(new KCharsetsPrivate(this))
491 QChar res = QChar::Null;
497 if(str[pos] == QLatin1Char(
'&')) pos++;
500 if (str[pos] == QLatin1Char(
'#') && str.length()-pos > 1) {
503 if (str[pos] == QLatin1Char(
'x') || str[pos] == QLatin1Char(
'X')) {
506 const QString tmp( str.mid( pos ) );
507 res = tmp.toInt(&ok, 16);
510 const QString tmp( str.mid( pos ) );
511 res = tmp.toInt(&ok, 10);
519 const QByteArray raw ( str.toLatin1() );
520 const entity *e = kde_findEntity( raw, raw.length() );
529 return QChar(e->code);
541 if( res != QChar::Null )
return res;
551 ent.sprintf(
"�x%x;", ch.unicode());
558 const QChar *p = text.unicode();
559 const QChar *end = p + text.length();
560 const QChar *ampersand = 0;
561 bool scanForSemicolon =
false;
563 for ( ; p < end; ++p ) {
566 if ( ch == QLatin1Char(
'&') ) {
568 scanForSemicolon =
true;
572 if ( ch != QLatin1Char(
';') || scanForSemicolon ==
false )
577 scanForSemicolon =
false;
579 const QChar *entityBegin = ampersand + 1;
581 const uint entityLength = p - entityBegin;
582 if ( entityLength == 0 )
586 if ( entityValue.isNull() )
589 const uint ampersandPos = ampersand - text.unicode();
591 text[ (int)ampersandPos ] = entityValue;
592 text.remove( ampersandPos + 1, entityLength + 1 );
593 p = text.unicode() + ampersandPos;
594 end = text.unicode() + text.length();
610 #ifndef KDE_NO_DEPRECATED
615 encoding.toUtf8().constData() );
617 return i18nc(
"@item Text character set", lang );
619 return i18nc(
"@item Text character set",
"Other" );
629 return i18nc(
"@item %1 character set, %2 encoding",
"%1 ( %2 )",
630 i18nc(
"@item Text character set", lang ), encoding );
632 return i18nc(
"@item",
"Other encoding (%1)", encoding );
637 const int left = descriptiveName.lastIndexOf( QLatin1Char(
'(') );
640 return descriptiveName.trimmed();
642 QString name(descriptiveName.mid(left+1));
644 const int right = name.lastIndexOf( QLatin1Char(
')') );
649 return name.left(right).trimmed();
658 encodings.append(
i18nc(
"@item Text encoding: %1 character set, %2 encoding",
"%1 ( %2 )",
659 description, name ) );
667 if (!d->encodingsByScript.isEmpty())
668 return d->encodingsByScript;
674 for (i=0; i<d->encodingsByScript.size(); ++i) {
675 if (d->encodingsByScript.at(i).at(0) == description) {
676 d->encodingsByScript[i].append(name);
681 if (i==d->encodingsByScript.size()) {
682 d->encodingsByScript.append(
QStringList() << description << name);
686 return d->encodingsByScript;
691 if ( n == QLatin1String(
"gb2312") || n == QLatin1String(
"gbk") )
693 const QByteArray name( n.toLatin1() );
694 QTextCodec* codec = codecForNameOrNull( name );
703 if (n == QLatin1String(
"gb2312") || n == QLatin1String(
"gbk")) {
707 const QByteArray name( n.toLatin1() );
708 QTextCodec* codec = codecForNameOrNull( name );
721 QTextCodec *KCharsets::codecForNameOrNull(
const QByteArray& n )
const
723 QTextCodec* codec = 0;
727 const QByteArray
locale =
"->locale<-";
728 if ( d->codecForNameDict.contains( locale ) )
729 return d->codecForNameDict.value( locale );
731 d->codecForNameDict.insert(
"->locale<-", codec);
735 else if ( d->codecForNameDict.contains( n ) ) {
736 return d->codecForNameDict.value( n );
743 d->codecForNameDict.insert( n, codec );
749 QByteArray name = n.toLower();
750 bool changed =
false;
751 if (name.endsWith(
"_charset")) {
755 if ( name.startsWith(
"x-" ) ) {
760 if (name.isEmpty()) {
769 d->codecForNameDict.insert( n, codec );
780 codec = QTextCodec::codecForName(cname);
784 d->codecForNameDict.insert( n, codec );
792 if (!cname.isEmpty()) {
795 d->codecForNameDict.insert( n, codec );