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

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

Issue 1171733003: Remove typdefs for pointer types in fx_system.h (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Manual fixes. Created 5 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
« no previous file with comments | « core/src/fxcrt/fx_basic_util.cpp ('k') | core/src/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> // For offsetof(). 7 #include <stddef.h> // For offsetof().
8 8
9 #include "../../include/fxcrt/fx_basic.h" 9 #include "../../include/fxcrt/fx_basic.h"
10 #include "../../../third_party/base/numerics/safe_math.h" 10 #include "../../../third_party/base/numerics/safe_math.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 return; 49 return;
50 } 50 }
51 if (stringSrc.m_pData->m_nRefs >= 0) { 51 if (stringSrc.m_pData->m_nRefs >= 0) {
52 m_pData = stringSrc.m_pData; 52 m_pData = stringSrc.m_pData;
53 m_pData->Retain(); 53 m_pData->Retain();
54 } else { 54 } else {
55 m_pData = NULL; 55 m_pData = NULL;
56 *this = stringSrc; 56 *this = stringSrc;
57 } 57 }
58 } 58 }
59 CFX_WideString::CFX_WideString(FX_LPCWSTR lpsz, FX_STRSIZE nLen) { 59 CFX_WideString::CFX_WideString(const FX_WCHAR* lpsz, FX_STRSIZE nLen) {
60 if (nLen < 0) { 60 if (nLen < 0) {
61 nLen = lpsz ? FXSYS_wcslen(lpsz) : 0; 61 nLen = lpsz ? FXSYS_wcslen(lpsz) : 0;
62 } 62 }
63 if (nLen) { 63 if (nLen) {
64 m_pData = StringData::Create(nLen); 64 m_pData = StringData::Create(nLen);
65 if (m_pData) { 65 if (m_pData) {
66 FXSYS_memcpy32(m_pData->m_String, lpsz, nLen * sizeof(FX_WCHAR)); 66 FXSYS_memcpy32(m_pData->m_String, lpsz, nLen * sizeof(FX_WCHAR));
67 } 67 }
68 } else { 68 } else {
69 m_pData = NULL; 69 m_pData = NULL;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 nNewLength = m_pData ? FXSYS_wcslen(m_pData->m_String) : 0; 110 nNewLength = m_pData ? FXSYS_wcslen(m_pData->m_String) : 0;
111 } 111 }
112 if (nNewLength == 0) { 112 if (nNewLength == 0) {
113 Empty(); 113 Empty();
114 return; 114 return;
115 } 115 }
116 FXSYS_assert(nNewLength <= m_pData->m_nAllocLength); 116 FXSYS_assert(nNewLength <= m_pData->m_nAllocLength);
117 m_pData->m_nDataLength = nNewLength; 117 m_pData->m_nDataLength = nNewLength;
118 m_pData->m_String[nNewLength] = 0; 118 m_pData->m_String[nNewLength] = 0;
119 } 119 }
120 const CFX_WideString& CFX_WideString::operator=(FX_LPCWSTR lpsz) 120 const CFX_WideString& CFX_WideString::operator=(const FX_WCHAR* lpsz)
121 { 121 {
122 if (lpsz == NULL || lpsz[0] == 0) { 122 if (lpsz == NULL || lpsz[0] == 0) {
123 Empty(); 123 Empty();
124 } else { 124 } else {
125 AssignCopy(FXSYS_wcslen(lpsz), lpsz); 125 AssignCopy(FXSYS_wcslen(lpsz), lpsz);
126 } 126 }
127 return *this; 127 return *this;
128 } 128 }
129 const CFX_WideString& CFX_WideString::operator=(const CFX_WideStringC& stringSrc ) 129 const CFX_WideString& CFX_WideString::operator=(const CFX_WideStringC& stringSrc )
130 { 130 {
(...skipping 21 matching lines...) Expand all
152 m_pData->Retain(); 152 m_pData->Retain();
153 } 153 }
154 } 154 }
155 return *this; 155 return *this;
156 } 156 }
157 const CFX_WideString& CFX_WideString::operator+=(FX_WCHAR ch) 157 const CFX_WideString& CFX_WideString::operator+=(FX_WCHAR ch)
158 { 158 {
159 ConcatInPlace(1, &ch); 159 ConcatInPlace(1, &ch);
160 return *this; 160 return *this;
161 } 161 }
162 const CFX_WideString& CFX_WideString::operator+=(FX_LPCWSTR lpsz) 162 const CFX_WideString& CFX_WideString::operator+=(const FX_WCHAR* lpsz)
163 { 163 {
164 if (lpsz) { 164 if (lpsz) {
165 ConcatInPlace(FXSYS_wcslen(lpsz), lpsz); 165 ConcatInPlace(FXSYS_wcslen(lpsz), lpsz);
166 } 166 }
167 return *this; 167 return *this;
168 } 168 }
169 const CFX_WideString& CFX_WideString::operator+=(const CFX_WideString& string) 169 const CFX_WideString& CFX_WideString::operator+=(const CFX_WideString& string)
170 { 170 {
171 if (string.m_pData == NULL) { 171 if (string.m_pData == NULL) {
172 return *this; 172 return *this;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 m_pData->m_String, 214 m_pData->m_String,
215 m_pData->m_nDataLength) == 0; 215 m_pData->m_nDataLength) == 0;
216 } 216 }
217 void CFX_WideString::Empty() 217 void CFX_WideString::Empty()
218 { 218 {
219 if (m_pData) { 219 if (m_pData) {
220 m_pData->Release(); 220 m_pData->Release();
221 m_pData = NULL; 221 m_pData = NULL;
222 } 222 }
223 } 223 }
224 void CFX_WideString::ConcatInPlace(FX_STRSIZE nSrcLen, FX_LPCWSTR lpszSrcData) 224 void CFX_WideString::ConcatInPlace(FX_STRSIZE nSrcLen, const FX_WCHAR* lpszSrcDa ta)
225 { 225 {
226 if (nSrcLen == 0 || lpszSrcData == NULL) { 226 if (nSrcLen == 0 || lpszSrcData == NULL) {
227 return; 227 return;
228 } 228 }
229 if (m_pData == NULL) { 229 if (m_pData == NULL) {
230 m_pData = StringData::Create(nSrcLen); 230 m_pData = StringData::Create(nSrcLen);
231 if (m_pData) { 231 if (m_pData) {
232 FXSYS_memcpy32(m_pData->m_String, lpszSrcData, nSrcLen * sizeof(FX_W CHAR)); 232 FXSYS_memcpy32(m_pData->m_String, lpszSrcData, nSrcLen * sizeof(FX_W CHAR));
233 } 233 }
234 return; 234 return;
235 } 235 }
236 if (m_pData->m_nRefs > 1 || m_pData->m_nDataLength + nSrcLen > m_pData->m_nA llocLength) { 236 if (m_pData->m_nRefs > 1 || m_pData->m_nDataLength + nSrcLen > m_pData->m_nA llocLength) {
237 ConcatCopy(m_pData->m_nDataLength, m_pData->m_String, nSrcLen, lpszSrcDa ta); 237 ConcatCopy(m_pData->m_nDataLength, m_pData->m_String, nSrcLen, lpszSrcDa ta);
238 } else { 238 } else {
239 FXSYS_memcpy32(m_pData->m_String + m_pData->m_nDataLength, lpszSrcData, nSrcLen * sizeof(FX_WCHAR)); 239 FXSYS_memcpy32(m_pData->m_String + m_pData->m_nDataLength, lpszSrcData, nSrcLen * sizeof(FX_WCHAR));
240 m_pData->m_nDataLength += nSrcLen; 240 m_pData->m_nDataLength += nSrcLen;
241 m_pData->m_String[m_pData->m_nDataLength] = 0; 241 m_pData->m_String[m_pData->m_nDataLength] = 0;
242 } 242 }
243 } 243 }
244 void CFX_WideString::ConcatCopy(FX_STRSIZE nSrc1Len, FX_LPCWSTR lpszSrc1Data, 244 void CFX_WideString::ConcatCopy(FX_STRSIZE nSrc1Len, const FX_WCHAR* lpszSrc1Dat a,
245 FX_STRSIZE nSrc2Len, FX_LPCWSTR lpszSrc2Data) 245 FX_STRSIZE nSrc2Len, const FX_WCHAR* lpszSrc2Dat a)
246 { 246 {
247 FX_STRSIZE nNewLen = nSrc1Len + nSrc2Len; 247 FX_STRSIZE nNewLen = nSrc1Len + nSrc2Len;
248 if (nNewLen <= 0) { 248 if (nNewLen <= 0) {
249 return; 249 return;
250 } 250 }
251 // Don't release until done copying, might be one of the arguments. 251 // Don't release until done copying, might be one of the arguments.
252 StringData* pOldData = m_pData; 252 StringData* pOldData = m_pData;
253 m_pData = StringData::Create(nNewLen); 253 m_pData = StringData::Create(nNewLen);
254 if (m_pData) { 254 if (m_pData) {
255 wmemcpy(m_pData->m_String, lpszSrc1Data, nSrc1Len); 255 wmemcpy(m_pData->m_String, lpszSrc1Data, nSrc1Len);
(...skipping 15 matching lines...) Expand all
271 } 271 }
272 } 272 }
273 void CFX_WideString::AllocBeforeWrite(FX_STRSIZE nLen) 273 void CFX_WideString::AllocBeforeWrite(FX_STRSIZE nLen)
274 { 274 {
275 if (m_pData && m_pData->m_nRefs <= 1 && m_pData->m_nAllocLength >= nLen) { 275 if (m_pData && m_pData->m_nRefs <= 1 && m_pData->m_nAllocLength >= nLen) {
276 return; 276 return;
277 } 277 }
278 Empty(); 278 Empty();
279 m_pData = StringData::Create(nLen); 279 m_pData = StringData::Create(nLen);
280 } 280 }
281 void CFX_WideString::AssignCopy(FX_STRSIZE nSrcLen, FX_LPCWSTR lpszSrcData) 281 void CFX_WideString::AssignCopy(FX_STRSIZE nSrcLen, const FX_WCHAR* lpszSrcData)
282 { 282 {
283 AllocBeforeWrite(nSrcLen); 283 AllocBeforeWrite(nSrcLen);
284 FXSYS_memcpy32(m_pData->m_String, lpszSrcData, nSrcLen * sizeof(FX_WCHAR)); 284 FXSYS_memcpy32(m_pData->m_String, lpszSrcData, nSrcLen * sizeof(FX_WCHAR));
285 m_pData->m_nDataLength = nSrcLen; 285 m_pData->m_nDataLength = nSrcLen;
286 m_pData->m_String[nSrcLen] = 0; 286 m_pData->m_String[nSrcLen] = 0;
287 } 287 }
288 int CFX_WideString::Compare(FX_LPCWSTR lpsz) const 288 int CFX_WideString::Compare(const FX_WCHAR* lpsz) const
289 { 289 {
290 if (m_pData == NULL) { 290 if (m_pData == NULL) {
291 return (lpsz == NULL || lpsz[0] == 0) ? 0 : -1; 291 return (lpsz == NULL || lpsz[0] == 0) ? 0 : -1;
292 } 292 }
293 return FXSYS_wcscmp(m_pData->m_String, lpsz); 293 return FXSYS_wcscmp(m_pData->m_String, lpsz);
294 } 294 }
295 CFX_ByteString CFX_WideString::UTF8Encode() const 295 CFX_ByteString CFX_WideString::UTF8Encode() const
296 { 296 {
297 return FX_UTF8Encode(*this); 297 return FX_UTF8Encode(*this);
298 } 298 }
299 CFX_ByteString CFX_WideString::UTF16LE_Encode() const 299 CFX_ByteString CFX_WideString::UTF16LE_Encode() const
300 { 300 {
301 if (m_pData == NULL) { 301 if (m_pData == NULL) {
302 return CFX_ByteString(FX_BSTRC("\0\0")); 302 return CFX_ByteString(FX_BSTRC("\0\0"));
303 } 303 }
304 int len = m_pData->m_nDataLength; 304 int len = m_pData->m_nDataLength;
305 CFX_ByteString result; 305 CFX_ByteString result;
306 FX_LPSTR buffer = result.GetBuffer(len * 2 + 2); 306 FX_CHAR* buffer = result.GetBuffer(len * 2 + 2);
307 for (int i = 0; i < len; i ++) { 307 for (int i = 0; i < len; i ++) {
308 buffer[i * 2] = m_pData->m_String[i] & 0xff; 308 buffer[i * 2] = m_pData->m_String[i] & 0xff;
309 buffer[i * 2 + 1] = m_pData->m_String[i] >> 8; 309 buffer[i * 2 + 1] = m_pData->m_String[i] >> 8;
310 } 310 }
311 buffer[len * 2] = 0; 311 buffer[len * 2] = 0;
312 buffer[len * 2 + 1] = 0; 312 buffer[len * 2 + 1] = 0;
313 result.ReleaseBuffer(len * 2 + 2); 313 result.ReleaseBuffer(len * 2 + 2);
314 return result; 314 return result;
315 } 315 }
316 void CFX_WideString::ConvertFrom(const CFX_ByteString& str, CFX_CharMap* pCharMa p) 316 void CFX_WideString::ConvertFrom(const CFX_ByteString& str, CFX_CharMap* pCharMa p)
317 { 317 {
318 if (pCharMap == NULL) { 318 if (pCharMap == NULL) {
319 pCharMap = CFX_CharMap::GetDefaultMapper(); 319 pCharMap = CFX_CharMap::GetDefaultMapper();
320 } 320 }
321 *this = pCharMap->m_GetWideString(pCharMap, str); 321 *this = pCharMap->m_GetWideString(pCharMap, str);
322 } 322 }
323 void CFX_WideString::Reserve(FX_STRSIZE len) 323 void CFX_WideString::Reserve(FX_STRSIZE len)
324 { 324 {
325 GetBuffer(len); 325 GetBuffer(len);
326 ReleaseBuffer(GetLength()); 326 ReleaseBuffer(GetLength());
327 } 327 }
328 FX_LPWSTR CFX_WideString::GetBuffer(FX_STRSIZE nMinBufLength) 328 FX_WCHAR* CFX_WideString::GetBuffer(FX_STRSIZE nMinBufLength)
329 { 329 {
330 if (m_pData == NULL && nMinBufLength == 0) { 330 if (m_pData == NULL && nMinBufLength == 0) {
331 return NULL; 331 return NULL;
332 } 332 }
333 if (m_pData && m_pData->m_nRefs <= 1 && m_pData->m_nAllocLength >= nMinBufLe ngth) { 333 if (m_pData && m_pData->m_nRefs <= 1 && m_pData->m_nAllocLength >= nMinBufLe ngth) {
334 return m_pData->m_String; 334 return m_pData->m_String;
335 } 335 }
336 if (m_pData == NULL) { 336 if (m_pData == NULL) {
337 m_pData = StringData::Create(nMinBufLength); 337 m_pData = StringData::Create(nMinBufLength);
338 if (!m_pData) { 338 if (!m_pData) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 if (nCount < 0) { 464 if (nCount < 0) {
465 nCount = 0; 465 nCount = 0;
466 } 466 }
467 if (nCount >= m_pData->m_nDataLength) { 467 if (nCount >= m_pData->m_nDataLength) {
468 return *this; 468 return *this;
469 } 469 }
470 CFX_WideString dest; 470 CFX_WideString dest;
471 AllocCopy(dest, nCount, m_pData->m_nDataLength - nCount); 471 AllocCopy(dest, nCount, m_pData->m_nDataLength - nCount);
472 return dest; 472 return dest;
473 } 473 }
474 int CFX_WideString::CompareNoCase(FX_LPCWSTR lpsz) const 474 int CFX_WideString::CompareNoCase(const FX_WCHAR* lpsz) const
475 { 475 {
476 if (m_pData == NULL) { 476 if (m_pData == NULL) {
477 return (lpsz == NULL || lpsz[0] == 0) ? 0 : -1; 477 return (lpsz == NULL || lpsz[0] == 0) ? 0 : -1;
478 } 478 }
479 return FXSYS_wcsicmp(m_pData->m_String, lpsz); 479 return FXSYS_wcsicmp(m_pData->m_String, lpsz);
480 } 480 }
481 int CFX_WideString::Compare(const CFX_WideString& str) const 481 int CFX_WideString::Compare(const CFX_WideString& str) const
482 { 482 {
483 if (m_pData == NULL) { 483 if (m_pData == NULL) {
484 if (str.m_pData == NULL) { 484 if (str.m_pData == NULL) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 { 530 {
531 if (m_pData == NULL) { 531 if (m_pData == NULL) {
532 return; 532 return;
533 } 533 }
534 CopyBeforeWrite(); 534 CopyBeforeWrite();
535 if (GetLength() < 1) { 535 if (GetLength() < 1) {
536 return; 536 return;
537 } 537 }
538 FXSYS_wcsupr(m_pData->m_String); 538 FXSYS_wcsupr(m_pData->m_String);
539 } 539 }
540 FX_STRSIZE CFX_WideString::Find(FX_LPCWSTR lpszSub, FX_STRSIZE nStart) const 540 FX_STRSIZE CFX_WideString::Find(const FX_WCHAR* lpszSub, FX_STRSIZE nStart) cons t
541 { 541 {
542 FX_STRSIZE nLength = GetLength(); 542 FX_STRSIZE nLength = GetLength();
543 if (nLength < 1 || nStart > nLength) { 543 if (nLength < 1 || nStart > nLength) {
544 return -1; 544 return -1;
545 } 545 }
546 FX_LPCWSTR lpsz = FXSYS_wcsstr(m_pData->m_String + nStart, lpszSub); 546 const FX_WCHAR* lpsz = FXSYS_wcsstr(m_pData->m_String + nStart, lpszSub);
547 return (lpsz == NULL) ? -1 : (int)(lpsz - m_pData->m_String); 547 return (lpsz == NULL) ? -1 : (int)(lpsz - m_pData->m_String);
548 } 548 }
549 FX_STRSIZE CFX_WideString::Find(FX_WCHAR ch, FX_STRSIZE nStart) const 549 FX_STRSIZE CFX_WideString::Find(FX_WCHAR ch, FX_STRSIZE nStart) const
550 { 550 {
551 if (m_pData == NULL) { 551 if (m_pData == NULL) {
552 return -1; 552 return -1;
553 } 553 }
554 FX_STRSIZE nLength = m_pData->m_nDataLength; 554 FX_STRSIZE nLength = m_pData->m_nDataLength;
555 if (nStart >= nLength) { 555 if (nStart >= nLength) {
556 return -1; 556 return -1;
557 } 557 }
558 FX_LPCWSTR lpsz = FXSYS_wcschr(m_pData->m_String + nStart, ch); 558 const FX_WCHAR* lpsz = FXSYS_wcschr(m_pData->m_String + nStart, ch);
559 return (lpsz == NULL) ? -1 : (int)(lpsz - m_pData->m_String); 559 return (lpsz == NULL) ? -1 : (int)(lpsz - m_pData->m_String);
560 } 560 }
561 void CFX_WideString::TrimRight(FX_LPCWSTR lpszTargetList) 561 void CFX_WideString::TrimRight(const FX_WCHAR* lpszTargetList)
562 { 562 {
563 FXSYS_assert(lpszTargetList != NULL); 563 FXSYS_assert(lpszTargetList != NULL);
564 if (m_pData == NULL || *lpszTargetList == 0) { 564 if (m_pData == NULL || *lpszTargetList == 0) {
565 return; 565 return;
566 } 566 }
567 CopyBeforeWrite(); 567 CopyBeforeWrite();
568 FX_STRSIZE len = GetLength(); 568 FX_STRSIZE len = GetLength();
569 if (len < 1) { 569 if (len < 1) {
570 return; 570 return;
571 } 571 }
(...skipping 11 matching lines...) Expand all
583 } 583 }
584 void CFX_WideString::TrimRight(FX_WCHAR chTarget) 584 void CFX_WideString::TrimRight(FX_WCHAR chTarget)
585 { 585 {
586 FX_WCHAR str[2] = {chTarget, 0}; 586 FX_WCHAR str[2] = {chTarget, 0};
587 TrimRight(str); 587 TrimRight(str);
588 } 588 }
589 void CFX_WideString::TrimRight() 589 void CFX_WideString::TrimRight()
590 { 590 {
591 TrimRight(L"\x09\x0a\x0b\x0c\x0d\x20"); 591 TrimRight(L"\x09\x0a\x0b\x0c\x0d\x20");
592 } 592 }
593 void CFX_WideString::TrimLeft(FX_LPCWSTR lpszTargets) 593 void CFX_WideString::TrimLeft(const FX_WCHAR* lpszTargets)
594 { 594 {
595 FXSYS_assert(lpszTargets != NULL); 595 FXSYS_assert(lpszTargets != NULL);
596 if (m_pData == NULL || *lpszTargets == 0) { 596 if (m_pData == NULL || *lpszTargets == 0) {
597 return; 597 return;
598 } 598 }
599 CopyBeforeWrite(); 599 CopyBeforeWrite();
600 if (GetLength() < 1) { 600 if (GetLength() < 1) {
601 return; 601 return;
602 } 602 }
603 FX_LPCWSTR lpsz = m_pData->m_String; 603 const FX_WCHAR* lpsz = m_pData->m_String;
604 while (*lpsz != 0) { 604 while (*lpsz != 0) {
605 if (FXSYS_wcschr(lpszTargets, *lpsz) == NULL) { 605 if (FXSYS_wcschr(lpszTargets, *lpsz) == NULL) {
606 break; 606 break;
607 } 607 }
608 lpsz ++; 608 lpsz ++;
609 } 609 }
610 if (lpsz != m_pData->m_String) { 610 if (lpsz != m_pData->m_String) {
611 int nDataLength = m_pData->m_nDataLength - (FX_STRSIZE)(lpsz - m_pData-> m_String); 611 int nDataLength = m_pData->m_nDataLength - (FX_STRSIZE)(lpsz - m_pData-> m_String);
612 FXSYS_memmove32(m_pData->m_String, lpsz, (nDataLength + 1)*sizeof(FX_WCH AR)); 612 FXSYS_memmove32(m_pData->m_String, lpsz, (nDataLength + 1)*sizeof(FX_WCH AR));
613 m_pData->m_nDataLength = nDataLength; 613 m_pData->m_nDataLength = nDataLength;
614 } 614 }
615 } 615 }
616 void CFX_WideString::TrimLeft(FX_WCHAR chTarget) 616 void CFX_WideString::TrimLeft(FX_WCHAR chTarget)
617 { 617 {
618 FX_WCHAR str[2] = {chTarget, 0}; 618 FX_WCHAR str[2] = {chTarget, 0};
619 TrimLeft(str); 619 TrimLeft(str);
620 } 620 }
621 void CFX_WideString::TrimLeft() 621 void CFX_WideString::TrimLeft()
622 { 622 {
623 TrimLeft(L"\x09\x0a\x0b\x0c\x0d\x20"); 623 TrimLeft(L"\x09\x0a\x0b\x0c\x0d\x20");
624 } 624 }
625 FX_STRSIZE CFX_WideString::Replace(FX_LPCWSTR lpszOld, FX_LPCWSTR lpszNew) 625 FX_STRSIZE CFX_WideString::Replace(const FX_WCHAR* lpszOld, const FX_WCHAR* lpsz New)
626 { 626 {
627 if (GetLength() < 1) { 627 if (GetLength() < 1) {
628 return 0; 628 return 0;
629 } 629 }
630 if (lpszOld == NULL) { 630 if (lpszOld == NULL) {
631 return 0; 631 return 0;
632 } 632 }
633 FX_STRSIZE nSourceLen = FXSYS_wcslen(lpszOld); 633 FX_STRSIZE nSourceLen = FXSYS_wcslen(lpszOld);
634 if (nSourceLen == 0) { 634 if (nSourceLen == 0) {
635 return 0; 635 return 0;
636 } 636 }
637 FX_STRSIZE nReplacementLen = lpszNew ? FXSYS_wcslen(lpszNew) : 0; 637 FX_STRSIZE nReplacementLen = lpszNew ? FXSYS_wcslen(lpszNew) : 0;
638 FX_STRSIZE nCount = 0; 638 FX_STRSIZE nCount = 0;
639 FX_LPWSTR lpszStart = m_pData->m_String; 639 FX_WCHAR* lpszStart = m_pData->m_String;
640 FX_LPWSTR lpszEnd = m_pData->m_String + m_pData->m_nDataLength; 640 FX_WCHAR* lpszEnd = m_pData->m_String + m_pData->m_nDataLength;
641 FX_LPWSTR lpszTarget; 641 FX_WCHAR* lpszTarget;
642 { 642 {
643 while ((lpszTarget = (FX_LPWSTR)FXSYS_wcsstr(lpszStart, lpszOld)) != NUL L && lpszStart < lpszEnd) { 643 while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) != NUL L && lpszStart < lpszEnd) {
644 nCount++; 644 nCount++;
645 lpszStart = lpszTarget + nSourceLen; 645 lpszStart = lpszTarget + nSourceLen;
646 } 646 }
647 } 647 }
648 if (nCount > 0) { 648 if (nCount > 0) {
649 CopyBeforeWrite(); 649 CopyBeforeWrite();
650 FX_STRSIZE nOldLength = m_pData->m_nDataLength; 650 FX_STRSIZE nOldLength = m_pData->m_nDataLength;
651 FX_STRSIZE nNewLength = nOldLength + (nReplacementLen - nSourceLen) * n Count; 651 FX_STRSIZE nNewLength = nOldLength + (nReplacementLen - nSourceLen) * n Count;
652 if (m_pData->m_nAllocLength < nNewLength || m_pData->m_nRefs > 1) { 652 if (m_pData->m_nAllocLength < nNewLength || m_pData->m_nRefs > 1) {
653 StringData* pOldData = m_pData; 653 StringData* pOldData = m_pData;
654 FX_LPCWSTR pstr = m_pData->m_String; 654 const FX_WCHAR* pstr = m_pData->m_String;
655 m_pData = StringData::Create(nNewLength); 655 m_pData = StringData::Create(nNewLength);
656 if (!m_pData) { 656 if (!m_pData) {
657 return 0; 657 return 0;
658 } 658 }
659 FXSYS_memcpy32(m_pData->m_String, pstr, pOldData->m_nDataLength * si zeof(FX_WCHAR)); 659 FXSYS_memcpy32(m_pData->m_String, pstr, pOldData->m_nDataLength * si zeof(FX_WCHAR));
660 pOldData->Release(); 660 pOldData->Release();
661 } 661 }
662 lpszStart = m_pData->m_String; 662 lpszStart = m_pData->m_String;
663 lpszEnd = m_pData->m_String + FX_MAX(m_pData->m_nDataLength, nNewLength) ; 663 lpszEnd = m_pData->m_String + FX_MAX(m_pData->m_nDataLength, nNewLength) ;
664 { 664 {
665 while ((lpszTarget = (FX_LPWSTR)FXSYS_wcsstr(lpszStart, lpszOld)) != NULL && lpszStart < lpszEnd) { 665 while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) != NULL && lpszStart < lpszEnd) {
666 FX_STRSIZE nBalance = nOldLength - (FX_STRSIZE)(lpszTarget - m_p Data->m_String + nSourceLen); 666 FX_STRSIZE nBalance = nOldLength - (FX_STRSIZE)(lpszTarget - m_p Data->m_String + nSourceLen);
667 FXSYS_memmove32(lpszTarget + nReplacementLen, lpszTarget + nSour ceLen, nBalance * sizeof(FX_WCHAR)); 667 FXSYS_memmove32(lpszTarget + nReplacementLen, lpszTarget + nSour ceLen, nBalance * sizeof(FX_WCHAR));
668 FXSYS_memcpy32(lpszTarget, lpszNew, nReplacementLen * sizeof(FX_ WCHAR)); 668 FXSYS_memcpy32(lpszTarget, lpszNew, nReplacementLen * sizeof(FX_ WCHAR));
669 lpszStart = lpszTarget + nReplacementLen; 669 lpszStart = lpszTarget + nReplacementLen;
670 lpszStart[nBalance] = 0; 670 lpszStart[nBalance] = 0;
671 nOldLength += (nReplacementLen - nSourceLen); 671 nOldLength += (nReplacementLen - nSourceLen);
672 } 672 }
673 } 673 }
674 ASSERT(m_pData->m_String[nNewLength] == 0); 674 ASSERT(m_pData->m_String[nNewLength] == 0);
675 m_pData->m_nDataLength = nNewLength; 675 m_pData->m_nDataLength = nNewLength;
676 } 676 }
677 return nCount; 677 return nCount;
678 } 678 }
679 FX_STRSIZE CFX_WideString::Insert(FX_STRSIZE nIndex, FX_WCHAR ch) 679 FX_STRSIZE CFX_WideString::Insert(FX_STRSIZE nIndex, FX_WCHAR ch)
680 { 680 {
681 CopyBeforeWrite(); 681 CopyBeforeWrite();
682 if (nIndex < 0) { 682 if (nIndex < 0) {
683 nIndex = 0; 683 nIndex = 0;
684 } 684 }
685 FX_STRSIZE nNewLength = GetLength(); 685 FX_STRSIZE nNewLength = GetLength();
686 if (nIndex > nNewLength) { 686 if (nIndex > nNewLength) {
687 nIndex = nNewLength; 687 nIndex = nNewLength;
688 } 688 }
689 nNewLength++; 689 nNewLength++;
690 if (m_pData == NULL || m_pData->m_nAllocLength < nNewLength) { 690 if (m_pData == NULL || m_pData->m_nAllocLength < nNewLength) {
691 StringData* pOldData = m_pData; 691 StringData* pOldData = m_pData;
692 FX_LPCWSTR pstr = m_pData->m_String; 692 const FX_WCHAR* pstr = m_pData->m_String;
693 m_pData = StringData::Create(nNewLength); 693 m_pData = StringData::Create(nNewLength);
694 if (!m_pData) { 694 if (!m_pData) {
695 return 0; 695 return 0;
696 } 696 }
697 if(pOldData != NULL) { 697 if(pOldData != NULL) {
698 FXSYS_memmove32(m_pData->m_String, pstr, (pOldData->m_nDataLength + 1)*sizeof(FX_WCHAR)); 698 FXSYS_memmove32(m_pData->m_String, pstr, (pOldData->m_nDataLength + 1)*sizeof(FX_WCHAR));
699 pOldData->Release(); 699 pOldData->Release();
700 } else { 700 } else {
701 m_pData->m_String[0] = 0; 701 m_pData->m_String[0] = 0;
702 } 702 }
(...skipping 24 matching lines...) Expand all
727 } 727 }
728 FX_STRSIZE CFX_WideString::Remove(FX_WCHAR chRemove) 728 FX_STRSIZE CFX_WideString::Remove(FX_WCHAR chRemove)
729 { 729 {
730 if (m_pData == NULL) { 730 if (m_pData == NULL) {
731 return 0; 731 return 0;
732 } 732 }
733 CopyBeforeWrite(); 733 CopyBeforeWrite();
734 if (GetLength() < 1) { 734 if (GetLength() < 1) {
735 return 0; 735 return 0;
736 } 736 }
737 FX_LPWSTR pstrSource = m_pData->m_String; 737 FX_WCHAR* pstrSource = m_pData->m_String;
738 FX_LPWSTR pstrDest = m_pData->m_String; 738 FX_WCHAR* pstrDest = m_pData->m_String;
739 FX_LPWSTR pstrEnd = m_pData->m_String + m_pData->m_nDataLength; 739 FX_WCHAR* pstrEnd = m_pData->m_String + m_pData->m_nDataLength;
740 while (pstrSource < pstrEnd) { 740 while (pstrSource < pstrEnd) {
741 if (*pstrSource != chRemove) { 741 if (*pstrSource != chRemove) {
742 *pstrDest = *pstrSource; 742 *pstrDest = *pstrSource;
743 pstrDest ++; 743 pstrDest ++;
744 } 744 }
745 pstrSource ++; 745 pstrSource ++;
746 } 746 }
747 *pstrDest = 0; 747 *pstrDest = 0;
748 FX_STRSIZE nCount = (FX_STRSIZE)(pstrSource - pstrDest); 748 FX_STRSIZE nCount = (FX_STRSIZE)(pstrSource - pstrDest);
749 m_pData->m_nDataLength -= nCount; 749 m_pData->m_nDataLength -= nCount;
750 return nCount; 750 return nCount;
751 } 751 }
752 #define FORCE_ANSI 0x10000 752 #define FORCE_ANSI 0x10000
753 #define FORCE_UNICODE 0x20000 753 #define FORCE_UNICODE 0x20000
754 #define FORCE_INT64 0x40000 754 #define FORCE_INT64 0x40000
755 void CFX_WideString::FormatV(FX_LPCWSTR lpszFormat, va_list argList) 755 void CFX_WideString::FormatV(const FX_WCHAR* lpszFormat, va_list argList)
756 { 756 {
757 va_list argListSave; 757 va_list argListSave;
758 #if defined(__ARMCC_VERSION) || (!defined(_MSC_VER) && (_FX_CPU_ == _FX_X64_ || _FX_CPU_ == _FX_IA64_ || _FX_CPU_ == _FX_ARM64_)) || defined(__native_client__) 758 #if defined(__ARMCC_VERSION) || (!defined(_MSC_VER) && (_FX_CPU_ == _FX_X64_ || _FX_CPU_ == _FX_IA64_ || _FX_CPU_ == _FX_ARM64_)) || defined(__native_client__)
759 va_copy(argListSave, argList); 759 va_copy(argListSave, argList);
760 #else 760 #else
761 argListSave = argList; 761 argListSave = argList;
762 #endif 762 #endif
763 int nMaxLen = 0; 763 int nMaxLen = 0;
764 for (FX_LPCWSTR lpsz = lpszFormat; *lpsz != 0; lpsz ++) { 764 for (const FX_WCHAR* lpsz = lpszFormat; *lpsz != 0; lpsz ++) {
765 if (*lpsz != '%' || *(lpsz = lpsz + 1) == '%') { 765 if (*lpsz != '%' || *(lpsz = lpsz + 1) == '%') {
766 nMaxLen += FXSYS_wcslen(lpsz); 766 nMaxLen += FXSYS_wcslen(lpsz);
767 continue; 767 continue;
768 } 768 }
769 int nItemLen = 0; 769 int nItemLen = 0;
770 int nWidth = 0; 770 int nWidth = 0;
771 for (; *lpsz != 0; lpsz ++) { 771 for (; *lpsz != 0; lpsz ++) {
772 if (*lpsz == '#') { 772 if (*lpsz == '#') {
773 nMaxLen += 2; 773 nMaxLen += 2;
774 } else if (*lpsz == '*') { 774 } else if (*lpsz == '*') {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 case 'C'|FORCE_ANSI: 838 case 'C'|FORCE_ANSI:
839 nItemLen = 2; 839 nItemLen = 2;
840 va_arg(argList, int); 840 va_arg(argList, int);
841 break; 841 break;
842 case 'c'|FORCE_UNICODE: 842 case 'c'|FORCE_UNICODE:
843 case 'C'|FORCE_UNICODE: 843 case 'C'|FORCE_UNICODE:
844 nItemLen = 2; 844 nItemLen = 2;
845 va_arg(argList, int); 845 va_arg(argList, int);
846 break; 846 break;
847 case 's': { 847 case 's': {
848 FX_LPCWSTR pstrNextArg = va_arg(argList, FX_LPCWSTR); 848 const FX_WCHAR* pstrNextArg = va_arg(argList, const FX_WCHAR *);
849 if (pstrNextArg == NULL) { 849 if (pstrNextArg == NULL) {
850 nItemLen = 6; 850 nItemLen = 6;
851 } else { 851 } else {
852 nItemLen = FXSYS_wcslen(pstrNextArg); 852 nItemLen = FXSYS_wcslen(pstrNextArg);
853 if (nItemLen < 1) { 853 if (nItemLen < 1) {
854 nItemLen = 1; 854 nItemLen = 1;
855 } 855 }
856 } 856 }
857 } 857 }
858 break; 858 break;
859 case 'S': { 859 case 'S': {
860 FX_LPCSTR pstrNextArg = va_arg(argList, FX_LPCSTR); 860 const FX_CHAR* pstrNextArg = va_arg(argList, const FX_CHAR*) ;
861 if (pstrNextArg == NULL) { 861 if (pstrNextArg == NULL) {
862 nItemLen = 6; 862 nItemLen = 6;
863 } else { 863 } else {
864 nItemLen = FXSYS_strlen(pstrNextArg); 864 nItemLen = FXSYS_strlen(pstrNextArg);
865 if (nItemLen < 1) { 865 if (nItemLen < 1) {
866 nItemLen = 1; 866 nItemLen = 1;
867 } 867 }
868 } 868 }
869 } 869 }
870 break; 870 break;
871 case 's'|FORCE_ANSI: 871 case 's'|FORCE_ANSI:
872 case 'S'|FORCE_ANSI: { 872 case 'S'|FORCE_ANSI: {
873 FX_LPCSTR pstrNextArg = va_arg(argList, FX_LPCSTR); 873 const FX_CHAR* pstrNextArg = va_arg(argList, const FX_CHAR*) ;
874 if (pstrNextArg == NULL) { 874 if (pstrNextArg == NULL) {
875 nItemLen = 6; 875 nItemLen = 6;
876 } else { 876 } else {
877 nItemLen = FXSYS_strlen(pstrNextArg); 877 nItemLen = FXSYS_strlen(pstrNextArg);
878 if (nItemLen < 1) { 878 if (nItemLen < 1) {
879 nItemLen = 1; 879 nItemLen = 1;
880 } 880 }
881 } 881 }
882 } 882 }
883 break; 883 break;
884 case 's'|FORCE_UNICODE: 884 case 's'|FORCE_UNICODE:
885 case 'S'|FORCE_UNICODE: { 885 case 'S'|FORCE_UNICODE: {
886 FX_LPWSTR pstrNextArg = va_arg(argList, FX_LPWSTR); 886 FX_WCHAR* pstrNextArg = va_arg(argList, FX_WCHAR*);
887 if (pstrNextArg == NULL) { 887 if (pstrNextArg == NULL) {
888 nItemLen = 6; 888 nItemLen = 6;
889 } else { 889 } else {
890 nItemLen = FXSYS_wcslen(pstrNextArg); 890 nItemLen = FXSYS_wcslen(pstrNextArg);
891 if (nItemLen < 1) { 891 if (nItemLen < 1) {
892 nItemLen = 1; 892 nItemLen = 1;
893 } 893 }
894 } 894 }
895 } 895 }
896 break; 896 break;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 } 957 }
958 nMaxLen += nItemLen; 958 nMaxLen += nItemLen;
959 } 959 }
960 GetBuffer(nMaxLen); 960 GetBuffer(nMaxLen);
961 if (m_pData) { 961 if (m_pData) {
962 FXSYS_vswprintf((wchar_t*)m_pData->m_String, nMaxLen + 1, (const wchar_t *)lpszFormat, argListSave); 962 FXSYS_vswprintf((wchar_t*)m_pData->m_String, nMaxLen + 1, (const wchar_t *)lpszFormat, argListSave);
963 ReleaseBuffer(); 963 ReleaseBuffer();
964 } 964 }
965 va_end(argListSave); 965 va_end(argListSave);
966 } 966 }
967 void CFX_WideString::Format(FX_LPCWSTR lpszFormat, ...) 967 void CFX_WideString::Format(const FX_WCHAR* lpszFormat, ...)
968 { 968 {
969 va_list argList; 969 va_list argList;
970 va_start(argList, lpszFormat); 970 va_start(argList, lpszFormat);
971 FormatV(lpszFormat, argList); 971 FormatV(lpszFormat, argList);
972 va_end(argList); 972 va_end(argList);
973 } 973 }
974 FX_FLOAT FX_wtof(FX_LPCWSTR str, int len) 974 FX_FLOAT FX_wtof(const FX_WCHAR* str, int len)
975 { 975 {
976 if (len == 0) { 976 if (len == 0) {
977 return 0.0; 977 return 0.0;
978 } 978 }
979 int cc = 0; 979 int cc = 0;
980 FX_BOOL bNegative = FALSE; 980 FX_BOOL bNegative = FALSE;
981 if (str[0] == '+') { 981 if (str[0] == '+') {
982 cc++; 982 cc++;
983 } else if (str[0] == '-') { 983 } else if (str[0] == '-') {
984 bNegative = TRUE; 984 bNegative = TRUE;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 } 1021 }
1022 static CFX_ByteString _DefMap_GetByteString(CFX_CharMap* pCharMap, const CFX_Wid eString& widestr) 1022 static CFX_ByteString _DefMap_GetByteString(CFX_CharMap* pCharMap, const CFX_Wid eString& widestr)
1023 { 1023 {
1024 int src_len = widestr.GetLength(); 1024 int src_len = widestr.GetLength();
1025 int codepage = pCharMap->m_GetCodePage ? pCharMap->m_GetCodePage() : 0; 1025 int codepage = pCharMap->m_GetCodePage ? pCharMap->m_GetCodePage() : 0;
1026 int dest_len = FXSYS_WideCharToMultiByte(codepage, 0, widestr.c_str(), src_l en, NULL, 0, NULL, NULL); 1026 int dest_len = FXSYS_WideCharToMultiByte(codepage, 0, widestr.c_str(), src_l en, NULL, 0, NULL, NULL);
1027 if (dest_len == 0) { 1027 if (dest_len == 0) {
1028 return CFX_ByteString(); 1028 return CFX_ByteString();
1029 } 1029 }
1030 CFX_ByteString bytestr; 1030 CFX_ByteString bytestr;
1031 FX_LPSTR dest_buf = bytestr.GetBuffer(dest_len); 1031 FX_CHAR* dest_buf = bytestr.GetBuffer(dest_len);
1032 FXSYS_WideCharToMultiByte(codepage, 0, widestr.c_str(), src_len, dest_buf, d est_len, NULL, NULL); 1032 FXSYS_WideCharToMultiByte(codepage, 0, widestr.c_str(), src_len, dest_buf, d est_len, NULL, NULL);
1033 bytestr.ReleaseBuffer(dest_len); 1033 bytestr.ReleaseBuffer(dest_len);
1034 return bytestr; 1034 return bytestr;
1035 } 1035 }
1036 static CFX_WideString _DefMap_GetWideString(CFX_CharMap* pCharMap, const CFX_Byt eString& bytestr) 1036 static CFX_WideString _DefMap_GetWideString(CFX_CharMap* pCharMap, const CFX_Byt eString& bytestr)
1037 { 1037 {
1038 int src_len = bytestr.GetLength(); 1038 int src_len = bytestr.GetLength();
1039 int codepage = pCharMap->m_GetCodePage ? pCharMap->m_GetCodePage() : 0; 1039 int codepage = pCharMap->m_GetCodePage ? pCharMap->m_GetCodePage() : 0;
1040 int dest_len = FXSYS_MultiByteToWideChar(codepage, 0, bytestr, src_len, NULL , 0); 1040 int dest_len = FXSYS_MultiByteToWideChar(codepage, 0, bytestr, src_len, NULL , 0);
1041 if (dest_len == 0) { 1041 if (dest_len == 0) {
1042 return CFX_WideString(); 1042 return CFX_WideString();
1043 } 1043 }
1044 CFX_WideString widestr; 1044 CFX_WideString widestr;
1045 FX_LPWSTR dest_buf = widestr.GetBuffer(dest_len); 1045 FX_WCHAR* dest_buf = widestr.GetBuffer(dest_len);
1046 FXSYS_MultiByteToWideChar(codepage, 0, bytestr, src_len, dest_buf, dest_len) ; 1046 FXSYS_MultiByteToWideChar(codepage, 0, bytestr, src_len, dest_buf, dest_len) ;
1047 widestr.ReleaseBuffer(dest_len); 1047 widestr.ReleaseBuffer(dest_len);
1048 return widestr; 1048 return widestr;
1049 } 1049 }
1050 static int _DefMap_GetGBKCodePage() 1050 static int _DefMap_GetGBKCodePage()
1051 { 1051 {
1052 return 936; 1052 return 936;
1053 } 1053 }
1054 static int _DefMap_GetUHCCodePage() 1054 static int _DefMap_GetUHCCodePage()
1055 { 1055 {
(...skipping 21 matching lines...) Expand all
1077 return (CFX_CharMap*)&g_DefaultJISMapper; 1077 return (CFX_CharMap*)&g_DefaultJISMapper;
1078 case 936: 1078 case 936:
1079 return (CFX_CharMap*)&g_DefaultGBKMapper; 1079 return (CFX_CharMap*)&g_DefaultGBKMapper;
1080 case 949: 1080 case 949:
1081 return (CFX_CharMap*)&g_DefaultUHCMapper; 1081 return (CFX_CharMap*)&g_DefaultUHCMapper;
1082 case 950: 1082 case 950:
1083 return (CFX_CharMap*)&g_DefaultBig5Mapper; 1083 return (CFX_CharMap*)&g_DefaultBig5Mapper;
1084 } 1084 }
1085 return NULL; 1085 return NULL;
1086 } 1086 }
OLDNEW
« no previous file with comments | « core/src/fxcrt/fx_basic_util.cpp ('k') | core/src/fxcrt/fx_extension.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698