Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: core/src/fxcrt/fx_basic_wstring.cpp

Issue 860973002: Simplify UTF16LE_Encode and add unittest. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: tab Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/include/fxcrt/fx_string.h ('k') | core/src/fxcrt/fx_basic_wstring_unittest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "../../include/fxcrt/fx_basic.h" 7 #include "../../include/fxcrt/fx_basic.h"
8 #include "../../../third_party/numerics/safe_math.h" 8 #include "../../../third_party/numerics/safe_math.h"
9 9
10 static CFX_StringDataW* FX_AllocStringW(int nLen) 10 static CFX_StringDataW* FX_AllocStringW(int nLen)
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 { 316 {
317 if (m_pData == NULL) { 317 if (m_pData == NULL) {
318 return (lpsz == NULL || lpsz[0] == 0) ? 0 : -1; 318 return (lpsz == NULL || lpsz[0] == 0) ? 0 : -1;
319 } 319 }
320 return FXSYS_wcscmp(m_pData->m_String, lpsz); 320 return FXSYS_wcscmp(m_pData->m_String, lpsz);
321 } 321 }
322 CFX_ByteString CFX_WideString::UTF8Encode() const 322 CFX_ByteString CFX_WideString::UTF8Encode() const
323 { 323 {
324 return FX_UTF8Encode(*this); 324 return FX_UTF8Encode(*this);
325 } 325 }
326 CFX_ByteString CFX_WideString::UTF16LE_Encode(FX_BOOL bTerminate) const 326 CFX_ByteString CFX_WideString::UTF16LE_Encode() const
327 { 327 {
328 if (m_pData == NULL) { 328 if (m_pData == NULL) {
329 return bTerminate ? CFX_ByteString(FX_BSTRC("\0\0")) : CFX_ByteString(); 329 return CFX_ByteString(FX_BSTRC("\0\0"));
330 } 330 }
331 int len = m_pData->m_nDataLength; 331 int len = m_pData->m_nDataLength;
332 CFX_ByteString result; 332 CFX_ByteString result;
333 FX_LPSTR buffer = result.GetBuffer(len * 2 + (bTerminate ? 2 : 0)); 333 FX_LPSTR buffer = result.GetBuffer(len * 2 + 2);
334 for (int i = 0; i < len; i ++) { 334 for (int i = 0; i < len; i ++) {
335 buffer[i * 2] = m_pData->m_String[i] & 0xff; 335 buffer[i * 2] = m_pData->m_String[i] & 0xff;
336 buffer[i * 2 + 1] = m_pData->m_String[i] >> 8; 336 buffer[i * 2 + 1] = m_pData->m_String[i] >> 8;
337 } 337 }
338 if (bTerminate) { 338 buffer[len * 2] = 0;
339 buffer[len * 2] = 0; 339 buffer[len * 2 + 1] = 0;
340 buffer[len * 2 + 1] = 0; 340 result.ReleaseBuffer(len * 2 + 2);
341 result.ReleaseBuffer(len * 2 + 2);
342 } else {
343 result.ReleaseBuffer(len * 2);
344 }
345 return result; 341 return result;
346 } 342 }
347 void CFX_WideString::ConvertFrom(const CFX_ByteString& str, CFX_CharMap* pCharMa p) 343 void CFX_WideString::ConvertFrom(const CFX_ByteString& str, CFX_CharMap* pCharMa p)
348 { 344 {
349 if (pCharMap == NULL) { 345 if (pCharMap == NULL) {
350 pCharMap = CFX_CharMap::GetDefaultMapper(); 346 pCharMap = CFX_CharMap::GetDefaultMapper();
351 } 347 }
352 *this = pCharMap->m_GetWideString(pCharMap, str); 348 *this = pCharMap->m_GetWideString(pCharMap, str);
353 } 349 }
354 void CFX_WideString::Reserve(FX_STRSIZE len) 350 void CFX_WideString::Reserve(FX_STRSIZE len)
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 return (CFX_CharMap*)&g_DefaultJISMapper; 1116 return (CFX_CharMap*)&g_DefaultJISMapper;
1121 case 936: 1117 case 936:
1122 return (CFX_CharMap*)&g_DefaultGBKMapper; 1118 return (CFX_CharMap*)&g_DefaultGBKMapper;
1123 case 949: 1119 case 949:
1124 return (CFX_CharMap*)&g_DefaultUHCMapper; 1120 return (CFX_CharMap*)&g_DefaultUHCMapper;
1125 case 950: 1121 case 950:
1126 return (CFX_CharMap*)&g_DefaultBig5Mapper; 1122 return (CFX_CharMap*)&g_DefaultBig5Mapper;
1127 } 1123 }
1128 return NULL; 1124 return NULL;
1129 } 1125 }
OLDNEW
« no previous file with comments | « core/include/fxcrt/fx_string.h ('k') | core/src/fxcrt/fx_basic_wstring_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698