| 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 == NULL || 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 != NULL) { | 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); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 return -1; | 533 return -1; |
| 534 } | 534 } |
| 535 FX_STRSIZE nLength = m_pData->m_nDataLength; | 535 FX_STRSIZE nLength = m_pData->m_nDataLength; |
| 536 if (nStart >= nLength) { | 536 if (nStart >= nLength) { |
| 537 return -1; | 537 return -1; |
| 538 } | 538 } |
| 539 const FX_WCHAR* lpsz = FXSYS_wcschr(m_pData->m_String + nStart, ch); | 539 const FX_WCHAR* lpsz = FXSYS_wcschr(m_pData->m_String + nStart, ch); |
| 540 return (lpsz == NULL) ? -1 : (int)(lpsz - m_pData->m_String); | 540 return (lpsz == NULL) ? -1 : (int)(lpsz - m_pData->m_String); |
| 541 } | 541 } |
| 542 void CFX_WideString::TrimRight(const FX_WCHAR* lpszTargetList) { | 542 void CFX_WideString::TrimRight(const FX_WCHAR* lpszTargetList) { |
| 543 FXSYS_assert(lpszTargetList != NULL); | 543 FXSYS_assert(lpszTargetList); |
| 544 if (m_pData == NULL || *lpszTargetList == 0) { | 544 if (m_pData == NULL || *lpszTargetList == 0) { |
| 545 return; | 545 return; |
| 546 } | 546 } |
| 547 CopyBeforeWrite(); | 547 CopyBeforeWrite(); |
| 548 FX_STRSIZE len = GetLength(); | 548 FX_STRSIZE len = GetLength(); |
| 549 if (len < 1) { | 549 if (len < 1) { |
| 550 return; | 550 return; |
| 551 } | 551 } |
| 552 FX_STRSIZE pos = len; | 552 FX_STRSIZE pos = len; |
| 553 while (pos) { | 553 while (pos) { |
| 554 if (FXSYS_wcschr(lpszTargetList, m_pData->m_String[pos - 1]) == NULL) { | 554 if (FXSYS_wcschr(lpszTargetList, m_pData->m_String[pos - 1]) == NULL) { |
| 555 break; | 555 break; |
| 556 } | 556 } |
| 557 pos--; | 557 pos--; |
| 558 } | 558 } |
| 559 if (pos < len) { | 559 if (pos < len) { |
| 560 m_pData->m_String[pos] = 0; | 560 m_pData->m_String[pos] = 0; |
| 561 m_pData->m_nDataLength = pos; | 561 m_pData->m_nDataLength = pos; |
| 562 } | 562 } |
| 563 } | 563 } |
| 564 void CFX_WideString::TrimRight(FX_WCHAR chTarget) { | 564 void CFX_WideString::TrimRight(FX_WCHAR chTarget) { |
| 565 FX_WCHAR str[2] = {chTarget, 0}; | 565 FX_WCHAR str[2] = {chTarget, 0}; |
| 566 TrimRight(str); | 566 TrimRight(str); |
| 567 } | 567 } |
| 568 void CFX_WideString::TrimRight() { | 568 void CFX_WideString::TrimRight() { |
| 569 TrimRight(L"\x09\x0a\x0b\x0c\x0d\x20"); | 569 TrimRight(L"\x09\x0a\x0b\x0c\x0d\x20"); |
| 570 } | 570 } |
| 571 void CFX_WideString::TrimLeft(const FX_WCHAR* lpszTargets) { | 571 void CFX_WideString::TrimLeft(const FX_WCHAR* lpszTargets) { |
| 572 FXSYS_assert(lpszTargets != NULL); | 572 FXSYS_assert(lpszTargets); |
| 573 if (m_pData == NULL || *lpszTargets == 0) { | 573 if (m_pData == NULL || *lpszTargets == 0) { |
| 574 return; | 574 return; |
| 575 } | 575 } |
| 576 CopyBeforeWrite(); | 576 CopyBeforeWrite(); |
| 577 if (GetLength() < 1) { | 577 if (GetLength() < 1) { |
| 578 return; | 578 return; |
| 579 } | 579 } |
| 580 const FX_WCHAR* lpsz = m_pData->m_String; | 580 const FX_WCHAR* lpsz = m_pData->m_String; |
| 581 while (*lpsz != 0) { | 581 while (*lpsz != 0) { |
| 582 if (FXSYS_wcschr(lpszTargets, *lpsz) == NULL) { | 582 if (FXSYS_wcschr(lpszTargets, *lpsz) == NULL) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 610 FX_STRSIZE nSourceLen = FXSYS_wcslen(lpszOld); | 610 FX_STRSIZE nSourceLen = FXSYS_wcslen(lpszOld); |
| 611 if (nSourceLen == 0) { | 611 if (nSourceLen == 0) { |
| 612 return 0; | 612 return 0; |
| 613 } | 613 } |
| 614 FX_STRSIZE nReplacementLen = lpszNew ? FXSYS_wcslen(lpszNew) : 0; | 614 FX_STRSIZE nReplacementLen = lpszNew ? FXSYS_wcslen(lpszNew) : 0; |
| 615 FX_STRSIZE nCount = 0; | 615 FX_STRSIZE nCount = 0; |
| 616 FX_WCHAR* lpszStart = m_pData->m_String; | 616 FX_WCHAR* lpszStart = m_pData->m_String; |
| 617 FX_WCHAR* lpszEnd = m_pData->m_String + m_pData->m_nDataLength; | 617 FX_WCHAR* lpszEnd = m_pData->m_String + m_pData->m_nDataLength; |
| 618 FX_WCHAR* lpszTarget; | 618 FX_WCHAR* lpszTarget; |
| 619 { | 619 { |
| 620 while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) != NULL && | 620 while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) && |
| 621 lpszStart < lpszEnd) { | 621 lpszStart < lpszEnd) { |
| 622 nCount++; | 622 nCount++; |
| 623 lpszStart = lpszTarget + nSourceLen; | 623 lpszStart = lpszTarget + nSourceLen; |
| 624 } | 624 } |
| 625 } | 625 } |
| 626 if (nCount > 0) { | 626 if (nCount > 0) { |
| 627 CopyBeforeWrite(); | 627 CopyBeforeWrite(); |
| 628 FX_STRSIZE nOldLength = m_pData->m_nDataLength; | 628 FX_STRSIZE nOldLength = m_pData->m_nDataLength; |
| 629 FX_STRSIZE nNewLength = | 629 FX_STRSIZE nNewLength = |
| 630 nOldLength + (nReplacementLen - nSourceLen) * nCount; | 630 nOldLength + (nReplacementLen - nSourceLen) * nCount; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 nIndex = nNewLength; | 671 nIndex = nNewLength; |
| 672 } | 672 } |
| 673 nNewLength++; | 673 nNewLength++; |
| 674 if (m_pData == NULL || m_pData->m_nAllocLength < nNewLength) { | 674 if (m_pData == NULL || m_pData->m_nAllocLength < nNewLength) { |
| 675 StringData* pOldData = m_pData; | 675 StringData* pOldData = m_pData; |
| 676 const FX_WCHAR* pstr = m_pData->m_String; | 676 const FX_WCHAR* pstr = m_pData->m_String; |
| 677 m_pData = StringData::Create(nNewLength); | 677 m_pData = StringData::Create(nNewLength); |
| 678 if (!m_pData) { | 678 if (!m_pData) { |
| 679 return 0; | 679 return 0; |
| 680 } | 680 } |
| 681 if (pOldData != NULL) { | 681 if (pOldData) { |
| 682 FXSYS_memmove(m_pData->m_String, pstr, | 682 FXSYS_memmove(m_pData->m_String, pstr, |
| 683 (pOldData->m_nDataLength + 1) * sizeof(FX_WCHAR)); | 683 (pOldData->m_nDataLength + 1) * sizeof(FX_WCHAR)); |
| 684 pOldData->Release(); | 684 pOldData->Release(); |
| 685 } else { | 685 } else { |
| 686 m_pData->m_String[0] = 0; | 686 m_pData->m_String[0] = 0; |
| 687 } | 687 } |
| 688 } | 688 } |
| 689 FXSYS_memmove(m_pData->m_String + nIndex + 1, m_pData->m_String + nIndex, | 689 FXSYS_memmove(m_pData->m_String + nIndex + 1, m_pData->m_String + nIndex, |
| 690 (nNewLength - nIndex) * sizeof(FX_WCHAR)); | 690 (nNewLength - nIndex) * sizeof(FX_WCHAR)); |
| 691 m_pData->m_String[nIndex] = ch; | 691 m_pData->m_String[nIndex] = ch; |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 return (CFX_CharMap*)&g_DefaultJISMapper; | 1059 return (CFX_CharMap*)&g_DefaultJISMapper; |
| 1060 case 936: | 1060 case 936: |
| 1061 return (CFX_CharMap*)&g_DefaultGBKMapper; | 1061 return (CFX_CharMap*)&g_DefaultGBKMapper; |
| 1062 case 949: | 1062 case 949: |
| 1063 return (CFX_CharMap*)&g_DefaultUHCMapper; | 1063 return (CFX_CharMap*)&g_DefaultUHCMapper; |
| 1064 case 950: | 1064 case 950: |
| 1065 return (CFX_CharMap*)&g_DefaultBig5Mapper; | 1065 return (CFX_CharMap*)&g_DefaultBig5Mapper; |
| 1066 } | 1066 } |
| 1067 return NULL; | 1067 return NULL; |
| 1068 } | 1068 } |
| OLD | NEW |