| OLD | NEW | 
|---|
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 
| 6 | 6 | 
| 7 #include "core/fxcrt/include/fx_ext.h" | 7 #include "core/fxcrt/include/fx_ext.h" | 
| 8 #include "xfa/fgas/crt/fgas_codepage.h" | 8 #include "xfa/fgas/crt/fgas_codepage.h" | 
| 9 #include "xfa/fgas/crt/fgas_language.h" | 9 #include "xfa/fgas/crt/fgas_language.h" | 
| 10 | 10 | 
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 265     {0xe3323399, 0x3a4},  {0xe60412dd, 0x3b5},  {0xeee47add, 0x4b0}, | 265     {0xe3323399, 0x3a4},  {0xe60412dd, 0x3b5},  {0xeee47add, 0x4b0}, | 
| 266     {0xf021a186, 0x4e2},  {0xf021a187, 0x4e3},  {0xf021a188, 0x4e4}, | 266     {0xf021a186, 0x4e2},  {0xf021a187, 0x4e3},  {0xf021a188, 0x4e4}, | 
| 267     {0xf021a189, 0x4e5},  {0xf021a18a, 0x4e6},  {0xf021a18b, 0x4e7}, | 267     {0xf021a189, 0x4e5},  {0xf021a18a, 0x4e6},  {0xf021a18b, 0x4e7}, | 
| 268     {0xf021a18c, 0x4e8},  {0xf021a18d, 0x4e9},  {0xf021a18e, 0x4ea}, | 268     {0xf021a18c, 0x4e8},  {0xf021a18d, 0x4e9},  {0xf021a18e, 0x4ea}, | 
| 269     {0xf0700456, 0x6fb3}, {0xf274f175, 0x3b5},  {0xf2a9730b, 0x3a8}, | 269     {0xf0700456, 0x6fb3}, {0xf274f175, 0x3b5},  {0xf2a9730b, 0x3a8}, | 
| 270     {0xf3d463c2, 0x3a4},  {0xf52a70a3, 0xc42e}, {0xf5693147, 0x6fb3}, | 270     {0xf3d463c2, 0x3a4},  {0xf52a70a3, 0xc42e}, {0xf5693147, 0x6fb3}, | 
| 271     {0xf637e157, 0x478},  {0xfc213f3a, 0x2717}, {0xff654d14, 0x3b5}, | 271     {0xf637e157, 0x478},  {0xfc213f3a, 0x2717}, {0xff654d14, 0x3b5}, | 
| 272 }; | 272 }; | 
| 273 | 273 | 
| 274 uint16_t GetCodePageFromStringA(const FX_CHAR* pStr, int32_t iLength) { | 274 uint16_t GetCodePageFromStringA(const FX_CHAR* pStr, int32_t iLength) { | 
| 275   ASSERT(pStr != NULL); | 275   ASSERT(pStr); | 
| 276   if (iLength < 0) { | 276   if (iLength < 0) { | 
| 277     iLength = FXSYS_strlen(pStr); | 277     iLength = FXSYS_strlen(pStr); | 
| 278   } | 278   } | 
| 279   if (iLength == 0) { | 279   if (iLength == 0) { | 
| 280     return 0xFFFF; | 280     return 0xFFFF; | 
| 281   } | 281   } | 
| 282   uint32_t uHash = FX_HashCode_GetA(CFX_ByteStringC(pStr, iLength), true); | 282   uint32_t uHash = FX_HashCode_GetA(CFX_ByteStringC(pStr, iLength), true); | 
| 283   int32_t iStart = 0; | 283   int32_t iStart = 0; | 
| 284   int32_t iEnd = sizeof(g_FXCPHashTable) / sizeof(FX_STR2CPHASH) - 1; | 284   int32_t iEnd = sizeof(g_FXCPHashTable) / sizeof(FX_STR2CPHASH) - 1; | 
| 285   ASSERT(iEnd >= 0); | 285   ASSERT(iEnd >= 0); | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 363   CFX_ByteString csStr; | 363   CFX_ByteString csStr; | 
| 364   FX_CHAR* pBuf = csStr.GetBuffer(iLength + 1); | 364   FX_CHAR* pBuf = csStr.GetBuffer(iLength + 1); | 
| 365   for (int32_t i = 0; i < iLength; ++i) { | 365   for (int32_t i = 0; i < iLength; ++i) { | 
| 366     *pBuf++ = (FX_CHAR)*pStr++; | 366     *pBuf++ = (FX_CHAR)*pStr++; | 
| 367   } | 367   } | 
| 368   csStr.ReleaseBuffer(iLength); | 368   csStr.ReleaseBuffer(iLength); | 
| 369   return GetCodePageFromStringA(csStr.c_str(), iLength); | 369   return GetCodePageFromStringA(csStr.c_str(), iLength); | 
| 370 } | 370 } | 
| 371 | 371 | 
| 372 void FX_SwapByteOrder(FX_WCHAR* pStr, int32_t iLength) { | 372 void FX_SwapByteOrder(FX_WCHAR* pStr, int32_t iLength) { | 
| 373   ASSERT(pStr != NULL); | 373   ASSERT(pStr); | 
| 374   if (iLength < 0) { | 374   if (iLength < 0) { | 
| 375     iLength = FXSYS_wcslen(pStr); | 375     iLength = FXSYS_wcslen(pStr); | 
| 376   } | 376   } | 
| 377   uint16_t wch; | 377   uint16_t wch; | 
| 378   if (sizeof(FX_WCHAR) > 2) { | 378   if (sizeof(FX_WCHAR) > 2) { | 
| 379     while (iLength-- > 0) { | 379     while (iLength-- > 0) { | 
| 380       wch = (uint16_t)*pStr; | 380       wch = (uint16_t)*pStr; | 
| 381       wch = (wch >> 8) | (wch << 8); | 381       wch = (wch >> 8) | (wch << 8); | 
| 382       wch &= 0x00FF; | 382       wch &= 0x00FF; | 
| 383       *pStr++ = wch; | 383       *pStr++ = wch; | 
| 384     } | 384     } | 
| 385   } else { | 385   } else { | 
| 386     while (iLength-- > 0) { | 386     while (iLength-- > 0) { | 
| 387       wch = (uint16_t)*pStr; | 387       wch = (uint16_t)*pStr; | 
| 388       wch = (wch >> 8) | (wch << 8); | 388       wch = (wch >> 8) | (wch << 8); | 
| 389       *pStr++ = wch; | 389       *pStr++ = wch; | 
| 390     } | 390     } | 
| 391   } | 391   } | 
| 392 } | 392 } | 
| 393 | 393 | 
| 394 void FX_UTF16ToWChar(void* pBuffer, int32_t iLength) { | 394 void FX_UTF16ToWChar(void* pBuffer, int32_t iLength) { | 
| 395   ASSERT(pBuffer != NULL && iLength > 0); | 395   ASSERT(pBuffer && iLength > 0); | 
| 396   if (sizeof(FX_WCHAR) == 2) { | 396   if (sizeof(FX_WCHAR) == 2) { | 
| 397     return; | 397     return; | 
| 398   } | 398   } | 
| 399   uint16_t* pSrc = (uint16_t*)pBuffer; | 399   uint16_t* pSrc = (uint16_t*)pBuffer; | 
| 400   FX_WCHAR* pDst = (FX_WCHAR*)pBuffer; | 400   FX_WCHAR* pDst = (FX_WCHAR*)pBuffer; | 
| 401   while (--iLength >= 0) { | 401   while (--iLength >= 0) { | 
| 402     pDst[iLength] = (FX_WCHAR)pSrc[iLength]; | 402     pDst[iLength] = (FX_WCHAR)pSrc[iLength]; | 
| 403   } | 403   } | 
| 404 } | 404 } | 
| 405 | 405 | 
| 406 void FX_WCharToUTF16(void* pBuffer, int32_t iLength) { | 406 void FX_WCharToUTF16(void* pBuffer, int32_t iLength) { | 
| 407   ASSERT(pBuffer != NULL && iLength > 0); | 407   ASSERT(pBuffer && iLength > 0); | 
| 408   if (sizeof(FX_WCHAR) == 2) { | 408   if (sizeof(FX_WCHAR) == 2) { | 
| 409     return; | 409     return; | 
| 410   } | 410   } | 
| 411   const FX_WCHAR* pSrc = (const FX_WCHAR*)pBuffer; | 411   const FX_WCHAR* pSrc = (const FX_WCHAR*)pBuffer; | 
| 412   uint16_t* pDst = (uint16_t*)pBuffer; | 412   uint16_t* pDst = (uint16_t*)pBuffer; | 
| 413   while (--iLength >= 0) { | 413   while (--iLength >= 0) { | 
| 414     *pDst++ = (uint16_t)*pSrc++; | 414     *pDst++ = (uint16_t)*pSrc++; | 
| 415   } | 415   } | 
| 416 } | 416 } | 
| 417 | 417 | 
| 418 int32_t FX_DecodeString(uint16_t wCodePage, | 418 int32_t FX_DecodeString(uint16_t wCodePage, | 
| 419                         const FX_CHAR* pSrc, | 419                         const FX_CHAR* pSrc, | 
| 420                         int32_t* pSrcLen, | 420                         int32_t* pSrcLen, | 
| 421                         FX_WCHAR* pDst, | 421                         FX_WCHAR* pDst, | 
| 422                         int32_t* pDstLen, | 422                         int32_t* pDstLen, | 
| 423                         FX_BOOL bErrBreak) { | 423                         FX_BOOL bErrBreak) { | 
| 424   if (wCodePage == FX_CODEPAGE_UTF8) { | 424   if (wCodePage == FX_CODEPAGE_UTF8) { | 
| 425     return FX_UTF8Decode(pSrc, pSrcLen, pDst, pDstLen); | 425     return FX_UTF8Decode(pSrc, pSrcLen, pDst, pDstLen); | 
| 426   } | 426   } | 
| 427   return -1; | 427   return -1; | 
| 428 } | 428 } | 
| 429 int32_t FX_UTF8Decode(const FX_CHAR* pSrc, | 429 int32_t FX_UTF8Decode(const FX_CHAR* pSrc, | 
| 430                       int32_t* pSrcLen, | 430                       int32_t* pSrcLen, | 
| 431                       FX_WCHAR* pDst, | 431                       FX_WCHAR* pDst, | 
| 432                       int32_t* pDstLen) { | 432                       int32_t* pDstLen) { | 
| 433   if (pSrcLen == NULL || pDstLen == NULL) { | 433   if (!pSrcLen || !pDstLen) { | 
| 434     return -1; | 434     return -1; | 
| 435   } | 435   } | 
| 436   int32_t iSrcLen = *pSrcLen; | 436   int32_t iSrcLen = *pSrcLen; | 
| 437   if (iSrcLen < 1) { | 437   if (iSrcLen < 1) { | 
| 438     *pSrcLen = *pDstLen = 0; | 438     *pSrcLen = *pDstLen = 0; | 
| 439     return 1; | 439     return 1; | 
| 440   } | 440   } | 
| 441   int32_t iDstLen = *pDstLen; | 441   int32_t iDstLen = *pDstLen; | 
| 442   FX_BOOL bValidDst = (pDst != NULL && iDstLen > 0); | 442   FX_BOOL bValidDst = (pDst && iDstLen > 0); | 
| 443   uint32_t dwCode = 0; | 443   uint32_t dwCode = 0; | 
| 444   int32_t iPending = 0; | 444   int32_t iPending = 0; | 
| 445   int32_t iSrcNum = 0, iDstNum = 0; | 445   int32_t iSrcNum = 0, iDstNum = 0; | 
| 446   int32_t k = 0; | 446   int32_t k = 0; | 
| 447   int32_t iIndex = 0; | 447   int32_t iIndex = 0; | 
| 448   k = 1; | 448   k = 1; | 
| 449   while (iIndex < iSrcLen) { | 449   while (iIndex < iSrcLen) { | 
| 450     uint8_t byte = (uint8_t) * (pSrc + iIndex); | 450     uint8_t byte = (uint8_t) * (pSrc + iIndex); | 
| 451     if (byte < 0x80) { | 451     if (byte < 0x80) { | 
| 452       iPending = 0; | 452       iPending = 0; | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 497       dwCode = (byte & 0x01) << 30; | 497       dwCode = (byte & 0x01) << 30; | 
| 498     } else { | 498     } else { | 
| 499       break; | 499       break; | 
| 500     } | 500     } | 
| 501     iIndex++; | 501     iIndex++; | 
| 502   } | 502   } | 
| 503   *pSrcLen = iSrcNum; | 503   *pSrcLen = iSrcNum; | 
| 504   *pDstLen = iDstNum; | 504   *pDstLen = iDstNum; | 
| 505   return 1; | 505   return 1; | 
| 506 } | 506 } | 
| OLD | NEW | 
|---|