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); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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++ = (uint16_t)*pWChar++; | 95 *pUTF16++ = (uint16_t)*pWChar++; |
96 } | 96 } |
97 } | 97 } |
98 } | 98 } |
99 inline FX_DWORD FX_DWordFromBytes(const uint8_t* pStr) { | 99 inline uint32_t 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 uint16_t 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(uint16_t 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, |
(...skipping 10 matching lines...) Expand all Loading... |
120 if (pSrcLen == NULL || pDstLen == NULL) { | 120 if (pSrcLen == NULL || pDstLen == NULL) { |
121 return -1; | 121 return -1; |
122 } | 122 } |
123 int32_t iSrcLen = *pSrcLen; | 123 int32_t iSrcLen = *pSrcLen; |
124 if (iSrcLen < 1) { | 124 if (iSrcLen < 1) { |
125 *pSrcLen = *pDstLen = 0; | 125 *pSrcLen = *pDstLen = 0; |
126 return 1; | 126 return 1; |
127 } | 127 } |
128 int32_t iDstLen = *pDstLen; | 128 int32_t iDstLen = *pDstLen; |
129 FX_BOOL bValidDst = (pDst != NULL && iDstLen > 0); | 129 FX_BOOL bValidDst = (pDst != NULL && iDstLen > 0); |
130 FX_DWORD dwCode = 0; | 130 uint32_t dwCode = 0; |
131 int32_t iPending = 0; | 131 int32_t iPending = 0; |
132 int32_t iSrcNum = 0, iDstNum = 0; | 132 int32_t iSrcNum = 0, iDstNum = 0; |
133 int32_t k = 0; | 133 int32_t k = 0; |
134 int32_t iIndex = 0; | 134 int32_t iIndex = 0; |
135 k = 1; | 135 k = 1; |
136 while (iIndex < iSrcLen) { | 136 while (iIndex < iSrcLen) { |
137 uint8_t byte = (uint8_t) * (pSrc + iIndex); | 137 uint8_t byte = (uint8_t) * (pSrc + iIndex); |
138 if (byte < 0x80) { | 138 if (byte < 0x80) { |
139 iPending = 0; | 139 iPending = 0; |
140 k = 1; | 140 k = 1; |
(...skipping 43 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 |