| 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 "xfa/fgas/crt/fgas_codepage.h" | 7 #include "xfa/fgas/crt/fgas_codepage.h" |
| 8 | 8 |
| 9 void FX_SwapByteOrder(FX_WCHAR* pStr, int32_t iLength) { | 9 void FX_SwapByteOrder(FX_WCHAR* pStr, int32_t iLength) { |
| 10 FXSYS_assert(pStr != NULL); | 10 FXSYS_assert(pStr != NULL); |
| 11 if (iLength < 0) { | 11 if (iLength < 0) { |
| 12 iLength = FXSYS_wcslen(pStr); | 12 iLength = FXSYS_wcslen(pStr); |
| 13 } | 13 } |
| 14 FX_WORD wch; | 14 uint16_t wch; |
| 15 if (sizeof(FX_WCHAR) > 2) { | 15 if (sizeof(FX_WCHAR) > 2) { |
| 16 while (iLength-- > 0) { | 16 while (iLength-- > 0) { |
| 17 wch = (FX_WORD)*pStr; | 17 wch = (uint16_t)*pStr; |
| 18 wch = (wch >> 8) | (wch << 8); | 18 wch = (wch >> 8) | (wch << 8); |
| 19 wch &= 0x00FF; | 19 wch &= 0x00FF; |
| 20 *pStr++ = wch; | 20 *pStr++ = wch; |
| 21 } | 21 } |
| 22 } else { | 22 } else { |
| 23 while (iLength-- > 0) { | 23 while (iLength-- > 0) { |
| 24 wch = (FX_WORD)*pStr; | 24 wch = (uint16_t)*pStr; |
| 25 wch = (wch >> 8) | (wch << 8); | 25 wch = (wch >> 8) | (wch << 8); |
| 26 *pStr++ = wch; | 26 *pStr++ = wch; |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 } | 29 } |
| 30 void FX_SwapByteOrderCopy(const FX_WCHAR* pSrc, | 30 void FX_SwapByteOrderCopy(const FX_WCHAR* pSrc, |
| 31 FX_WCHAR* pDst, | 31 FX_WCHAR* pDst, |
| 32 int32_t iLength) { | 32 int32_t iLength) { |
| 33 FXSYS_assert(pSrc != NULL && pDst != NULL); | 33 FXSYS_assert(pSrc != NULL && pDst != NULL); |
| 34 if (iLength < 0) { | 34 if (iLength < 0) { |
| 35 iLength = FXSYS_wcslen(pSrc); | 35 iLength = FXSYS_wcslen(pSrc); |
| 36 } | 36 } |
| 37 FX_WORD wch; | 37 uint16_t wch; |
| 38 if (sizeof(FX_WCHAR) > 2) { | 38 if (sizeof(FX_WCHAR) > 2) { |
| 39 while (iLength-- > 0) { | 39 while (iLength-- > 0) { |
| 40 wch = (FX_WORD)*pSrc++; | 40 wch = (uint16_t)*pSrc++; |
| 41 wch = (wch >> 8) | (wch << 8); | 41 wch = (wch >> 8) | (wch << 8); |
| 42 wch &= 0x00FF; | 42 wch &= 0x00FF; |
| 43 *pDst++ = wch; | 43 *pDst++ = wch; |
| 44 } | 44 } |
| 45 } else { | 45 } else { |
| 46 while (iLength-- > 0) { | 46 while (iLength-- > 0) { |
| 47 wch = (FX_WORD)*pSrc++; | 47 wch = (uint16_t)*pSrc++; |
| 48 wch = (wch >> 8) | (wch << 8); | 48 wch = (wch >> 8) | (wch << 8); |
| 49 *pDst++ = wch; | 49 *pDst++ = wch; |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 void FX_UTF16ToWChar(void* pBuffer, int32_t iLength) { | 53 void FX_UTF16ToWChar(void* pBuffer, int32_t iLength) { |
| 54 FXSYS_assert(pBuffer != NULL && iLength > 0); | 54 FXSYS_assert(pBuffer != NULL && iLength > 0); |
| 55 if (sizeof(FX_WCHAR) == 2) { | 55 if (sizeof(FX_WCHAR) == 2) { |
| 56 return; | 56 return; |
| 57 } | 57 } |
| 58 FX_WORD* pSrc = (FX_WORD*)pBuffer; | 58 uint16_t* pSrc = (uint16_t*)pBuffer; |
| 59 FX_WCHAR* pDst = (FX_WCHAR*)pBuffer; | 59 FX_WCHAR* pDst = (FX_WCHAR*)pBuffer; |
| 60 while (--iLength >= 0) { | 60 while (--iLength >= 0) { |
| 61 pDst[iLength] = (FX_WCHAR)pSrc[iLength]; | 61 pDst[iLength] = (FX_WCHAR)pSrc[iLength]; |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 void FX_UTF16ToWCharCopy(const FX_WORD* pUTF16, | 64 void FX_UTF16ToWCharCopy(const uint16_t* pUTF16, |
| 65 FX_WCHAR* pWChar, | 65 FX_WCHAR* pWChar, |
| 66 int32_t iLength) { | 66 int32_t iLength) { |
| 67 FXSYS_assert(pUTF16 != NULL && pWChar != NULL && iLength > 0); | 67 FXSYS_assert(pUTF16 != NULL && pWChar != NULL && iLength > 0); |
| 68 if (sizeof(FX_WCHAR) == 2) { | 68 if (sizeof(FX_WCHAR) == 2) { |
| 69 FXSYS_memcpy(pWChar, pUTF16, iLength * sizeof(FX_WCHAR)); | 69 FXSYS_memcpy(pWChar, pUTF16, iLength * sizeof(FX_WCHAR)); |
| 70 } else { | 70 } else { |
| 71 while (--iLength >= 0) { | 71 while (--iLength >= 0) { |
| 72 pWChar[iLength] = (FX_WCHAR)pUTF16[iLength]; | 72 pWChar[iLength] = (FX_WCHAR)pUTF16[iLength]; |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 void FX_WCharToUTF16(void* pBuffer, int32_t iLength) { | 76 void FX_WCharToUTF16(void* pBuffer, int32_t iLength) { |
| 77 FXSYS_assert(pBuffer != NULL && iLength > 0); | 77 FXSYS_assert(pBuffer != NULL && iLength > 0); |
| 78 if (sizeof(FX_WCHAR) == 2) { | 78 if (sizeof(FX_WCHAR) == 2) { |
| 79 return; | 79 return; |
| 80 } | 80 } |
| 81 const FX_WCHAR* pSrc = (const FX_WCHAR*)pBuffer; | 81 const FX_WCHAR* pSrc = (const FX_WCHAR*)pBuffer; |
| 82 FX_WORD* pDst = (FX_WORD*)pBuffer; | 82 uint16_t* pDst = (uint16_t*)pBuffer; |
| 83 while (--iLength >= 0) { | 83 while (--iLength >= 0) { |
| 84 *pDst++ = (FX_WORD)*pSrc++; | 84 *pDst++ = (uint16_t)*pSrc++; |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 void FX_WCharToUTF16Copy(const FX_WCHAR* pWChar, | 87 void FX_WCharToUTF16Copy(const FX_WCHAR* pWChar, |
| 88 FX_WORD* pUTF16, | 88 uint16_t* pUTF16, |
| 89 int32_t iLength) { | 89 int32_t iLength) { |
| 90 FXSYS_assert(pWChar != NULL && pUTF16 != NULL && iLength > 0); | 90 FXSYS_assert(pWChar != NULL && pUTF16 != NULL && iLength > 0); |
| 91 if (sizeof(FX_WCHAR) == 2) { | 91 if (sizeof(FX_WCHAR) == 2) { |
| 92 FXSYS_memcpy(pUTF16, pWChar, iLength * sizeof(FX_WCHAR)); | 92 FXSYS_memcpy(pUTF16, pWChar, iLength * sizeof(FX_WCHAR)); |
| 93 } else { | 93 } else { |
| 94 while (--iLength >= 0) { | 94 while (--iLength >= 0) { |
| 95 *pUTF16++ = (FX_WORD)*pWChar++; | 95 *pUTF16++ = (uint16_t)*pWChar++; |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 inline FX_DWORD FX_DWordFromBytes(const uint8_t* pStr) { | 99 inline FX_DWORD FX_DWordFromBytes(const uint8_t* pStr) { |
| 100 return FXBSTR_ID(pStr[3], pStr[2], pStr[1], pStr[0]); | 100 return FXBSTR_ID(pStr[3], pStr[2], pStr[1], pStr[0]); |
| 101 } | 101 } |
| 102 inline FX_WORD FX_WordFromBytes(const uint8_t* pStr) { | 102 inline uint16_t FX_WordFromBytes(const uint8_t* pStr) { |
| 103 return (pStr[1] << 8 | pStr[0]); | 103 return (pStr[1] << 8 | pStr[0]); |
| 104 } | 104 } |
| 105 int32_t FX_DecodeString(FX_WORD wCodePage, | 105 int32_t FX_DecodeString(uint16_t wCodePage, |
| 106 const FX_CHAR* pSrc, | 106 const FX_CHAR* pSrc, |
| 107 int32_t* pSrcLen, | 107 int32_t* pSrcLen, |
| 108 FX_WCHAR* pDst, | 108 FX_WCHAR* pDst, |
| 109 int32_t* pDstLen, | 109 int32_t* pDstLen, |
| 110 FX_BOOL bErrBreak) { | 110 FX_BOOL bErrBreak) { |
| 111 if (wCodePage == FX_CODEPAGE_UTF8) { | 111 if (wCodePage == FX_CODEPAGE_UTF8) { |
| 112 return FX_UTF8Decode(pSrc, pSrcLen, pDst, pDstLen); | 112 return FX_UTF8Decode(pSrc, pSrcLen, pDst, pDstLen); |
| 113 } | 113 } |
| 114 return -1; | 114 return -1; |
| 115 } | 115 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 dwCode = (byte & 0x01) << 30; | 184 dwCode = (byte & 0x01) << 30; |
| 185 } else { | 185 } else { |
| 186 break; | 186 break; |
| 187 } | 187 } |
| 188 iIndex++; | 188 iIndex++; |
| 189 } | 189 } |
| 190 *pSrcLen = iSrcNum; | 190 *pSrcLen = iSrcNum; |
| 191 *pDstLen = iDstNum; | 191 *pDstLen = iDstNum; |
| 192 return 1; | 192 return 1; |
| 193 } | 193 } |
| OLD | NEW |