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

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: Use GetConstStringBy(). 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
« no previous file with comments | « core/fxcrt/fx_basic_bstring.cpp ('k') | core/fxcrt/fx_extension.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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cctype> 10 #include <cctype>
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 if (!m_pData) { 740 if (!m_pData) {
741 return; 741 return;
742 } 742 }
743 ASSERT(nIndex >= 0); 743 ASSERT(nIndex >= 0);
744 ASSERT(nIndex < m_pData->m_nDataLength); 744 ASSERT(nIndex < m_pData->m_nDataLength);
745 ReallocBeforeWrite(m_pData->m_nDataLength); 745 ReallocBeforeWrite(m_pData->m_nDataLength);
746 m_pData->m_String[nIndex] = ch; 746 m_pData->m_String[nIndex] = ch;
747 } 747 }
748 748
749 // static 749 // static
750 CFX_WideString CFX_WideString::FromLocal(const CFX_ByteString& str) { 750 CFX_WideString CFX_WideString::FromLocal(const CFX_ByteStringC& str) {
751 return FromCodePage(str, 0); 751 return FromCodePage(str, 0);
752 } 752 }
753 753
754 // static 754 // static
755 CFX_WideString CFX_WideString::FromCodePage(const CFX_ByteString& str, 755 CFX_WideString CFX_WideString::FromCodePage(const CFX_ByteStringC& str,
756 uint16_t codepage) { 756 uint16_t codepage) {
757 return CFX_CharMap::GetWideString(codepage, str); 757 return CFX_CharMap::GetWideString(codepage, str);
758 } 758 }
759 759
760 // static 760 // static
761 CFX_WideString CFX_WideString::FromUTF8(const CFX_ByteStringC& str) { 761 CFX_WideString CFX_WideString::FromUTF8(const CFX_ByteStringC& str) {
762 if (str.IsEmpty()) 762 if (str.IsEmpty())
763 return CFX_WideString(); 763 return CFX_WideString();
764 764
765 CFX_UTF8Decoder decoder; 765 CFX_UTF8Decoder decoder;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 int CFX_WideString::GetInteger() const { 936 int CFX_WideString::GetInteger() const {
937 return m_pData ? FXSYS_wtoi(m_pData->m_String) : 0; 937 return m_pData ? FXSYS_wtoi(m_pData->m_String) : 0;
938 } 938 }
939 939
940 FX_FLOAT CFX_WideString::GetFloat() const { 940 FX_FLOAT CFX_WideString::GetFloat() const {
941 return m_pData ? FX_wtof(m_pData->m_String, m_pData->m_nDataLength) : 0.0f; 941 return m_pData ? FX_wtof(m_pData->m_String, m_pData->m_nDataLength) : 0.0f;
942 } 942 }
943 943
944 // static 944 // static
945 CFX_ByteString CFX_CharMap::GetByteString(uint16_t codepage, 945 CFX_ByteString CFX_CharMap::GetByteString(uint16_t codepage,
946 const CFX_WideString& wstr) { 946 const CFX_WideStringC& wstr) {
947 FXSYS_assert(IsValidCodePage(codepage)); 947 FXSYS_assert(IsValidCodePage(codepage));
948 int src_len = wstr.GetLength(); 948 int src_len = wstr.GetLength();
949 int dest_len = FXSYS_WideCharToMultiByte(codepage, 0, wstr.c_str(), src_len, 949 int dest_len = FXSYS_WideCharToMultiByte(codepage, 0, wstr.c_str(), src_len,
950 nullptr, 0, nullptr, nullptr); 950 nullptr, 0, nullptr, nullptr);
951 CFX_ByteString bstr; 951 CFX_ByteString bstr;
952 if (dest_len) { 952 if (dest_len) {
953 FX_CHAR* dest_buf = bstr.GetBuffer(dest_len); 953 FX_CHAR* dest_buf = bstr.GetBuffer(dest_len);
954 FXSYS_WideCharToMultiByte(codepage, 0, wstr.c_str(), src_len, dest_buf, 954 FXSYS_WideCharToMultiByte(codepage, 0, wstr.c_str(), src_len, dest_buf,
955 dest_len, nullptr, nullptr); 955 dest_len, nullptr, nullptr);
956 bstr.ReleaseBuffer(dest_len); 956 bstr.ReleaseBuffer(dest_len);
957 } 957 }
958 return bstr; 958 return bstr;
959 } 959 }
960 960
961 // static 961 // static
962 CFX_WideString CFX_CharMap::GetWideString(uint16_t codepage, 962 CFX_WideString CFX_CharMap::GetWideString(uint16_t codepage,
963 const CFX_ByteString& bstr) { 963 const CFX_ByteStringC& bstr) {
964 FXSYS_assert(IsValidCodePage(codepage)); 964 FXSYS_assert(IsValidCodePage(codepage));
965 int src_len = bstr.GetLength(); 965 int src_len = bstr.GetLength();
966 int dest_len = 966 int dest_len =
967 FXSYS_MultiByteToWideChar(codepage, 0, bstr, src_len, nullptr, 0); 967 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, nullptr, 0);
968 CFX_WideString wstr; 968 CFX_WideString wstr;
969 if (dest_len) { 969 if (dest_len) {
970 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len); 970 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len);
971 FXSYS_MultiByteToWideChar(codepage, 0, bstr, src_len, dest_buf, dest_len); 971 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, dest_buf,
972 dest_len);
972 wstr.ReleaseBuffer(dest_len); 973 wstr.ReleaseBuffer(dest_len);
973 } 974 }
974 return wstr; 975 return wstr;
975 } 976 }
OLDNEW
« no previous file with comments | « core/fxcrt/fx_basic_bstring.cpp ('k') | core/fxcrt/fx_extension.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698