Changeset 769 for trunk/src/corelib/codecs
- Timestamp:
- Aug 2, 2010, 9:27:30 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
-
. (modified) (1 prop)
-
src/corelib/codecs/qiconvcodec.cpp (modified) (9 diffs)
-
src/corelib/codecs/qsimplecodec.cpp (modified) (1 diff)
-
src/corelib/codecs/qtextcodec.cpp (modified) (13 diffs)
-
src/corelib/codecs/qtextcodec.h (modified) (2 diffs)
-
src/corelib/codecs/qutfcodec.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.6.3 (added) merged: 768 /branches/vendor/nokia/qt/current merged: 767 /branches/vendor/nokia/qt/4.6.2 removed
- Property svn:mergeinfo changed
-
trunk/src/corelib/codecs/qiconvcodec.cpp
r651 r769 169 169 { 170 170 if (utf16Codec == reinterpret_cast<QTextCodec *>(~0)) 171 return QString::from Ascii(chars, len);171 return QString::from(chars, len); 172 172 173 173 int invalidCount = 0; … … 208 208 if (!reported++) { 209 209 fprintf(stderr, 210 "QIconvCodec::convertToUnicode: using ASCIIfor conversion, iconv_open failed\n");211 } 212 return QString::from Ascii(chars, len);210 "QIconvCodec::convertToUnicode: using for conversion, iconv_open failed\n"); 211 } 212 return QString::from(chars, len); 213 213 } 214 214 … … 274 274 // some other error 275 275 // note, cannot use qWarning() since we are implementing the codecForLocale :) 276 perror("QIconvCodec::convertToUnicode: using ASCIIfor conversion, iconv failed");276 perror("QIconvCodec::convertToUnicode: using for conversion, iconv failed"); 277 277 278 278 if (!convState) { … … 281 281 } 282 282 283 return QString::from Ascii(chars, len);283 return QString::from(chars, len); 284 284 } 285 285 } while (inBytesLeft != 0); … … 299 299 300 300 Q_GLOBAL_STATIC(QThreadStorage<QIconvCodec::IconvState *>, fromUnicodeState) 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 301 327 302 328 QByteArray QIconvCodec::convertFromUnicode(const QChar *uc, int len, ConverterState *convState) const … … 326 352 if (!state) { 327 353 state = new IconvState(QIconvCodec::createIconv_t(0, UTF16)); 328 if (state->cd != reinterpret_cast<iconv_t>(-1)) { 329 size_t outBytesLeft = len + 3; // +3 for the BOM 330 QByteArray ba(outBytesLeft, Qt::Uninitialized); 331 outBytes = ba.data(); 332 333 #if !defined(NO_BOM) 334 // give iconv() a BOM 335 QChar bom[] = { QChar(QChar::ByteOrderMark) }; 336 inBytes = reinterpret_cast<char *>(bom); 337 inBytesLeft = sizeof(bom); 338 if (iconv(state->cd, inBytesPtr, &inBytesLeft, &outBytes, &outBytesLeft) == (size_t) -1) { 339 perror("QIconvCodec::convertFromUnicode: using ASCII for conversion, iconv failed for BOM"); 354 if (state->cd == reinterpret_cast<iconv_t>(-1)) { 355 if (!setByteOrder(state->cd)) { 356 perror("QIconvCodec::convertFromUnicode: using Latin-1 for conversion, iconv failed for BOM"); 340 357 341 358 iconv_close(state->cd); 342 359 state->cd = reinterpret_cast<iconv_t>(-1); 343 360 344 return QString(uc, len).toAscii(); 345 } 346 #endif // NO_BOM 361 return QString(uc, len).toLatin1(); 362 } 347 363 } 348 364 } … … 351 367 if (!reported++) { 352 368 fprintf(stderr, 353 "QIconvCodec::convertFromUnicode: using ASCIIfor conversion, iconv_open failed\n");354 } 355 return QString(uc, len).to Ascii();369 "QIconvCodec::convertFromUnicode: using for conversion, iconv_open failed\n"); 370 } 371 return QString(uc, len).to(); 356 372 } 357 373 … … 410 426 { 411 427 // note, cannot use qWarning() since we are implementing the codecForLocale :) 412 perror("QIconvCodec::convertFromUnicode: using ASCIIfor conversion, iconv failed");428 perror("QIconvCodec::convertFromUnicode: using for conversion, iconv failed"); 413 429 414 430 // reset to initial state 415 431 iconv(state->cd, 0, &inBytesLeft, 0, &outBytesLeft); 416 432 417 return QString(uc, len).to Ascii();433 return QString(uc, len).to(); 418 434 } 419 435 } … … 423 439 // reset to initial state 424 440 iconv(state->cd, 0, &inBytesLeft, 0, &outBytesLeft); 441 425 442 426 443 ba.resize(ba.size() - outBytesLeft); -
trunk/src/corelib/codecs/qsimplecodec.cpp
r651 r769 682 682 const QChar* ucp = in; 683 683 unsigned char* rp = (unsigned char *)r.data(); 684 const unsigned char* rmp = (const unsigned char *)reverseMap-> data();684 const unsigned char* rmp = (const unsigned char *)reverseMap->ata(); 685 685 int rmsize = (int) reverseMap->size(); 686 686 while(i--) -
trunk/src/corelib/codecs/qtextcodec.cpp
r651 r769 86 86 #endif // QT_NO_CODECS 87 87 #include "qlocale.h" 88 #include "private/qmutexpool_p.h" 88 #include "qmutex.h" 89 #include "qhash.h" 89 90 90 91 #include <stdlib.h> … … 108 109 (QTextCodecFactoryInterface_iid, QLatin1String("/codecs"))) 109 110 #endif 111 110 112 111 113 static char qtolower(register char c) … … 179 181 180 182 static QList<QTextCodec*> *all = 0; 183 181 184 #ifdef Q_DEBUG_TEXTCODEC 182 185 static bool destroying_is_ok = false; … … 221 224 222 225 Q_GLOBAL_STATIC(QTextCodecCleanup, createQTextCodecCleanup) 226 227 228 229 230 231 232 233 234 235 236 237 238 223 239 224 240 #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) … … 906 922 } 907 923 908 924 #ifndef QT_NO_THREAD 925 Q_GLOBAL_STATIC_WITH_ARGS(QMutex, textCodecsMutex, (QMutex::Recursive)); 926 #endif 927 928 // textCodecsMutex need to be locked to enter this function 909 929 static void setup() 910 930 { 911 #ifndef QT_NO_THREAD912 QMutexLocker locker(QMutexPool::globalInstanceGet(&all));913 #endif914 915 931 if (all) 916 932 return; 933 934 935 936 937 938 939 940 917 941 918 942 #ifdef Q_DEBUG_TEXTCODEC … … 1164 1188 1165 1189 /*! 1166 \nonreentrant1167 1168 1190 Constructs a QTextCodec, and gives it the highest precedence. The 1169 1191 QTextCodec should always be constructed on the heap (i.e. with \c … … 1173 1195 QTextCodec::QTextCodec() 1174 1196 { 1197 1198 1199 1175 1200 setup(); 1176 1201 all->prepend(this); … … 1190 1215 qWarning("QTextCodec::~QTextCodec: Called by application"); 1191 1216 #endif 1192 if (all) 1217 if (all) { 1218 #ifndef QT_NO_THREAD 1219 QMutexLocker locker(textCodecsMutex()); 1220 #endif 1193 1221 all->removeAll(this); 1222 1223 1194 1224 } 1195 1225 … … 1212 1242 return 0; 1213 1243 1244 1245 1246 1214 1247 setup(); 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1215 1260 1216 1261 for (int i = 0; i < all->size(); ++i) { 1217 1262 QTextCodec *cursor = all->at(i); 1218 if (nameMatch(cursor->name(), name)) 1263 if (nameMatch(cursor->name(), name)) { 1264 cache.insert(name, cursor); 1219 1265 return cursor; 1266 1220 1267 QList<QByteArray> aliases = cursor->aliases(); 1221 for (int i = 0; i < aliases.size(); ++i) 1222 if (nameMatch(aliases.at(i), name)) 1268 for (int y = 0; y < aliases.size(); ++y) 1269 if (nameMatch(aliases.at(y), name)) { 1270 cache.insert(name, cursor); 1223 1271 return cursor; 1224 } 1225 1226 return createForName(name); 1272 } 1273 } 1274 1275 codec = createForName(name); 1276 if (codec) 1277 cache.insert(name, codec); 1278 return codec; 1227 1279 } 1228 1280 … … 1234 1286 QTextCodec* QTextCodec::codecForMib(int mib) 1235 1287 { 1288 1289 1290 1236 1291 setup(); 1237 1292 1238 // Qt 3 used 1000 (mib for UCS2) as its identifier for the utf16 codec. Map 1239 // this correctly for compatibility. 1240 if (mib == 1000) 1241 mib = 1015; 1293 if (!validCodecs()) 1294 return 0; 1295 1296 static QHash <int, QTextCodec *> cache; 1297 if (clearCaches & 0x2) { 1298 cache.clear(); 1299 clearCaches &= ~0x2; 1300 } 1301 QTextCodec *codec = cache.value(mib); 1302 if (codec) 1303 return codec; 1242 1304 1243 1305 QList<QTextCodec*>::ConstIterator i; 1244 1306 for (int i = 0; i < all->size(); ++i) { 1245 1307 QTextCodec *cursor = all->at(i); 1246 if (cursor->mibEnum() == mib) 1308 if (cursor->mibEnum() == mib) { 1309 cache.insert(mib, cursor); 1247 1310 return cursor; 1248 } 1249 1250 return createForMib(mib); 1311 } 1312 } 1313 1314 codec = createForMib(mib); 1315 1316 // Qt 3 used 1000 (mib for UCS2) as its identifier for the utf16 codec. Map 1317 // this correctly for compatibility. 1318 if (!codec && mib == 1000) 1319 return codecForMib(1015); 1320 1321 if (codec) 1322 cache.insert(mib, codec); 1323 return codec; 1251 1324 } 1252 1325 … … 1262 1335 QList<QByteArray> QTextCodec::availableCodecs() 1263 1336 { 1337 1338 1339 1264 1340 setup(); 1265 1341 1266 1342 QList<QByteArray> codecs; 1343 1344 1345 1346 1267 1347 for (int i = 0; i < all->size(); ++i) { 1268 1348 codecs += all->at(i)->name(); 1269 1349 codecs += all->at(i)->aliases(); 1270 1350 } 1351 1352 1353 1354 1355 1271 1356 #ifndef QT_NO_TEXTCODECPLUGIN 1272 1357 QFactoryLoader *l = loader(); … … 1292 1377 QList<int> QTextCodec::availableMibs() 1293 1378 { 1379 1380 1381 1294 1382 setup(); 1295 1383 1296 1384 QList<int> codecs; 1385 1386 1387 1388 1297 1389 for (int i = 0; i < all->size(); ++i) 1298 1390 codecs += all->at(i)->mibEnum(); 1391 1392 1393 1394 1395 1299 1396 #ifndef QT_NO_TEXTCODECPLUGIN 1300 1397 QFactoryLoader *l = loader(); … … 1341 1438 QTextCodec* QTextCodec::codecForLocale() 1342 1439 { 1440 1441 1442 1343 1443 if (localeMapper) 1344 1444 return localeMapper; 1345 1445 1446 1447 1448 1346 1449 setup(); 1347 1450 -
trunk/src/corelib/codecs/qtextcodec.h
r651 r769 146 146 friend class QTextCodecCleanup; 147 147 static QTextCodec *cftr; 148 148 149 }; 149 150 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextCodec::ConversionFlags) 150 151 151 inline QTextCodec* QTextCodec::codecForTr() { return cftr; }152 ; } 152 153 inline void QTextCodec::setCodecForTr(QTextCodec *c) { cftr = c; } 153 inline QTextCodec* QTextCodec::codecForCStrings() { return QString::codecForCStrings; }154 inline QTextCodec* QTextCodec::codecForCStrings() { return ; } 154 155 inline void QTextCodec::setCodecForCStrings(QTextCodec *c) { QString::codecForCStrings = c; } 155 156 … … 171 172 friend class QXmlStreamWriter; 172 173 friend class QXmlStreamWriterPrivate; 174 173 175 friend class QCoreXmlStreamWriter; 174 176 friend class QCoreXmlStreamWriterPrivate; 177 175 178 }; 176 179 -
trunk/src/corelib/codecs/qutfcodec.cpp
r651 r769 327 327 } 328 328 if (!headerdone) { 329 329 330 if (endian == DetectEndianness) { 330 if (ch == QChar::ByteOrderSwapped && endian != BigEndianness) {331 if (ch == QChar::ByteOrderSwapped) { 331 332 endian = LittleEndianness; 332 } else if (ch == QChar::ByteOrderMark && endian != LittleEndianness) { 333 // ignore BOM 333 } else if (ch == QChar::ByteOrderMark) { 334 334 endian = BigEndianness; 335 335 } else { … … 345 345 *qch++ = ch; 346 346 } 347 headerdone = true;348 347 } else { 349 348 *qch++ = ch;
Note:
See TracChangeset
for help on using the changeset viewer.
