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

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

Issue 2060913003: Make code compile with clang_use_chrome_plugin (part II) (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: base Created 4 years, 6 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 "Strings must not require more space than pointers"); 64 "Strings must not require more space than pointers");
65 65
66 CFX_WideString::CFX_WideString(const FX_WCHAR* pStr, FX_STRSIZE nLen) { 66 CFX_WideString::CFX_WideString(const FX_WCHAR* pStr, FX_STRSIZE nLen) {
67 if (nLen < 0) 67 if (nLen < 0)
68 nLen = pStr ? FXSYS_wcslen(pStr) : 0; 68 nLen = pStr ? FXSYS_wcslen(pStr) : 0;
69 69
70 if (nLen) 70 if (nLen)
71 m_pData.Reset(StringData::Create(pStr, nLen)); 71 m_pData.Reset(StringData::Create(pStr, nLen));
72 } 72 }
73 73
74 CFX_WideString::CFX_WideString() {}
75
76 CFX_WideString::CFX_WideString(const CFX_WideString& other)
77 : m_pData(other.m_pData) {}
78
79 CFX_WideString::CFX_WideString(CFX_WideString&& other) {
80 m_pData.Swap(other.m_pData);
81 }
82
74 CFX_WideString::CFX_WideString(FX_WCHAR ch) { 83 CFX_WideString::CFX_WideString(FX_WCHAR ch) {
75 m_pData.Reset(StringData::Create(1)); 84 m_pData.Reset(StringData::Create(1));
76 m_pData->m_String[0] = ch; 85 m_pData->m_String[0] = ch;
77 } 86 }
78 87
88 CFX_WideString::CFX_WideString(const FX_WCHAR* ptr)
89 : CFX_WideString(ptr, ptr ? FXSYS_wcslen(ptr) : 0) {}
90
79 CFX_WideString::CFX_WideString(const CFX_WideStringC& stringSrc) { 91 CFX_WideString::CFX_WideString(const CFX_WideStringC& stringSrc) {
80 if (!stringSrc.IsEmpty()) { 92 if (!stringSrc.IsEmpty()) {
81 m_pData.Reset(StringData::Create(stringSrc.c_str(), stringSrc.GetLength())); 93 m_pData.Reset(StringData::Create(stringSrc.c_str(), stringSrc.GetLength()));
82 } 94 }
83 } 95 }
84 96
85 CFX_WideString::CFX_WideString(const CFX_WideStringC& str1, 97 CFX_WideString::CFX_WideString(const CFX_WideStringC& str1,
86 const CFX_WideStringC& str2) { 98 const CFX_WideStringC& str2) {
87 int nNewLen = str1.GetLength() + str2.GetLength(); 99 int nNewLen = str1.GetLength() + str2.GetLength();
88 if (nNewLen == 0) 100 if (nNewLen == 0)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 return other.IsEmpty(); 184 return other.IsEmpty();
173 185
174 if (other.IsEmpty()) 186 if (other.IsEmpty())
175 return false; 187 return false;
176 188
177 return other.m_pData->m_nDataLength == m_pData->m_nDataLength && 189 return other.m_pData->m_nDataLength == m_pData->m_nDataLength &&
178 wmemcmp(other.m_pData->m_String, m_pData->m_String, 190 wmemcmp(other.m_pData->m_String, m_pData->m_String,
179 m_pData->m_nDataLength) == 0; 191 m_pData->m_nDataLength) == 0;
180 } 192 }
181 193
194 bool CFX_WideString::operator!=(const wchar_t* ptr) const {
195 return !(*this == ptr);
196 }
197
198 bool CFX_WideString::operator!=(const CFX_WideStringC& str) const {
199 return !(*this == str);
200 }
201
202 bool CFX_WideString::operator!=(const CFX_WideString& other) const {
203 return !(*this == other);
204 }
205
206 bool CFX_WideString::operator<(const CFX_WideString& str) const {
207 int result =
208 wmemcmp(c_str(), str.c_str(), std::min(GetLength(), str.GetLength()));
209 return result < 0 || (result == 0 && GetLength() < str.GetLength());
210 }
211
212 FX_WCHAR CFX_WideString::GetAt(FX_STRSIZE nIndex) const {
213 return m_pData ? m_pData->m_String[nIndex] : 0;
214 }
215
216 FX_WCHAR CFX_WideString::operator[](FX_STRSIZE nIndex) const {
217 return m_pData ? m_pData->m_String[nIndex] : 0;
218 }
219
182 void CFX_WideString::AssignCopy(const FX_WCHAR* pSrcData, FX_STRSIZE nSrcLen) { 220 void CFX_WideString::AssignCopy(const FX_WCHAR* pSrcData, FX_STRSIZE nSrcLen) {
183 AllocBeforeWrite(nSrcLen); 221 AllocBeforeWrite(nSrcLen);
184 m_pData->CopyContents(pSrcData, nSrcLen); 222 m_pData->CopyContents(pSrcData, nSrcLen);
185 m_pData->m_nDataLength = nSrcLen; 223 m_pData->m_nDataLength = nSrcLen;
186 } 224 }
187 225
188 void CFX_WideString::ReallocBeforeWrite(FX_STRSIZE nNewLength) { 226 void CFX_WideString::ReallocBeforeWrite(FX_STRSIZE nNewLength) {
189 if (m_pData && m_pData->CanOperateInPlace(nNewLength)) 227 if (m_pData && m_pData->CanOperateInPlace(nNewLength))
190 return; 228 return;
191 229
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 } 890 }
853 891
854 FX_STRSIZE CFX_WideString::WStringLength(const unsigned short* str) { 892 FX_STRSIZE CFX_WideString::WStringLength(const unsigned short* str) {
855 FX_STRSIZE len = 0; 893 FX_STRSIZE len = 0;
856 if (str) 894 if (str)
857 while (str[len]) 895 while (str[len])
858 len++; 896 len++;
859 return len; 897 return len;
860 } 898 }
861 899
900 const FX_WCHAR* CFX_WideString::c_str() const {
901 return m_pData ? m_pData->m_String : L"";
902 }
903
904 CFX_WideStringC CFX_WideString::AsStringC() const {
905 return CFX_WideStringC(c_str(), GetLength());
906 }
907
908 void CFX_WideString::clear() {
909 m_pData.Reset();
910 }
911
912 FX_STRSIZE CFX_WideString::GetLength() const {
913 return m_pData ? m_pData->m_nDataLength : 0;
914 }
915
916 bool CFX_WideString::IsEmpty() const {
917 return !GetLength();
918 }
919
862 void CFX_WideString::TrimRight(const CFX_WideStringC& pTargets) { 920 void CFX_WideString::TrimRight(const CFX_WideStringC& pTargets) {
863 if (IsEmpty() || pTargets.IsEmpty()) 921 if (IsEmpty() || pTargets.IsEmpty())
864 return; 922 return;
865 923
866 FX_STRSIZE pos = GetLength(); 924 FX_STRSIZE pos = GetLength();
867 while (pos && pTargets.Find(m_pData->m_String[pos - 1]) != -1) 925 while (pos && pTargets.Find(m_pData->m_String[pos - 1]) != -1)
868 pos--; 926 pos--;
869 927
870 if (pos < m_pData->m_nDataLength) { 928 if (pos < m_pData->m_nDataLength) {
871 ReallocBeforeWrite(m_pData->m_nDataLength); 929 ReallocBeforeWrite(m_pData->m_nDataLength);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, nullptr, 0); 1046 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, nullptr, 0);
989 CFX_WideString wstr; 1047 CFX_WideString wstr;
990 if (dest_len) { 1048 if (dest_len) {
991 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len); 1049 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len);
992 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, dest_buf, 1050 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, dest_buf,
993 dest_len); 1051 dest_len);
994 wstr.ReleaseBuffer(dest_len); 1052 wstr.ReleaseBuffer(dest_len);
995 } 1053 }
996 return wstr; 1054 return wstr;
997 } 1055 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698