Changeset 17335 in webkit


Ignore:
Timestamp:
Oct 26, 2006 12:06:07 PM (17 years ago)
Author:
zbujtas
Message:

2006-10-25 raalexan <rasvan.alexandrescu@nokia.com>

Reviewed by zalan.
DESC: fix brake in chineese variant for google search
http://bugs.webkit.org/show_bug.cgi?id=11414


  • kwq/KWQTextCodec.cpp: (KWQTextDecoder::fromUnicode):
Location:
S60/branches/3.1m/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • S60/branches/3.1m/WebCore/ChangeLog

    r16851 r17335  
     12006-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
    1102006-10-05  rathnasa  <sornalatha.rathnasamy@nokia.com>
    211
  • S60/branches/3.1m/WebCore/kwq/KWQTextCodec.cpp

    r14549 r17335  
    4646friend class QTextCodec;
    4747public:
    48     KWQTextDecoder(TUint aEnc) : iEncoding(aEnc)        {}
    49     ~KWQTextDecoder()                                                           {}
     48    KWQTextDecoder(TUint aEnc) : iEncoding(aEnc)  {}
     49    ~KWQTextDecoder()                 {}
    5050
    5151    QString toUnicode(const char *chs, int len, bool flush);
    5252    QCString fromUnicode(const QString &);
    5353    bool IsConversionSupportedL();
    54         QString windows125xToUnicode( const char *chs, int len );
     54  QString windows125xToUnicode( const char *chs, int len );
    5555
    5656private:
     
    5959    QString convertLatin1(const unsigned char *chs, int len);
    6060    static CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* iArrayOfCharacterSetsAvailable;
    61     TUint       iEncoding;
     61    TUint iEncoding;
    6262};
    6363
     
    150150        }
    151151    }
    152         if( enc == 0 )
    153                 enc = BrDefaultEnc;
     152  if( enc == 0 )
     153    enc = BrDefaultEnc;
    154154
    155155    return new QTextCodec( enc, flags );
     
    189189QTextCodec *QTextCodec::codecForLocale()
    190190{
    191         // FIXME NOKIA: how to get the system encoding in Symbian OS?
    192         // only UTF8 used here
     191  // FIXME NOKIA: how to get the system encoding in Symbian OS?
     192  // only UTF8 used here
    193193    return new QTextCodec( KCharacterSetIdentifierIso88591 );
    194194}
     
    203203        default:
    204204            return '\\';
    205         }
     205  }
    206206}
    207207
     
    226226QCString QTextCodec::fromUnicode(const QString &qcs) const
    227227{
    228         return KWQTextDecoder( iEncoding ).fromUnicode( qcs );
     228  return KWQTextDecoder( iEncoding ).fromUnicode( qcs );
    229229}
    230230
     
    317317    // make sure the converter is available
    318318
    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) {
     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) {
    324324        encoding = KCharacterSetIdentifierUnicodeLittle;
    325325        bomLength = 2;
    326326    } else if (len > 2 && chs[0] == FE && chs[1] == FF) {
    327327        encoding = KCharacterSetIdentifierUnicodeBig;
    328                 endianness = CCnvCharacterSetConverter::EBigEndian;
     328    endianness = CCnvCharacterSetConverter::EBigEndian;
    329329        bomLength = 2;
    330330    } else if (len > 3 && chs[0] == EF && chs[1] == BB && chs[2] == BF) {
     
    334334
    335335    if (!IsConversionSupportedL())
    336                 {
    337                 iEncoding = KCharacterSetIdentifierIso88591;
    338                 }
     336    {
     337    iEncoding = KCharacterSetIdentifierIso88591;
     338    }
    339339
    340340    // check if it really looks like valid utf-8
     
    349349    if (iEncoding == KCharacterSetIdentifierIso88591)
    350350        return convertLatin1(reinterpret_cast<const unsigned char *>(chs), len);
    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                 }
     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    }
    360360
    361361    CCnvCharacterSetConverter* charConv = KWQGlobalServices::InstanceL()->CharConv();
     
    368368    TBuf16<32> outBuf;
    369369
    370         len = len - bomLength ;
    371     TPtrC8      inBuf( (const TUint8*)chs + bomLength, len );
     370  len = len - bomLength ;
     371    TPtrC8  inBuf( (const TUint8*)chs + bomLength, len );
    372372    TInt state=CCnvCharacterSetConverter::KStateDefault;
    373373
     
    391391        // copy result to out buffer
    392392
    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                   }
     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      }
    435435
    436436        if( ret == 0  || ret == -1 ) break;
     
    464464
    465465    // 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 );
    467468    TPtr8 ptr( outBuf->Des() );
    468469    ptr.SetLength( 0 );
     
    504505QString KWQTextDecoder::windows125xToUnicode( const char *chs, int len )
    505506{
    506         QString out;
    507         const unsigned short* cnvTable = 0;
    508         switch( iEncoding ) {
    509                 case KCharacterSetIdentifierWindow1250: cnvTable = win1250toUnicode; break;
    510                 case KCharacterSetIdentifierWindow1251: cnvTable = win1251toUnicode; break;
    511                 case KCharacterSetIdentifierWindow1253: cnvTable = win1253toUnicode; break;
    512                 case KCharacterSetIdentifierWindow1256: cnvTable = win1256toUnicode; break;
    513                 case KCharacterSetIdentifierWindow1257: cnvTable = win1257toUnicode; break;
    514                 default: return out;
    515         }
    516 
    517         OOM_PRE_CHECK( len*2, len*2, "KWQTextDecoder::toUnicode" );
    518         out.reserve( len * 2/3 );
    519         const char* p = chs;
    520         const char* top = chs + len;
    521         while(p<top) {
    522                 const unsigned char ch = *p++;
    523                 out.append( ch < 0x80 ? QChar(ch) : QChar(cnvTable[ch-0x80]) );
    524         }
    525         OOM_POST_CHECK_FAILED(return out;)
    526         return out;
     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;
    527528}
    528529
Note: See TracChangeset for help on using the changeset viewer.