| 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 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 void* pData = FX_Alloc(uint8_t, totalSize); | 37 void* pData = FX_Alloc(uint8_t, totalSize); |
| 38 return new (pData) StringData(nLen, usableLen); | 38 return new (pData) StringData(nLen, usableLen); |
| 39 } | 39 } |
| 40 CFX_WideString::~CFX_WideString() { | 40 CFX_WideString::~CFX_WideString() { |
| 41 if (m_pData) { | 41 if (m_pData) { |
| 42 m_pData->Release(); | 42 m_pData->Release(); |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 CFX_WideString::CFX_WideString(const CFX_WideString& stringSrc) { | 45 CFX_WideString::CFX_WideString(const CFX_WideString& stringSrc) { |
| 46 if (stringSrc.m_pData == NULL) { | 46 if (!stringSrc.m_pData) { |
| 47 m_pData = NULL; | 47 m_pData = NULL; |
| 48 return; | 48 return; |
| 49 } | 49 } |
| 50 if (stringSrc.m_pData->m_nRefs >= 0) { | 50 if (stringSrc.m_pData->m_nRefs >= 0) { |
| 51 m_pData = stringSrc.m_pData; | 51 m_pData = stringSrc.m_pData; |
| 52 m_pData->Retain(); | 52 m_pData->Retain(); |
| 53 } else { | 53 } else { |
| 54 m_pData = NULL; | 54 m_pData = NULL; |
| 55 *this = stringSrc; | 55 *this = stringSrc; |
| 56 } | 56 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } | 94 } |
| 95 m_pData = StringData::Create(nNewLen); | 95 m_pData = StringData::Create(nNewLen); |
| 96 if (m_pData) { | 96 if (m_pData) { |
| 97 FXSYS_memcpy(m_pData->m_String, str1.GetPtr(), | 97 FXSYS_memcpy(m_pData->m_String, str1.GetPtr(), |
| 98 str1.GetLength() * sizeof(FX_WCHAR)); | 98 str1.GetLength() * sizeof(FX_WCHAR)); |
| 99 FXSYS_memcpy(m_pData->m_String + str1.GetLength(), str2.GetPtr(), | 99 FXSYS_memcpy(m_pData->m_String + str1.GetLength(), str2.GetPtr(), |
| 100 str2.GetLength() * sizeof(FX_WCHAR)); | 100 str2.GetLength() * sizeof(FX_WCHAR)); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 void CFX_WideString::ReleaseBuffer(FX_STRSIZE nNewLength) { | 103 void CFX_WideString::ReleaseBuffer(FX_STRSIZE nNewLength) { |
| 104 if (m_pData == NULL) { | 104 if (!m_pData) { |
| 105 return; | 105 return; |
| 106 } | 106 } |
| 107 CopyBeforeWrite(); | 107 CopyBeforeWrite(); |
| 108 if (nNewLength == -1) { | 108 if (nNewLength == -1) { |
| 109 nNewLength = m_pData ? FXSYS_wcslen(m_pData->m_String) : 0; | 109 nNewLength = m_pData ? FXSYS_wcslen(m_pData->m_String) : 0; |
| 110 } | 110 } |
| 111 if (nNewLength == 0) { | 111 if (nNewLength == 0) { |
| 112 Empty(); | 112 Empty(); |
| 113 return; | 113 return; |
| 114 } | 114 } |
| 115 FXSYS_assert(nNewLength <= m_pData->m_nAllocLength); | 115 FXSYS_assert(nNewLength <= m_pData->m_nAllocLength); |
| 116 m_pData->m_nDataLength = nNewLength; | 116 m_pData->m_nDataLength = nNewLength; |
| 117 m_pData->m_String[nNewLength] = 0; | 117 m_pData->m_String[nNewLength] = 0; |
| 118 } | 118 } |
| 119 const CFX_WideString& CFX_WideString::operator=(const FX_WCHAR* lpsz) { | 119 const CFX_WideString& CFX_WideString::operator=(const FX_WCHAR* lpsz) { |
| 120 if (lpsz == NULL || lpsz[0] == 0) { | 120 if (!lpsz || lpsz[0] == 0) { |
| 121 Empty(); | 121 Empty(); |
| 122 } else { | 122 } else { |
| 123 AssignCopy(FXSYS_wcslen(lpsz), lpsz); | 123 AssignCopy(FXSYS_wcslen(lpsz), lpsz); |
| 124 } | 124 } |
| 125 return *this; | 125 return *this; |
| 126 } | 126 } |
| 127 const CFX_WideString& CFX_WideString::operator=( | 127 const CFX_WideString& CFX_WideString::operator=( |
| 128 const CFX_WideStringC& stringSrc) { | 128 const CFX_WideStringC& stringSrc) { |
| 129 if (stringSrc.IsEmpty()) { | 129 if (stringSrc.IsEmpty()) { |
| 130 Empty(); | 130 Empty(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 156 ConcatInPlace(1, &ch); | 156 ConcatInPlace(1, &ch); |
| 157 return *this; | 157 return *this; |
| 158 } | 158 } |
| 159 const CFX_WideString& CFX_WideString::operator+=(const FX_WCHAR* lpsz) { | 159 const CFX_WideString& CFX_WideString::operator+=(const FX_WCHAR* lpsz) { |
| 160 if (lpsz) { | 160 if (lpsz) { |
| 161 ConcatInPlace(FXSYS_wcslen(lpsz), lpsz); | 161 ConcatInPlace(FXSYS_wcslen(lpsz), lpsz); |
| 162 } | 162 } |
| 163 return *this; | 163 return *this; |
| 164 } | 164 } |
| 165 const CFX_WideString& CFX_WideString::operator+=(const CFX_WideString& string) { | 165 const CFX_WideString& CFX_WideString::operator+=(const CFX_WideString& string) { |
| 166 if (string.m_pData == NULL) { | 166 if (!string.m_pData) { |
| 167 return *this; | 167 return *this; |
| 168 } | 168 } |
| 169 ConcatInPlace(string.m_pData->m_nDataLength, string.m_pData->m_String); | 169 ConcatInPlace(string.m_pData->m_nDataLength, string.m_pData->m_String); |
| 170 return *this; | 170 return *this; |
| 171 } | 171 } |
| 172 const CFX_WideString& CFX_WideString::operator+=( | 172 const CFX_WideString& CFX_WideString::operator+=( |
| 173 const CFX_WideStringC& string) { | 173 const CFX_WideStringC& string) { |
| 174 if (string.IsEmpty()) { | 174 if (string.IsEmpty()) { |
| 175 return *this; | 175 return *this; |
| 176 } | 176 } |
| 177 ConcatInPlace(string.GetLength(), string.GetPtr()); | 177 ConcatInPlace(string.GetLength(), string.GetPtr()); |
| 178 return *this; | 178 return *this; |
| 179 } | 179 } |
| 180 bool CFX_WideString::Equal(const wchar_t* ptr) const { | 180 bool CFX_WideString::Equal(const wchar_t* ptr) const { |
| 181 if (!m_pData) { | 181 if (!m_pData) { |
| 182 return !ptr || ptr[0] == L'\0'; | 182 return !ptr || ptr[0] == L'\0'; |
| 183 } | 183 } |
| 184 if (!ptr) { | 184 if (!ptr) { |
| 185 return m_pData->m_nDataLength == 0; | 185 return m_pData->m_nDataLength == 0; |
| 186 } | 186 } |
| 187 return wcslen(ptr) == m_pData->m_nDataLength && | 187 return wcslen(ptr) == m_pData->m_nDataLength && |
| 188 wmemcmp(ptr, m_pData->m_String, m_pData->m_nDataLength) == 0; | 188 wmemcmp(ptr, m_pData->m_String, m_pData->m_nDataLength) == 0; |
| 189 } | 189 } |
| 190 bool CFX_WideString::Equal(const CFX_WideStringC& str) const { | 190 bool CFX_WideString::Equal(const CFX_WideStringC& str) const { |
| 191 if (m_pData == NULL) { | 191 if (!m_pData) { |
| 192 return str.IsEmpty(); | 192 return str.IsEmpty(); |
| 193 } | 193 } |
| 194 return str.GetLength() == m_pData->m_nDataLength && | 194 return str.GetLength() == m_pData->m_nDataLength && |
| 195 wmemcmp(str.GetPtr(), m_pData->m_String, m_pData->m_nDataLength) == 0; | 195 wmemcmp(str.GetPtr(), m_pData->m_String, m_pData->m_nDataLength) == 0; |
| 196 } | 196 } |
| 197 bool CFX_WideString::Equal(const CFX_WideString& other) const { | 197 bool CFX_WideString::Equal(const CFX_WideString& other) const { |
| 198 if (IsEmpty()) { | 198 if (IsEmpty()) { |
| 199 return other.IsEmpty(); | 199 return other.IsEmpty(); |
| 200 } | 200 } |
| 201 if (other.IsEmpty()) { | 201 if (other.IsEmpty()) { |
| 202 return false; | 202 return false; |
| 203 } | 203 } |
| 204 return other.m_pData->m_nDataLength == m_pData->m_nDataLength && | 204 return other.m_pData->m_nDataLength == m_pData->m_nDataLength && |
| 205 wmemcmp(other.m_pData->m_String, m_pData->m_String, | 205 wmemcmp(other.m_pData->m_String, m_pData->m_String, |
| 206 m_pData->m_nDataLength) == 0; | 206 m_pData->m_nDataLength) == 0; |
| 207 } | 207 } |
| 208 void CFX_WideString::Empty() { | 208 void CFX_WideString::Empty() { |
| 209 if (m_pData) { | 209 if (m_pData) { |
| 210 m_pData->Release(); | 210 m_pData->Release(); |
| 211 m_pData = NULL; | 211 m_pData = NULL; |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 void CFX_WideString::ConcatInPlace(FX_STRSIZE nSrcLen, | 214 void CFX_WideString::ConcatInPlace(FX_STRSIZE nSrcLen, |
| 215 const FX_WCHAR* lpszSrcData) { | 215 const FX_WCHAR* lpszSrcData) { |
| 216 if (nSrcLen == 0 || lpszSrcData == NULL) { | 216 if (nSrcLen == 0 || !lpszSrcData) { |
| 217 return; | 217 return; |
| 218 } | 218 } |
| 219 if (m_pData == NULL) { | 219 if (!m_pData) { |
| 220 m_pData = StringData::Create(nSrcLen); | 220 m_pData = StringData::Create(nSrcLen); |
| 221 if (m_pData) { | 221 if (m_pData) { |
| 222 FXSYS_memcpy(m_pData->m_String, lpszSrcData, nSrcLen * sizeof(FX_WCHAR)); | 222 FXSYS_memcpy(m_pData->m_String, lpszSrcData, nSrcLen * sizeof(FX_WCHAR)); |
| 223 } | 223 } |
| 224 return; | 224 return; |
| 225 } | 225 } |
| 226 if (m_pData->m_nRefs > 1 || | 226 if (m_pData->m_nRefs > 1 || |
| 227 m_pData->m_nDataLength + nSrcLen > m_pData->m_nAllocLength) { | 227 m_pData->m_nDataLength + nSrcLen > m_pData->m_nAllocLength) { |
| 228 ConcatCopy(m_pData->m_nDataLength, m_pData->m_String, nSrcLen, lpszSrcData); | 228 ConcatCopy(m_pData->m_nDataLength, m_pData->m_String, nSrcLen, lpszSrcData); |
| 229 } else { | 229 } else { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 244 // Don't release until done copying, might be one of the arguments. | 244 // Don't release until done copying, might be one of the arguments. |
| 245 StringData* pOldData = m_pData; | 245 StringData* pOldData = m_pData; |
| 246 m_pData = StringData::Create(nNewLen); | 246 m_pData = StringData::Create(nNewLen); |
| 247 if (m_pData) { | 247 if (m_pData) { |
| 248 wmemcpy(m_pData->m_String, lpszSrc1Data, nSrc1Len); | 248 wmemcpy(m_pData->m_String, lpszSrc1Data, nSrc1Len); |
| 249 wmemcpy(m_pData->m_String + nSrc1Len, lpszSrc2Data, nSrc2Len); | 249 wmemcpy(m_pData->m_String + nSrc1Len, lpszSrc2Data, nSrc2Len); |
| 250 } | 250 } |
| 251 pOldData->Release(); | 251 pOldData->Release(); |
| 252 } | 252 } |
| 253 void CFX_WideString::CopyBeforeWrite() { | 253 void CFX_WideString::CopyBeforeWrite() { |
| 254 if (m_pData == NULL || m_pData->m_nRefs <= 1) { | 254 if (!m_pData || m_pData->m_nRefs <= 1) { |
| 255 return; | 255 return; |
| 256 } | 256 } |
| 257 StringData* pData = m_pData; | 257 StringData* pData = m_pData; |
| 258 m_pData->Release(); | 258 m_pData->Release(); |
| 259 FX_STRSIZE nDataLength = pData->m_nDataLength; | 259 FX_STRSIZE nDataLength = pData->m_nDataLength; |
| 260 m_pData = StringData::Create(nDataLength); | 260 m_pData = StringData::Create(nDataLength); |
| 261 if (m_pData) { | 261 if (m_pData) { |
| 262 FXSYS_memcpy(m_pData->m_String, pData->m_String, | 262 FXSYS_memcpy(m_pData->m_String, pData->m_String, |
| 263 (nDataLength + 1) * sizeof(FX_WCHAR)); | 263 (nDataLength + 1) * sizeof(FX_WCHAR)); |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 void CFX_WideString::AllocBeforeWrite(FX_STRSIZE nLen) { | 266 void CFX_WideString::AllocBeforeWrite(FX_STRSIZE nLen) { |
| 267 if (m_pData && m_pData->m_nRefs <= 1 && m_pData->m_nAllocLength >= nLen) { | 267 if (m_pData && m_pData->m_nRefs <= 1 && m_pData->m_nAllocLength >= nLen) { |
| 268 return; | 268 return; |
| 269 } | 269 } |
| 270 Empty(); | 270 Empty(); |
| 271 m_pData = StringData::Create(nLen); | 271 m_pData = StringData::Create(nLen); |
| 272 } | 272 } |
| 273 void CFX_WideString::AssignCopy(FX_STRSIZE nSrcLen, | 273 void CFX_WideString::AssignCopy(FX_STRSIZE nSrcLen, |
| 274 const FX_WCHAR* lpszSrcData) { | 274 const FX_WCHAR* lpszSrcData) { |
| 275 AllocBeforeWrite(nSrcLen); | 275 AllocBeforeWrite(nSrcLen); |
| 276 FXSYS_memcpy(m_pData->m_String, lpszSrcData, nSrcLen * sizeof(FX_WCHAR)); | 276 FXSYS_memcpy(m_pData->m_String, lpszSrcData, nSrcLen * sizeof(FX_WCHAR)); |
| 277 m_pData->m_nDataLength = nSrcLen; | 277 m_pData->m_nDataLength = nSrcLen; |
| 278 m_pData->m_String[nSrcLen] = 0; | 278 m_pData->m_String[nSrcLen] = 0; |
| 279 } | 279 } |
| 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) |
| 282 return (lpsz == NULL || lpsz[0] == 0) ? 0 : -1; | 282 return FXSYS_wcscmp(m_pData->m_String, lpsz); |
| 283 } | 283 return (!lpsz || lpsz[0] == 0) ? 0 : -1; |
| 284 return FXSYS_wcscmp(m_pData->m_String, lpsz); | |
| 285 } | 284 } |
| 286 CFX_ByteString CFX_WideString::UTF8Encode() const { | 285 CFX_ByteString CFX_WideString::UTF8Encode() const { |
| 287 return FX_UTF8Encode(*this); | 286 return FX_UTF8Encode(*this); |
| 288 } | 287 } |
| 289 CFX_ByteString CFX_WideString::UTF16LE_Encode() const { | 288 CFX_ByteString CFX_WideString::UTF16LE_Encode() const { |
| 290 if (m_pData == NULL) { | 289 if (!m_pData) { |
| 291 return CFX_ByteString("\0\0", 2); | 290 return CFX_ByteString("\0\0", 2); |
| 292 } | 291 } |
| 293 int len = m_pData->m_nDataLength; | 292 int len = m_pData->m_nDataLength; |
| 294 CFX_ByteString result; | 293 CFX_ByteString result; |
| 295 FX_CHAR* buffer = result.GetBuffer(len * 2 + 2); | 294 FX_CHAR* buffer = result.GetBuffer(len * 2 + 2); |
| 296 for (int i = 0; i < len; i++) { | 295 for (int i = 0; i < len; i++) { |
| 297 buffer[i * 2] = m_pData->m_String[i] & 0xff; | 296 buffer[i * 2] = m_pData->m_String[i] & 0xff; |
| 298 buffer[i * 2 + 1] = m_pData->m_String[i] >> 8; | 297 buffer[i * 2 + 1] = m_pData->m_String[i] >> 8; |
| 299 } | 298 } |
| 300 buffer[len * 2] = 0; | 299 buffer[len * 2] = 0; |
| 301 buffer[len * 2 + 1] = 0; | 300 buffer[len * 2 + 1] = 0; |
| 302 result.ReleaseBuffer(len * 2 + 2); | 301 result.ReleaseBuffer(len * 2 + 2); |
| 303 return result; | 302 return result; |
| 304 } | 303 } |
| 305 void CFX_WideString::ConvertFrom(const CFX_ByteString& str, | 304 void CFX_WideString::ConvertFrom(const CFX_ByteString& str, |
| 306 CFX_CharMap* pCharMap) { | 305 CFX_CharMap* pCharMap) { |
| 307 if (pCharMap == NULL) { | 306 if (!pCharMap) { |
| 308 pCharMap = CFX_CharMap::GetDefaultMapper(); | 307 pCharMap = CFX_CharMap::GetDefaultMapper(); |
| 309 } | 308 } |
| 310 *this = pCharMap->m_GetWideString(pCharMap, str); | 309 *this = pCharMap->m_GetWideString(pCharMap, str); |
| 311 } | 310 } |
| 312 void CFX_WideString::Reserve(FX_STRSIZE len) { | 311 void CFX_WideString::Reserve(FX_STRSIZE len) { |
| 313 GetBuffer(len); | 312 GetBuffer(len); |
| 314 ReleaseBuffer(GetLength()); | 313 ReleaseBuffer(GetLength()); |
| 315 } | 314 } |
| 316 FX_WCHAR* CFX_WideString::GetBuffer(FX_STRSIZE nMinBufLength) { | 315 FX_WCHAR* CFX_WideString::GetBuffer(FX_STRSIZE nMinBufLength) { |
| 317 if (m_pData == NULL && nMinBufLength == 0) { | 316 if (!m_pData && nMinBufLength == 0) { |
| 318 return NULL; | 317 return NULL; |
| 319 } | 318 } |
| 320 if (m_pData && m_pData->m_nRefs <= 1 && | 319 if (m_pData && m_pData->m_nRefs <= 1 && |
| 321 m_pData->m_nAllocLength >= nMinBufLength) { | 320 m_pData->m_nAllocLength >= nMinBufLength) { |
| 322 return m_pData->m_String; | 321 return m_pData->m_String; |
| 323 } | 322 } |
| 324 if (m_pData == NULL) { | 323 if (!m_pData) { |
| 325 m_pData = StringData::Create(nMinBufLength); | 324 m_pData = StringData::Create(nMinBufLength); |
| 326 if (!m_pData) { | 325 if (!m_pData) { |
| 327 return NULL; | 326 return NULL; |
| 328 } | 327 } |
| 329 m_pData->m_nDataLength = 0; | 328 m_pData->m_nDataLength = 0; |
| 330 m_pData->m_String[0] = 0; | 329 m_pData->m_String[0] = 0; |
| 331 return m_pData->m_String; | 330 return m_pData->m_String; |
| 332 } | 331 } |
| 333 StringData* pOldData = m_pData; | 332 StringData* pOldData = m_pData; |
| 334 FX_STRSIZE nOldLen = pOldData->m_nDataLength; | 333 FX_STRSIZE nOldLen = pOldData->m_nDataLength; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 FX_STRSIZE nCopyLen, | 386 FX_STRSIZE nCopyLen, |
| 388 FX_STRSIZE nCopyIndex) const { | 387 FX_STRSIZE nCopyIndex) const { |
| 389 // |FX_STRSIZE| is currently typedef'd as in |int|. TODO(palmer): It | 388 // |FX_STRSIZE| is currently typedef'd as in |int|. TODO(palmer): It |
| 390 // should be a |size_t|, or at least unsigned. | 389 // should be a |size_t|, or at least unsigned. |
| 391 if (nCopyLen == 0 || nCopyLen < 0) { | 390 if (nCopyLen == 0 || nCopyLen < 0) { |
| 392 return; | 391 return; |
| 393 } | 392 } |
| 394 pdfium::base::CheckedNumeric<FX_STRSIZE> iSize = | 393 pdfium::base::CheckedNumeric<FX_STRSIZE> iSize = |
| 395 static_cast<FX_STRSIZE>(sizeof(FX_WCHAR)); | 394 static_cast<FX_STRSIZE>(sizeof(FX_WCHAR)); |
| 396 iSize *= nCopyLen; | 395 iSize *= nCopyLen; |
| 397 ASSERT(dest.m_pData == NULL); | 396 ASSERT(!dest.m_pData); |
| 398 dest.m_pData = StringData::Create(nCopyLen); | 397 dest.m_pData = StringData::Create(nCopyLen); |
| 399 if (dest.m_pData) { | 398 if (dest.m_pData) { |
| 400 FXSYS_memcpy(dest.m_pData->m_String, m_pData->m_String + nCopyIndex, | 399 FXSYS_memcpy(dest.m_pData->m_String, m_pData->m_String + nCopyIndex, |
| 401 iSize.ValueOrDie()); | 400 iSize.ValueOrDie()); |
| 402 } | 401 } |
| 403 } | 402 } |
| 404 CFX_WideString CFX_WideString::Left(FX_STRSIZE nCount) const { | 403 CFX_WideString CFX_WideString::Left(FX_STRSIZE nCount) const { |
| 405 if (m_pData == NULL) { | 404 if (!m_pData) { |
| 406 return CFX_WideString(); | 405 return CFX_WideString(); |
| 407 } | 406 } |
| 408 if (nCount < 0) { | 407 if (nCount < 0) { |
| 409 nCount = 0; | 408 nCount = 0; |
| 410 } | 409 } |
| 411 if (nCount >= m_pData->m_nDataLength) { | 410 if (nCount >= m_pData->m_nDataLength) { |
| 412 return *this; | 411 return *this; |
| 413 } | 412 } |
| 414 CFX_WideString dest; | 413 CFX_WideString dest; |
| 415 AllocCopy(dest, nCount, 0); | 414 AllocCopy(dest, nCount, 0); |
| 416 return dest; | 415 return dest; |
| 417 } | 416 } |
| 418 CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst) const { | 417 CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst) const { |
| 419 return Mid(nFirst, m_pData->m_nDataLength - nFirst); | 418 return Mid(nFirst, m_pData->m_nDataLength - nFirst); |
| 420 } | 419 } |
| 421 CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const { | 420 CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const { |
| 422 if (m_pData == NULL) { | 421 if (!m_pData) { |
| 423 return CFX_WideString(); | 422 return CFX_WideString(); |
| 424 } | 423 } |
| 425 if (nFirst < 0) { | 424 if (nFirst < 0) { |
| 426 nFirst = 0; | 425 nFirst = 0; |
| 427 } | 426 } |
| 428 if (nCount < 0) { | 427 if (nCount < 0) { |
| 429 nCount = 0; | 428 nCount = 0; |
| 430 } | 429 } |
| 431 if (nFirst + nCount > m_pData->m_nDataLength) { | 430 if (nFirst + nCount > m_pData->m_nDataLength) { |
| 432 nCount = m_pData->m_nDataLength - nFirst; | 431 nCount = m_pData->m_nDataLength - nFirst; |
| 433 } | 432 } |
| 434 if (nFirst > m_pData->m_nDataLength) { | 433 if (nFirst > m_pData->m_nDataLength) { |
| 435 nCount = 0; | 434 nCount = 0; |
| 436 } | 435 } |
| 437 if (nFirst == 0 && nFirst + nCount == m_pData->m_nDataLength) { | 436 if (nFirst == 0 && nFirst + nCount == m_pData->m_nDataLength) { |
| 438 return *this; | 437 return *this; |
| 439 } | 438 } |
| 440 CFX_WideString dest; | 439 CFX_WideString dest; |
| 441 AllocCopy(dest, nCount, nFirst); | 440 AllocCopy(dest, nCount, nFirst); |
| 442 return dest; | 441 return dest; |
| 443 } | 442 } |
| 444 CFX_WideString CFX_WideString::Right(FX_STRSIZE nCount) const { | 443 CFX_WideString CFX_WideString::Right(FX_STRSIZE nCount) const { |
| 445 if (m_pData == NULL) { | 444 if (!m_pData) { |
| 446 return CFX_WideString(); | 445 return CFX_WideString(); |
| 447 } | 446 } |
| 448 if (nCount < 0) { | 447 if (nCount < 0) { |
| 449 nCount = 0; | 448 nCount = 0; |
| 450 } | 449 } |
| 451 if (nCount >= m_pData->m_nDataLength) { | 450 if (nCount >= m_pData->m_nDataLength) { |
| 452 return *this; | 451 return *this; |
| 453 } | 452 } |
| 454 CFX_WideString dest; | 453 CFX_WideString dest; |
| 455 AllocCopy(dest, nCount, m_pData->m_nDataLength - nCount); | 454 AllocCopy(dest, nCount, m_pData->m_nDataLength - nCount); |
| 456 return dest; | 455 return dest; |
| 457 } | 456 } |
| 458 int CFX_WideString::CompareNoCase(const FX_WCHAR* lpsz) const { | 457 int CFX_WideString::CompareNoCase(const FX_WCHAR* lpsz) const { |
| 459 if (m_pData == NULL) { | 458 if (!m_pData) { |
| 460 return (lpsz == NULL || lpsz[0] == 0) ? 0 : -1; | 459 return (!lpsz || lpsz[0] == 0) ? 0 : -1; |
| 461 } | 460 } |
| 462 return FXSYS_wcsicmp(m_pData->m_String, lpsz); | 461 return FXSYS_wcsicmp(m_pData->m_String, lpsz); |
| 463 } | 462 } |
| 464 int CFX_WideString::Compare(const CFX_WideString& str) const { | 463 int CFX_WideString::Compare(const CFX_WideString& str) const { |
| 465 if (m_pData == NULL) { | 464 if (!m_pData) { |
| 466 if (str.m_pData == NULL) { | 465 if (!str.m_pData) { |
| 467 return 0; | 466 return 0; |
| 468 } | 467 } |
| 469 return -1; | 468 return -1; |
| 470 } | 469 } |
| 471 if (str.m_pData == NULL) { | 470 if (!str.m_pData) { |
| 472 return 1; | 471 return 1; |
| 473 } | 472 } |
| 474 int this_len = m_pData->m_nDataLength; | 473 int this_len = m_pData->m_nDataLength; |
| 475 int that_len = str.m_pData->m_nDataLength; | 474 int that_len = str.m_pData->m_nDataLength; |
| 476 int min_len = this_len < that_len ? this_len : that_len; | 475 int min_len = this_len < that_len ? this_len : that_len; |
| 477 for (int i = 0; i < min_len; i++) { | 476 for (int i = 0; i < min_len; i++) { |
| 478 if (m_pData->m_String[i] < str.m_pData->m_String[i]) { | 477 if (m_pData->m_String[i] < str.m_pData->m_String[i]) { |
| 479 return -1; | 478 return -1; |
| 480 } | 479 } |
| 481 if (m_pData->m_String[i] > str.m_pData->m_String[i]) { | 480 if (m_pData->m_String[i] > str.m_pData->m_String[i]) { |
| 482 return 1; | 481 return 1; |
| 483 } | 482 } |
| 484 } | 483 } |
| 485 if (this_len < that_len) { | 484 if (this_len < that_len) { |
| 486 return -1; | 485 return -1; |
| 487 } | 486 } |
| 488 if (this_len > that_len) { | 487 if (this_len > that_len) { |
| 489 return 1; | 488 return 1; |
| 490 } | 489 } |
| 491 return 0; | 490 return 0; |
| 492 } | 491 } |
| 493 void CFX_WideString::SetAt(FX_STRSIZE nIndex, FX_WCHAR ch) { | 492 void CFX_WideString::SetAt(FX_STRSIZE nIndex, FX_WCHAR ch) { |
| 494 if (m_pData == NULL) { | 493 if (!m_pData) { |
| 495 return; | 494 return; |
| 496 } | 495 } |
| 497 ASSERT(nIndex >= 0); | 496 ASSERT(nIndex >= 0); |
| 498 ASSERT(nIndex < m_pData->m_nDataLength); | 497 ASSERT(nIndex < m_pData->m_nDataLength); |
| 499 CopyBeforeWrite(); | 498 CopyBeforeWrite(); |
| 500 m_pData->m_String[nIndex] = ch; | 499 m_pData->m_String[nIndex] = ch; |
| 501 } | 500 } |
| 502 void CFX_WideString::MakeLower() { | 501 void CFX_WideString::MakeLower() { |
| 503 if (m_pData == NULL) { | 502 if (!m_pData) { |
| 504 return; | 503 return; |
| 505 } | 504 } |
| 506 CopyBeforeWrite(); | 505 CopyBeforeWrite(); |
| 507 if (GetLength() < 1) { | 506 if (GetLength() < 1) { |
| 508 return; | 507 return; |
| 509 } | 508 } |
| 510 FXSYS_wcslwr(m_pData->m_String); | 509 FXSYS_wcslwr(m_pData->m_String); |
| 511 } | 510 } |
| 512 void CFX_WideString::MakeUpper() { | 511 void CFX_WideString::MakeUpper() { |
| 513 if (m_pData == NULL) { | 512 if (!m_pData) { |
| 514 return; | 513 return; |
| 515 } | 514 } |
| 516 CopyBeforeWrite(); | 515 CopyBeforeWrite(); |
| 517 if (GetLength() < 1) { | 516 if (GetLength() < 1) { |
| 518 return; | 517 return; |
| 519 } | 518 } |
| 520 FXSYS_wcsupr(m_pData->m_String); | 519 FXSYS_wcsupr(m_pData->m_String); |
| 521 } | 520 } |
| 522 FX_STRSIZE CFX_WideString::Find(const FX_WCHAR* lpszSub, | 521 FX_STRSIZE CFX_WideString::Find(const FX_WCHAR* lpszSub, |
| 523 FX_STRSIZE nStart) const { | 522 FX_STRSIZE nStart) const { |
| 524 FX_STRSIZE nLength = GetLength(); | 523 FX_STRSIZE nLength = GetLength(); |
| 525 if (nLength < 1 || nStart > nLength) { | 524 if (nLength < 1 || nStart > nLength) { |
| 526 return -1; | 525 return -1; |
| 527 } | 526 } |
| 528 const FX_WCHAR* lpsz = FXSYS_wcsstr(m_pData->m_String + nStart, lpszSub); | 527 const FX_WCHAR* lpsz = FXSYS_wcsstr(m_pData->m_String + nStart, lpszSub); |
| 529 return (lpsz == NULL) ? -1 : (int)(lpsz - m_pData->m_String); | 528 return lpsz ? (int)(lpsz - m_pData->m_String) : -1; |
| 530 } | 529 } |
| 531 FX_STRSIZE CFX_WideString::Find(FX_WCHAR ch, FX_STRSIZE nStart) const { | 530 FX_STRSIZE CFX_WideString::Find(FX_WCHAR ch, FX_STRSIZE nStart) const { |
| 532 if (m_pData == NULL) { | 531 if (!m_pData) { |
| 533 return -1; | 532 return -1; |
| 534 } | 533 } |
| 535 FX_STRSIZE nLength = m_pData->m_nDataLength; | 534 FX_STRSIZE nLength = m_pData->m_nDataLength; |
| 536 if (nStart >= nLength) { | 535 if (nStart >= nLength) { |
| 537 return -1; | 536 return -1; |
| 538 } | 537 } |
| 539 const FX_WCHAR* lpsz = FXSYS_wcschr(m_pData->m_String + nStart, ch); | 538 const FX_WCHAR* lpsz = FXSYS_wcschr(m_pData->m_String + nStart, ch); |
| 540 return (lpsz == NULL) ? -1 : (int)(lpsz - m_pData->m_String); | 539 return (lpsz) ? (int)(lpsz - m_pData->m_String) : -1; |
| 541 } | 540 } |
| 542 void CFX_WideString::TrimRight(const FX_WCHAR* lpszTargetList) { | 541 void CFX_WideString::TrimRight(const FX_WCHAR* lpszTargetList) { |
| 543 FXSYS_assert(lpszTargetList); | 542 FXSYS_assert(lpszTargetList); |
| 544 if (m_pData == NULL || *lpszTargetList == 0) { | 543 if (!m_pData || *lpszTargetList == 0) { |
| 545 return; | 544 return; |
| 546 } | 545 } |
| 547 CopyBeforeWrite(); | 546 CopyBeforeWrite(); |
| 548 FX_STRSIZE len = GetLength(); | 547 FX_STRSIZE len = GetLength(); |
| 549 if (len < 1) { | 548 if (len < 1) { |
| 550 return; | 549 return; |
| 551 } | 550 } |
| 552 FX_STRSIZE pos = len; | 551 FX_STRSIZE pos = len; |
| 553 while (pos) { | 552 while (pos) { |
| 554 if (FXSYS_wcschr(lpszTargetList, m_pData->m_String[pos - 1]) == NULL) { | 553 if (!FXSYS_wcschr(lpszTargetList, m_pData->m_String[pos - 1])) { |
| 555 break; | 554 break; |
| 556 } | 555 } |
| 557 pos--; | 556 pos--; |
| 558 } | 557 } |
| 559 if (pos < len) { | 558 if (pos < len) { |
| 560 m_pData->m_String[pos] = 0; | 559 m_pData->m_String[pos] = 0; |
| 561 m_pData->m_nDataLength = pos; | 560 m_pData->m_nDataLength = pos; |
| 562 } | 561 } |
| 563 } | 562 } |
| 564 void CFX_WideString::TrimRight(FX_WCHAR chTarget) { | 563 void CFX_WideString::TrimRight(FX_WCHAR chTarget) { |
| 565 FX_WCHAR str[2] = {chTarget, 0}; | 564 FX_WCHAR str[2] = {chTarget, 0}; |
| 566 TrimRight(str); | 565 TrimRight(str); |
| 567 } | 566 } |
| 568 void CFX_WideString::TrimRight() { | 567 void CFX_WideString::TrimRight() { |
| 569 TrimRight(L"\x09\x0a\x0b\x0c\x0d\x20"); | 568 TrimRight(L"\x09\x0a\x0b\x0c\x0d\x20"); |
| 570 } | 569 } |
| 571 void CFX_WideString::TrimLeft(const FX_WCHAR* lpszTargets) { | 570 void CFX_WideString::TrimLeft(const FX_WCHAR* lpszTargets) { |
| 572 FXSYS_assert(lpszTargets); | 571 FXSYS_assert(lpszTargets); |
| 573 if (m_pData == NULL || *lpszTargets == 0) { | 572 if (!m_pData || *lpszTargets == 0) { |
| 574 return; | 573 return; |
| 575 } | 574 } |
| 576 CopyBeforeWrite(); | 575 CopyBeforeWrite(); |
| 577 if (GetLength() < 1) { | 576 if (GetLength() < 1) { |
| 578 return; | 577 return; |
| 579 } | 578 } |
| 580 const FX_WCHAR* lpsz = m_pData->m_String; | 579 const FX_WCHAR* lpsz = m_pData->m_String; |
| 581 while (*lpsz != 0) { | 580 while (*lpsz != 0) { |
| 582 if (FXSYS_wcschr(lpszTargets, *lpsz) == NULL) { | 581 if (!FXSYS_wcschr(lpszTargets, *lpsz)) { |
| 583 break; | 582 break; |
| 584 } | 583 } |
| 585 lpsz++; | 584 lpsz++; |
| 586 } | 585 } |
| 587 if (lpsz != m_pData->m_String) { | 586 if (lpsz != m_pData->m_String) { |
| 588 int nDataLength = | 587 int nDataLength = |
| 589 m_pData->m_nDataLength - (FX_STRSIZE)(lpsz - m_pData->m_String); | 588 m_pData->m_nDataLength - (FX_STRSIZE)(lpsz - m_pData->m_String); |
| 590 FXSYS_memmove(m_pData->m_String, lpsz, | 589 FXSYS_memmove(m_pData->m_String, lpsz, |
| 591 (nDataLength + 1) * sizeof(FX_WCHAR)); | 590 (nDataLength + 1) * sizeof(FX_WCHAR)); |
| 592 m_pData->m_nDataLength = nDataLength; | 591 m_pData->m_nDataLength = nDataLength; |
| 593 } | 592 } |
| 594 } | 593 } |
| 595 void CFX_WideString::TrimLeft(FX_WCHAR chTarget) { | 594 void CFX_WideString::TrimLeft(FX_WCHAR chTarget) { |
| 596 FX_WCHAR str[2] = {chTarget, 0}; | 595 FX_WCHAR str[2] = {chTarget, 0}; |
| 597 TrimLeft(str); | 596 TrimLeft(str); |
| 598 } | 597 } |
| 599 void CFX_WideString::TrimLeft() { | 598 void CFX_WideString::TrimLeft() { |
| 600 TrimLeft(L"\x09\x0a\x0b\x0c\x0d\x20"); | 599 TrimLeft(L"\x09\x0a\x0b\x0c\x0d\x20"); |
| 601 } | 600 } |
| 602 FX_STRSIZE CFX_WideString::Replace(const FX_WCHAR* lpszOld, | 601 FX_STRSIZE CFX_WideString::Replace(const FX_WCHAR* lpszOld, |
| 603 const FX_WCHAR* lpszNew) { | 602 const FX_WCHAR* lpszNew) { |
| 604 if (GetLength() < 1) { | 603 if (GetLength() < 1) { |
| 605 return 0; | 604 return 0; |
| 606 } | 605 } |
| 607 if (lpszOld == NULL) { | 606 if (!lpszOld) { |
| 608 return 0; | 607 return 0; |
| 609 } | 608 } |
| 610 FX_STRSIZE nSourceLen = FXSYS_wcslen(lpszOld); | 609 FX_STRSIZE nSourceLen = FXSYS_wcslen(lpszOld); |
| 611 if (nSourceLen == 0) { | 610 if (nSourceLen == 0) { |
| 612 return 0; | 611 return 0; |
| 613 } | 612 } |
| 614 FX_STRSIZE nReplacementLen = lpszNew ? FXSYS_wcslen(lpszNew) : 0; | 613 FX_STRSIZE nReplacementLen = lpszNew ? FXSYS_wcslen(lpszNew) : 0; |
| 615 FX_STRSIZE nCount = 0; | 614 FX_STRSIZE nCount = 0; |
| 616 FX_WCHAR* lpszStart = m_pData->m_String; | 615 FX_WCHAR* lpszStart = m_pData->m_String; |
| 617 FX_WCHAR* lpszEnd = m_pData->m_String + m_pData->m_nDataLength; | 616 FX_WCHAR* lpszEnd = m_pData->m_String + m_pData->m_nDataLength; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 FX_STRSIZE CFX_WideString::Insert(FX_STRSIZE nIndex, FX_WCHAR ch) { | 663 FX_STRSIZE CFX_WideString::Insert(FX_STRSIZE nIndex, FX_WCHAR ch) { |
| 665 CopyBeforeWrite(); | 664 CopyBeforeWrite(); |
| 666 if (nIndex < 0) { | 665 if (nIndex < 0) { |
| 667 nIndex = 0; | 666 nIndex = 0; |
| 668 } | 667 } |
| 669 FX_STRSIZE nNewLength = GetLength(); | 668 FX_STRSIZE nNewLength = GetLength(); |
| 670 if (nIndex > nNewLength) { | 669 if (nIndex > nNewLength) { |
| 671 nIndex = nNewLength; | 670 nIndex = nNewLength; |
| 672 } | 671 } |
| 673 nNewLength++; | 672 nNewLength++; |
| 674 if (m_pData == NULL || m_pData->m_nAllocLength < nNewLength) { | 673 if (!m_pData || m_pData->m_nAllocLength < nNewLength) { |
| 675 StringData* pOldData = m_pData; | 674 StringData* pOldData = m_pData; |
| 676 const FX_WCHAR* pstr = m_pData->m_String; | 675 const FX_WCHAR* pstr = m_pData->m_String; |
| 677 m_pData = StringData::Create(nNewLength); | 676 m_pData = StringData::Create(nNewLength); |
| 678 if (!m_pData) { | 677 if (!m_pData) { |
| 679 return 0; | 678 return 0; |
| 680 } | 679 } |
| 681 if (pOldData) { | 680 if (pOldData) { |
| 682 FXSYS_memmove(m_pData->m_String, pstr, | 681 FXSYS_memmove(m_pData->m_String, pstr, |
| 683 (pOldData->m_nDataLength + 1) * sizeof(FX_WCHAR)); | 682 (pOldData->m_nDataLength + 1) * sizeof(FX_WCHAR)); |
| 684 pOldData->Release(); | 683 pOldData->Release(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 704 CopyBeforeWrite(); | 703 CopyBeforeWrite(); |
| 705 int nBytesToCopy = nOldLength - (nIndex + nCount) + 1; | 704 int nBytesToCopy = nOldLength - (nIndex + nCount) + 1; |
| 706 FXSYS_memmove(m_pData->m_String + nIndex, | 705 FXSYS_memmove(m_pData->m_String + nIndex, |
| 707 m_pData->m_String + nIndex + nCount, | 706 m_pData->m_String + nIndex + nCount, |
| 708 nBytesToCopy * sizeof(FX_WCHAR)); | 707 nBytesToCopy * sizeof(FX_WCHAR)); |
| 709 m_pData->m_nDataLength = nOldLength - nCount; | 708 m_pData->m_nDataLength = nOldLength - nCount; |
| 710 } | 709 } |
| 711 return m_pData->m_nDataLength; | 710 return m_pData->m_nDataLength; |
| 712 } | 711 } |
| 713 FX_STRSIZE CFX_WideString::Remove(FX_WCHAR chRemove) { | 712 FX_STRSIZE CFX_WideString::Remove(FX_WCHAR chRemove) { |
| 714 if (m_pData == NULL) { | 713 if (!m_pData) { |
| 715 return 0; | 714 return 0; |
| 716 } | 715 } |
| 717 CopyBeforeWrite(); | 716 CopyBeforeWrite(); |
| 718 if (GetLength() < 1) { | 717 if (GetLength() < 1) { |
| 719 return 0; | 718 return 0; |
| 720 } | 719 } |
| 721 FX_WCHAR* pstrSource = m_pData->m_String; | 720 FX_WCHAR* pstrSource = m_pData->m_String; |
| 722 FX_WCHAR* pstrDest = m_pData->m_String; | 721 FX_WCHAR* pstrDest = m_pData->m_String; |
| 723 FX_WCHAR* pstrEnd = m_pData->m_String + m_pData->m_nDataLength; | 722 FX_WCHAR* pstrEnd = m_pData->m_String + m_pData->m_nDataLength; |
| 724 while (pstrSource < pstrEnd) { | 723 while (pstrSource < pstrEnd) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 nItemLen = 2; | 823 nItemLen = 2; |
| 825 va_arg(argList, int); | 824 va_arg(argList, int); |
| 826 break; | 825 break; |
| 827 case 'c' | FORCE_UNICODE: | 826 case 'c' | FORCE_UNICODE: |
| 828 case 'C' | FORCE_UNICODE: | 827 case 'C' | FORCE_UNICODE: |
| 829 nItemLen = 2; | 828 nItemLen = 2; |
| 830 va_arg(argList, int); | 829 va_arg(argList, int); |
| 831 break; | 830 break; |
| 832 case 's': { | 831 case 's': { |
| 833 const FX_WCHAR* pstrNextArg = va_arg(argList, const FX_WCHAR*); | 832 const FX_WCHAR* pstrNextArg = va_arg(argList, const FX_WCHAR*); |
| 834 if (pstrNextArg == NULL) { | 833 if (pstrNextArg) { |
| 835 nItemLen = 6; | |
| 836 } else { | |
| 837 nItemLen = FXSYS_wcslen(pstrNextArg); | 834 nItemLen = FXSYS_wcslen(pstrNextArg); |
| 838 if (nItemLen < 1) { | 835 if (nItemLen < 1) { |
| 839 nItemLen = 1; | 836 nItemLen = 1; |
| 840 } | 837 } |
| 838 } else { |
| 839 nItemLen = 6; |
| 841 } | 840 } |
| 842 } break; | 841 } break; |
| 843 case 'S': { | 842 case 'S': { |
| 844 const FX_CHAR* pstrNextArg = va_arg(argList, const FX_CHAR*); | 843 const FX_CHAR* pstrNextArg = va_arg(argList, const FX_CHAR*); |
| 845 if (pstrNextArg == NULL) { | 844 if (pstrNextArg) { |
| 846 nItemLen = 6; | |
| 847 } else { | |
| 848 nItemLen = FXSYS_strlen(pstrNextArg); | 845 nItemLen = FXSYS_strlen(pstrNextArg); |
| 849 if (nItemLen < 1) { | 846 if (nItemLen < 1) { |
| 850 nItemLen = 1; | 847 nItemLen = 1; |
| 851 } | 848 } |
| 849 } else { |
| 850 nItemLen = 6; |
| 852 } | 851 } |
| 853 } break; | 852 } break; |
| 854 case 's' | FORCE_ANSI: | 853 case 's' | FORCE_ANSI: |
| 855 case 'S' | FORCE_ANSI: { | 854 case 'S' | FORCE_ANSI: { |
| 856 const FX_CHAR* pstrNextArg = va_arg(argList, const FX_CHAR*); | 855 const FX_CHAR* pstrNextArg = va_arg(argList, const FX_CHAR*); |
| 857 if (pstrNextArg == NULL) { | 856 if (pstrNextArg) { |
| 858 nItemLen = 6; | |
| 859 } else { | |
| 860 nItemLen = FXSYS_strlen(pstrNextArg); | 857 nItemLen = FXSYS_strlen(pstrNextArg); |
| 861 if (nItemLen < 1) { | 858 if (nItemLen < 1) { |
| 862 nItemLen = 1; | 859 nItemLen = 1; |
| 863 } | 860 } |
| 861 } else { |
| 862 nItemLen = 6; |
| 864 } | 863 } |
| 865 } break; | 864 } break; |
| 866 case 's' | FORCE_UNICODE: | 865 case 's' | FORCE_UNICODE: |
| 867 case 'S' | FORCE_UNICODE: { | 866 case 'S' | FORCE_UNICODE: { |
| 868 FX_WCHAR* pstrNextArg = va_arg(argList, FX_WCHAR*); | 867 FX_WCHAR* pstrNextArg = va_arg(argList, FX_WCHAR*); |
| 869 if (pstrNextArg == NULL) { | 868 if (pstrNextArg) { |
| 870 nItemLen = 6; | |
| 871 } else { | |
| 872 nItemLen = FXSYS_wcslen(pstrNextArg); | 869 nItemLen = FXSYS_wcslen(pstrNextArg); |
| 873 if (nItemLen < 1) { | 870 if (nItemLen < 1) { |
| 874 nItemLen = 1; | 871 nItemLen = 1; |
| 875 } | 872 } |
| 873 } else { |
| 874 nItemLen = 6; |
| 876 } | 875 } |
| 877 } break; | 876 } break; |
| 878 } | 877 } |
| 879 if (nItemLen != 0) { | 878 if (nItemLen != 0) { |
| 880 if (nPrecision != 0 && nItemLen > nPrecision) { | 879 if (nPrecision != 0 && nItemLen > nPrecision) { |
| 881 nItemLen = nPrecision; | 880 nItemLen = nPrecision; |
| 882 } | 881 } |
| 883 if (nItemLen < nWidth) { | 882 if (nItemLen < nWidth) { |
| 884 nItemLen = nWidth; | 883 nItemLen = nWidth; |
| 885 } | 884 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 while (cc < len) { | 979 while (cc < len) { |
| 981 fraction += scale * FXSYS_toDecimalDigitWide(str[cc]); | 980 fraction += scale * FXSYS_toDecimalDigitWide(str[cc]); |
| 982 scale *= 0.1f; | 981 scale *= 0.1f; |
| 983 cc++; | 982 cc++; |
| 984 } | 983 } |
| 985 } | 984 } |
| 986 fraction += (FX_FLOAT)integer; | 985 fraction += (FX_FLOAT)integer; |
| 987 return bNegative ? -fraction : fraction; | 986 return bNegative ? -fraction : fraction; |
| 988 } | 987 } |
| 989 int CFX_WideString::GetInteger() const { | 988 int CFX_WideString::GetInteger() const { |
| 990 if (m_pData == NULL) { | 989 return m_pData ? FXSYS_wtoi(m_pData->m_String) : 0; |
| 991 return 0; | |
| 992 } | |
| 993 return FXSYS_wtoi(m_pData->m_String); | |
| 994 } | 990 } |
| 995 FX_FLOAT CFX_WideString::GetFloat() const { | 991 FX_FLOAT CFX_WideString::GetFloat() const { |
| 996 if (m_pData == NULL) { | 992 return m_pData ? FX_wtof(m_pData->m_String, m_pData->m_nDataLength) : 0.0; |
| 997 return 0.0; | |
| 998 } | |
| 999 return FX_wtof(m_pData->m_String, m_pData->m_nDataLength); | |
| 1000 } | 993 } |
| 1001 static CFX_ByteString _DefMap_GetByteString(CFX_CharMap* pCharMap, | 994 static CFX_ByteString _DefMap_GetByteString(CFX_CharMap* pCharMap, |
| 1002 const CFX_WideString& widestr) { | 995 const CFX_WideString& widestr) { |
| 1003 int src_len = widestr.GetLength(); | 996 int src_len = widestr.GetLength(); |
| 1004 int codepage = pCharMap->m_GetCodePage ? pCharMap->m_GetCodePage() : 0; | 997 int codepage = pCharMap->m_GetCodePage ? pCharMap->m_GetCodePage() : 0; |
| 1005 int dest_len = FXSYS_WideCharToMultiByte(codepage, 0, widestr.c_str(), | 998 int dest_len = FXSYS_WideCharToMultiByte(codepage, 0, widestr.c_str(), |
| 1006 src_len, NULL, 0, NULL, NULL); | 999 src_len, NULL, 0, NULL, NULL); |
| 1007 if (dest_len == 0) { | 1000 if (dest_len == 0) { |
| 1008 return CFX_ByteString(); | 1001 return CFX_ByteString(); |
| 1009 } | 1002 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 return (CFX_CharMap*)&g_DefaultJISMapper; | 1052 return (CFX_CharMap*)&g_DefaultJISMapper; |
| 1060 case 936: | 1053 case 936: |
| 1061 return (CFX_CharMap*)&g_DefaultGBKMapper; | 1054 return (CFX_CharMap*)&g_DefaultGBKMapper; |
| 1062 case 949: | 1055 case 949: |
| 1063 return (CFX_CharMap*)&g_DefaultUHCMapper; | 1056 return (CFX_CharMap*)&g_DefaultUHCMapper; |
| 1064 case 950: | 1057 case 950: |
| 1065 return (CFX_CharMap*)&g_DefaultBig5Mapper; | 1058 return (CFX_CharMap*)&g_DefaultBig5Mapper; |
| 1066 } | 1059 } |
| 1067 return NULL; | 1060 return NULL; |
| 1068 } | 1061 } |
| OLD | NEW |