Changeset 17335 in webkit
- Timestamp:
- Oct 26, 2006 12:06:07 PM (17 years ago)
- Location:
- S60/branches/3.1m/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
S60/branches/3.1m/WebCore/ChangeLog
r16851 r17335 1 2006-10-25 raalexan <rasvan.alexandrescu@nokia.com> 2 3 Reviewed by zalan. 4 DESC: fix brake in chineese variant for google search 5 http://bugs.webkit.org/show_bug.cgi?id=11414 6 7 * kwq/KWQTextCodec.cpp: 8 (KWQTextDecoder::fromUnicode): 9 1 10 2006-10-05 rathnasa <sornalatha.rathnasamy@nokia.com> 2 11 -
S60/branches/3.1m/WebCore/kwq/KWQTextCodec.cpp
r14549 r17335 46 46 friend class QTextCodec; 47 47 public: 48 KWQTextDecoder(TUint aEnc) : iEncoding(aEnc) 49 ~KWQTextDecoder() 48 KWQTextDecoder(TUint aEnc) : iEncoding(aEnc) {} 49 ~KWQTextDecoder() {} 50 50 51 51 QString toUnicode(const char *chs, int len, bool flush); 52 52 QCString fromUnicode(const QString &); 53 53 bool IsConversionSupportedL(); 54 54 QString windows125xToUnicode( const char *chs, int len ); 55 55 56 56 private: … … 59 59 QString convertLatin1(const unsigned char *chs, int len); 60 60 static CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* iArrayOfCharacterSetsAvailable; 61 TUint 61 TUint iEncoding; 62 62 }; 63 63 … … 150 150 } 151 151 } 152 153 152 if( enc == 0 ) 153 enc = BrDefaultEnc; 154 154 155 155 return new QTextCodec( enc, flags ); … … 189 189 QTextCodec *QTextCodec::codecForLocale() 190 190 { 191 192 191 // FIXME NOKIA: how to get the system encoding in Symbian OS? 192 // only UTF8 used here 193 193 return new QTextCodec( KCharacterSetIdentifierIso88591 ); 194 194 } … … 203 203 default: 204 204 return '\\'; 205 205 } 206 206 } 207 207 … … 226 226 QCString QTextCodec::fromUnicode(const QString &qcs) const 227 227 { 228 228 return KWQTextDecoder( iEncoding ).fromUnicode( qcs ); 229 229 } 230 230 … … 317 317 // make sure the converter is available 318 318 319 320 321 322 323 319 int bomLength = 0; 320 TUint encoding = iEncoding; 321 CCnvCharacterSetConverter::TEndianness endianness = CCnvCharacterSetConverter::ELittleEndian; 322 323 if (len > 2 && chs[0] == FF && chs[1] == FE) { 324 324 encoding = KCharacterSetIdentifierUnicodeLittle; 325 325 bomLength = 2; 326 326 } else if (len > 2 && chs[0] == FE && chs[1] == FF) { 327 327 encoding = KCharacterSetIdentifierUnicodeBig; 328 328 endianness = CCnvCharacterSetConverter::EBigEndian; 329 329 bomLength = 2; 330 330 } else if (len > 3 && chs[0] == EF && chs[1] == BB && chs[2] == BF) { … … 334 334 335 335 if (!IsConversionSupportedL()) 336 337 338 336 { 337 iEncoding = KCharacterSetIdentifierIso88591; 338 } 339 339 340 340 // check if it really looks like valid utf-8 … … 349 349 if (iEncoding == KCharacterSetIdentifierIso88591) 350 350 return convertLatin1(reinterpret_cast<const unsigned char *>(chs), len); 351 352 353 354 355 356 357 358 359 351 else if(iEncoding == KCharacterSetIdentifierWindow1250 || 352 iEncoding == KCharacterSetIdentifierWindow1251 || 353 iEncoding == KCharacterSetIdentifierWindow1253 || 354 iEncoding == KCharacterSetIdentifierWindow1256 || 355 iEncoding == KCharacterSetIdentifierWindow1257 356 ) // work around for Symbian converter hanging when converting windows-125x charset 357 { 358 return windows125xToUnicode( chs, len ); 359 } 360 360 361 361 CCnvCharacterSetConverter* charConv = KWQGlobalServices::InstanceL()->CharConv(); … … 368 368 TBuf16<32> outBuf; 369 369 370 371 TPtrC8 370 len = len - bomLength ; 371 TPtrC8 inBuf( (const TUint8*)chs + bomLength, len ); 372 372 TInt state=CCnvCharacterSetConverter::KStateDefault; 373 373 … … 391 391 // copy result to out buffer 392 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 393 if(ret == -1 ) 394 { 395 // if there are no sifficient character to be converted to unicode, 396 // just append the rest to the characters to the result string. 397 result.append( (char *)inBuf.Ptr(), inBuf.Length() ); 398 } 399 else 400 { 401 // ### FIXME NOKIA: is it correct to remove the replacement 0xFFFD chars here? 402 // Maybe we need to replace it with space character 403 404 TPtr outPtr( 0, 0 ); 405 406 // there is some illegal/unconvertible chars 407 // try to create a buffer with all 0xFFFD chars trimmed 408 if (rep != 0 && rIndx < tmpBuf.Length() ) 409 { 410 TInt i=rIndx; 411 // first copy the part of buffer before the first 0xFFFD char 412 outBuf.Append(tmpBuf.Left(i++)); 413 rep--; 414 // search for more occurance of 0xFFFD chars 415 // and append valid chars before the last 0xFFFD char 416 // if there is only one 0xFFFD char, wouldn't enter the loop 417 for( ; rep && i<tmpBuf.Length(); i++ ) 418 { 419 if( tmpBuf[i] != 0xFFFD ) 420 outBuf.Append( tmpBuf[i] ); 421 else 422 rep--; 423 } 424 // append the chars after last 0xFFFD char 425 outBuf.Append(tmpBuf.Right(tmpBuf.Length() - i)); 426 outPtr.Set( (TUint16*)outBuf.Ptr(), outBuf.Length(), outBuf.Length() ); 427 outBuf.Zero(); 428 429 } 430 else outPtr.Set( (TUint16*)tmpBuf.Ptr(), tmpBuf.Length(), tmpBuf.Length() ); 431 432 // append the buffers to final result, will reincrease the size in needed 433 result.append( (const QChar*)(outPtr.Ptr()), outPtr.Length() ); 434 } 435 435 436 436 if( ret == 0 || ret == -1 ) break; … … 464 464 465 465 // guess the size of out buffer, try to minimize reallocation 466 HBufC8* outBuf = HBufC8::NewMaxL( str.length() * 2 + 1 ); 466 // the last added 1 is for the ptr which is zeroed later 467 HBufC8* outBuf = HBufC8::NewMaxL( str.length() * 2 + 1 + 1 ); 467 468 TPtr8 ptr( outBuf->Des() ); 468 469 ptr.SetLength( 0 ); … … 504 505 QString KWQTextDecoder::windows125xToUnicode( const char *chs, int len ) 505 506 { 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 507 QString out; 508 const unsigned short* cnvTable = 0; 509 switch( iEncoding ) { 510 case KCharacterSetIdentifierWindow1250: cnvTable = win1250toUnicode; break; 511 case KCharacterSetIdentifierWindow1251: cnvTable = win1251toUnicode; break; 512 case KCharacterSetIdentifierWindow1253: cnvTable = win1253toUnicode; break; 513 case KCharacterSetIdentifierWindow1256: cnvTable = win1256toUnicode; break; 514 case KCharacterSetIdentifierWindow1257: cnvTable = win1257toUnicode; break; 515 default: return out; 516 } 517 518 OOM_PRE_CHECK( len*2, len*2, "KWQTextDecoder::toUnicode" ); 519 out.reserve( len * 2/3 ); 520 const char* p = chs; 521 const char* top = chs + len; 522 while(p<top) { 523 const unsigned char ch = *p++; 524 out.append( ch < 0x80 ? QChar(ch) : QChar(cnvTable[ch-0x80]) ); 525 } 526 OOM_POST_CHECK_FAILED(return out;) 527 return out; 527 528 } 528 529
Note: See TracChangeset
for help on using the changeset viewer.