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

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

Issue 1862953004: Make CFX_WideString::FromLocal() take a CFX_ByteStringC arg (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Propogate into CFX_CharMap methods, avoid silent alloc. Created 4 years, 8 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cctype> 10 #include <cctype>
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 return NULL; 354 return NULL;
355 } 355 }
356 FXSYS_memcpy(m_pData->m_String, pOldData->m_String, 356 FXSYS_memcpy(m_pData->m_String, pOldData->m_String,
357 (nOldLen + 1) * sizeof(FX_WCHAR)); 357 (nOldLen + 1) * sizeof(FX_WCHAR));
358 m_pData->m_nDataLength = nOldLen; 358 m_pData->m_nDataLength = nOldLen;
359 pOldData->Release(); 359 pOldData->Release();
360 return m_pData->m_String; 360 return m_pData->m_String;
361 } 361 }
362 362
363 // static 363 // static
364 CFX_WideString CFX_WideString::FromLocal(const CFX_ByteString& str) { 364 CFX_WideString CFX_WideString::FromLocal(const CFX_ByteStringC& str) {
365 return FromCodePage(str, 0); 365 return FromCodePage(str, 0);
366 } 366 }
367 367
368 // static 368 // static
369 CFX_WideString CFX_WideString::FromCodePage(const CFX_ByteString& str, 369 CFX_WideString CFX_WideString::FromCodePage(const CFX_ByteStringC& str,
370 uint16_t codepage) { 370 uint16_t codepage) {
371 return CFX_CharMap::GetWideString(codepage, str); 371 return CFX_CharMap::GetWideString(codepage, str);
372 } 372 }
373 373
374 // static 374 // static
375 CFX_WideString CFX_WideString::FromUTF8(const CFX_ByteStringC& str) { 375 CFX_WideString CFX_WideString::FromUTF8(const CFX_ByteStringC& str) {
376 if (str.IsEmpty()) 376 if (str.IsEmpty())
377 return CFX_WideString(); 377 return CFX_WideString();
378 378
379 CFX_UTF8Decoder decoder; 379 CFX_UTF8Decoder decoder;
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 } 1003 }
1004 int CFX_WideString::GetInteger() const { 1004 int CFX_WideString::GetInteger() const {
1005 return m_pData ? FXSYS_wtoi(m_pData->m_String) : 0; 1005 return m_pData ? FXSYS_wtoi(m_pData->m_String) : 0;
1006 } 1006 }
1007 FX_FLOAT CFX_WideString::GetFloat() const { 1007 FX_FLOAT CFX_WideString::GetFloat() const {
1008 return m_pData ? FX_wtof(m_pData->m_String, m_pData->m_nDataLength) : 0.0f; 1008 return m_pData ? FX_wtof(m_pData->m_String, m_pData->m_nDataLength) : 0.0f;
1009 } 1009 }
1010 1010
1011 // static 1011 // static
1012 CFX_ByteString CFX_CharMap::GetByteString(uint16_t codepage, 1012 CFX_ByteString CFX_CharMap::GetByteString(uint16_t codepage,
1013 const CFX_WideString& wstr) { 1013 const CFX_WideStringC& wstr) {
1014 FXSYS_assert(IsValidCodePage(codepage)); 1014 FXSYS_assert(IsValidCodePage(codepage));
1015 int src_len = wstr.GetLength(); 1015 int src_len = wstr.GetLength();
1016 int dest_len = FXSYS_WideCharToMultiByte(codepage, 0, wstr.c_str(), src_len, 1016 int dest_len = FXSYS_WideCharToMultiByte(codepage, 0, wstr.c_str(), src_len,
1017 nullptr, 0, nullptr, nullptr); 1017 nullptr, 0, nullptr, nullptr);
1018 CFX_ByteString bstr; 1018 CFX_ByteString bstr;
1019 if (dest_len) { 1019 if (dest_len) {
1020 FX_CHAR* dest_buf = bstr.GetBuffer(dest_len); 1020 FX_CHAR* dest_buf = bstr.GetBuffer(dest_len);
1021 FXSYS_WideCharToMultiByte(codepage, 0, wstr.c_str(), src_len, dest_buf, 1021 FXSYS_WideCharToMultiByte(codepage, 0, wstr.c_str(), src_len, dest_buf,
1022 dest_len, nullptr, nullptr); 1022 dest_len, nullptr, nullptr);
1023 bstr.ReleaseBuffer(dest_len); 1023 bstr.ReleaseBuffer(dest_len);
1024 } 1024 }
1025 return bstr; 1025 return bstr;
1026 } 1026 }
1027 1027
1028 // static 1028 // static
1029 CFX_WideString CFX_CharMap::GetWideString(uint16_t codepage, 1029 CFX_WideString CFX_CharMap::GetWideString(uint16_t codepage,
1030 const CFX_ByteString& bstr) { 1030 const CFX_ByteStringC& bstr) {
1031 FXSYS_assert(IsValidCodePage(codepage)); 1031 FXSYS_assert(IsValidCodePage(codepage));
1032 int src_len = bstr.GetLength(); 1032 int src_len = bstr.GetLength();
1033 int dest_len = 1033 int dest_len =
1034 FXSYS_MultiByteToWideChar(codepage, 0, bstr, src_len, nullptr, 0); 1034 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, nullptr, 0);
1035 CFX_WideString wstr; 1035 CFX_WideString wstr;
1036 if (dest_len) { 1036 if (dest_len) {
1037 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len); 1037 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len);
1038 FXSYS_MultiByteToWideChar(codepage, 0, bstr, src_len, dest_buf, dest_len); 1038 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, dest_buf,
1039 dest_len);
1039 wstr.ReleaseBuffer(dest_len); 1040 wstr.ReleaseBuffer(dest_len);
1040 } 1041 }
1041 return wstr; 1042 return wstr;
1042 } 1043 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698