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 <stddef.h> // For offsetof(). | 7 #include <stddef.h> // For offsetof(). |
8 #include <cctype> | 8 #include <cctype> |
9 | 9 |
10 #include "core/include/fxcrt/fx_basic.h" | 10 #include "core/include/fxcrt/fx_basic.h" |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 int CFX_WideString::Compare(const FX_WCHAR* lpsz) const { | 280 int CFX_WideString::Compare(const FX_WCHAR* lpsz) const { |
281 if (m_pData == NULL) { | 281 if (m_pData == NULL) { |
282 return (lpsz == NULL || lpsz[0] == 0) ? 0 : -1; | 282 return (lpsz == NULL || lpsz[0] == 0) ? 0 : -1; |
283 } | 283 } |
284 return FXSYS_wcscmp(m_pData->m_String, lpsz); | 284 return FXSYS_wcscmp(m_pData->m_String, lpsz); |
285 } | 285 } |
286 CFX_ByteString CFX_WideString::UTF8Encode() const { | 286 CFX_ByteString CFX_WideString::UTF8Encode() const { |
287 return FX_UTF8Encode(*this); | 287 return FX_UTF8Encode(*this); |
288 } | 288 } |
289 CFX_ByteString CFX_WideString::UTF16LE_Encode() const { | 289 CFX_ByteString CFX_WideString::UTF16LE_Encode() const { |
290 if (m_pData == NULL) { | 290 CFX_ByteString result; |
291 return CFX_ByteString(FX_BSTRC("\0\0")); | 291 if (!m_pData) { |
| 292 return result; |
292 } | 293 } |
293 int len = m_pData->m_nDataLength; | 294 int len = m_pData->m_nDataLength; |
294 CFX_ByteString result; | 295 FX_CHAR* buffer = result.GetBuffer(len * 2); |
295 FX_CHAR* buffer = result.GetBuffer(len * 2 + 2); | 296 for (int i = 0; i < len; ++i) { |
296 for (int i = 0; i < len; i++) { | |
297 buffer[i * 2] = m_pData->m_String[i] & 0xff; | 297 buffer[i * 2] = m_pData->m_String[i] & 0xff; |
298 buffer[i * 2 + 1] = m_pData->m_String[i] >> 8; | 298 buffer[i * 2 + 1] = m_pData->m_String[i] >> 8; |
299 } | 299 } |
300 buffer[len * 2] = 0; | 300 result.ReleaseBuffer(len * 2); |
301 buffer[len * 2 + 1] = 0; | |
302 result.ReleaseBuffer(len * 2 + 2); | |
303 return result; | 301 return result; |
304 } | 302 } |
305 void CFX_WideString::ConvertFrom(const CFX_ByteString& str, | 303 void CFX_WideString::ConvertFrom(const CFX_ByteString& str, |
306 CFX_CharMap* pCharMap) { | 304 CFX_CharMap* pCharMap) { |
307 if (pCharMap == NULL) { | 305 if (pCharMap == NULL) { |
308 pCharMap = CFX_CharMap::GetDefaultMapper(); | 306 pCharMap = CFX_CharMap::GetDefaultMapper(); |
309 } | 307 } |
310 *this = pCharMap->m_GetWideString(pCharMap, str); | 308 *this = pCharMap->m_GetWideString(pCharMap, str); |
311 } | 309 } |
312 void CFX_WideString::Reserve(FX_STRSIZE len) { | 310 void CFX_WideString::Reserve(FX_STRSIZE len) { |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 return (CFX_CharMap*)&g_DefaultJISMapper; | 1057 return (CFX_CharMap*)&g_DefaultJISMapper; |
1060 case 936: | 1058 case 936: |
1061 return (CFX_CharMap*)&g_DefaultGBKMapper; | 1059 return (CFX_CharMap*)&g_DefaultGBKMapper; |
1062 case 949: | 1060 case 949: |
1063 return (CFX_CharMap*)&g_DefaultUHCMapper; | 1061 return (CFX_CharMap*)&g_DefaultUHCMapper; |
1064 case 950: | 1062 case 950: |
1065 return (CFX_CharMap*)&g_DefaultBig5Mapper; | 1063 return (CFX_CharMap*)&g_DefaultBig5Mapper; |
1066 } | 1064 } |
1067 return NULL; | 1065 return NULL; |
1068 } | 1066 } |
OLD | NEW |