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 | 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 // Now round to an 8-byte boundary. We'd expect that this is the minimum | 66 // Now round to an 8-byte boundary. We'd expect that this is the minimum |
67 // granularity of any of the underlying allocators, so there may be cases | 67 // granularity of any of the underlying allocators, so there may be cases |
68 // where we can save a re-alloc when adding a few characters to a string | 68 // where we can save a re-alloc when adding a few characters to a string |
69 // by using this otherwise wasted space. | 69 // by using this otherwise wasted space. |
70 nSize += 7; | 70 nSize += 7; |
71 int totalSize = nSize.ValueOrDie() & ~7; | 71 int totalSize = nSize.ValueOrDie() & ~7; |
72 int usableSize = totalSize - overhead; | 72 int usableSize = totalSize - overhead; |
73 FXSYS_assert(usableSize >= nLen); | 73 FXSYS_assert(usableSize >= nLen); |
74 | 74 |
75 void* pData = FX_Alloc(FX_BYTE, totalSize); | 75 void* pData = FX_Alloc(uint8_t, totalSize); |
76 return new (pData) StringData(nLen, usableSize); | 76 return new (pData) StringData(nLen, usableSize); |
77 } | 77 } |
78 CFX_ByteString::~CFX_ByteString() | 78 CFX_ByteString::~CFX_ByteString() |
79 { | 79 { |
80 if (m_pData) { | 80 if (m_pData) { |
81 m_pData->Release(); | 81 m_pData->Release(); |
82 } | 82 } |
83 } | 83 } |
84 CFX_ByteString::CFX_ByteString(FX_LPCSTR lpsz, FX_STRSIZE nLen) | 84 CFX_ByteString::CFX_ByteString(FX_LPCSTR lpsz, FX_STRSIZE nLen) |
85 { | 85 { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 return str.IsEmpty(); | 277 return str.IsEmpty(); |
278 } | 278 } |
279 FX_STRSIZE len = str.GetLength(); | 279 FX_STRSIZE len = str.GetLength(); |
280 if (m_pData->m_nDataLength != len) { | 280 if (m_pData->m_nDataLength != len) { |
281 return false; | 281 return false; |
282 } | 282 } |
283 FX_LPCBYTE pThis = (FX_LPCBYTE)m_pData->m_String; | 283 FX_LPCBYTE pThis = (FX_LPCBYTE)m_pData->m_String; |
284 FX_LPCBYTE pThat = str.GetPtr(); | 284 FX_LPCBYTE pThat = str.GetPtr(); |
285 for (FX_STRSIZE i = 0; i < len; i ++) { | 285 for (FX_STRSIZE i = 0; i < len; i ++) { |
286 if ((*pThis) != (*pThat)) { | 286 if ((*pThis) != (*pThat)) { |
287 FX_BYTE bThis = *pThis; | 287 uint8_t bThis = *pThis; |
288 if (bThis >= 'A' && bThis <= 'Z') { | 288 if (bThis >= 'A' && bThis <= 'Z') { |
289 bThis += 'a' - 'A'; | 289 bThis += 'a' - 'A'; |
290 } | 290 } |
291 FX_BYTE bThat = *pThat; | 291 uint8_t bThat = *pThat; |
292 if (bThat >= 'A' && bThat <= 'Z') { | 292 if (bThat >= 'A' && bThat <= 'Z') { |
293 bThat += 'a' - 'A'; | 293 bThat += 'a' - 'A'; |
294 } | 294 } |
295 if (bThis != bThat) { | 295 if (bThis != bThat) { |
296 return false; | 296 return false; |
297 } | 297 } |
298 } | 298 } |
299 pThis ++; | 299 pThis ++; |
300 pThat ++; | 300 pThat ++; |
301 } | 301 } |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 } | 638 } |
639 } else { | 639 } else { |
640 switch (*lpsz) { | 640 switch (*lpsz) { |
641 case 'd': | 641 case 'd': |
642 case 'i': | 642 case 'i': |
643 case 'u': | 643 case 'u': |
644 case 'x': | 644 case 'x': |
645 case 'X': | 645 case 'X': |
646 case 'o': | 646 case 'o': |
647 if (nModifier & FORCE_INT64) { | 647 if (nModifier & FORCE_INT64) { |
648 va_arg(argList, FX_INT64); | 648 va_arg(argList, int64_t); |
649 } else { | 649 } else { |
650 va_arg(argList, int); | 650 va_arg(argList, int); |
651 } | 651 } |
652 nItemLen = 32; | 652 nItemLen = 32; |
653 if (nItemLen < nWidth + nPrecision) { | 653 if (nItemLen < nWidth + nPrecision) { |
654 nItemLen = nWidth + nPrecision; | 654 nItemLen = nWidth + nPrecision; |
655 } | 655 } |
656 break; | 656 break; |
657 case 'a': | 657 case 'a': |
658 case 'A': | 658 case 'A': |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 } | 929 } |
930 FXSYS_assert(nIndex >= 0); | 930 FXSYS_assert(nIndex >= 0); |
931 FXSYS_assert(nIndex < m_pData->m_nDataLength); | 931 FXSYS_assert(nIndex < m_pData->m_nDataLength); |
932 CopyBeforeWrite(); | 932 CopyBeforeWrite(); |
933 m_pData->m_String[nIndex] = ch; | 933 m_pData->m_String[nIndex] = ch; |
934 } | 934 } |
935 CFX_WideString CFX_ByteString::UTF8Decode() const | 935 CFX_WideString CFX_ByteString::UTF8Decode() const |
936 { | 936 { |
937 CFX_UTF8Decoder decoder; | 937 CFX_UTF8Decoder decoder; |
938 for (FX_STRSIZE i = 0; i < GetLength(); i ++) { | 938 for (FX_STRSIZE i = 0; i < GetLength(); i ++) { |
939 decoder.Input((FX_BYTE)m_pData->m_String[i]); | 939 decoder.Input((uint8_t)m_pData->m_String[i]); |
940 } | 940 } |
941 return decoder.GetResult(); | 941 return decoder.GetResult(); |
942 } | 942 } |
943 CFX_ByteString CFX_ByteString::FromUnicode(FX_LPCWSTR str, FX_STRSIZE len) | 943 CFX_ByteString CFX_ByteString::FromUnicode(FX_LPCWSTR str, FX_STRSIZE len) |
944 { | 944 { |
945 if (len < 0) { | 945 if (len < 0) { |
946 len = FXSYS_wcslen(str); | 946 len = FXSYS_wcslen(str); |
947 } | 947 } |
948 CFX_ByteString bstr; | 948 CFX_ByteString bstr; |
949 bstr.ConvertFrom(CFX_WideString(str, len)); | 949 bstr.ConvertFrom(CFX_WideString(str, len)); |
(...skipping 12 matching lines...) Expand all Loading... |
962 } | 962 } |
963 int CFX_ByteString::Compare(FX_BSTR str) const | 963 int CFX_ByteString::Compare(FX_BSTR str) const |
964 { | 964 { |
965 if (m_pData == NULL) { | 965 if (m_pData == NULL) { |
966 return str.IsEmpty() ? 0 : -1; | 966 return str.IsEmpty() ? 0 : -1; |
967 } | 967 } |
968 int this_len = m_pData->m_nDataLength; | 968 int this_len = m_pData->m_nDataLength; |
969 int that_len = str.GetLength(); | 969 int that_len = str.GetLength(); |
970 int min_len = this_len < that_len ? this_len : that_len; | 970 int min_len = this_len < that_len ? this_len : that_len; |
971 for (int i = 0; i < min_len; i ++) { | 971 for (int i = 0; i < min_len; i ++) { |
972 if ((FX_BYTE)m_pData->m_String[i] < str.GetAt(i)) { | 972 if ((uint8_t)m_pData->m_String[i] < str.GetAt(i)) { |
973 return -1; | 973 return -1; |
974 } else if ((FX_BYTE)m_pData->m_String[i] > str.GetAt(i)) { | 974 } else if ((uint8_t)m_pData->m_String[i] > str.GetAt(i)) { |
975 return 1; | 975 return 1; |
976 } | 976 } |
977 } | 977 } |
978 if (this_len < that_len) { | 978 if (this_len < that_len) { |
979 return -1; | 979 return -1; |
980 } else if (this_len > that_len) { | 980 } else if (this_len > that_len) { |
981 return 1; | 981 return 1; |
982 } | 982 } |
983 return 0; | 983 return 0; |
984 } | 984 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 scale /= 10; | 1124 scale /= 10; |
1125 } | 1125 } |
1126 return buf_size; | 1126 return buf_size; |
1127 } | 1127 } |
1128 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) | 1128 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) |
1129 { | 1129 { |
1130 FX_CHAR buf[32]; | 1130 FX_CHAR buf[32]; |
1131 FX_STRSIZE len = FX_ftoa(d, buf); | 1131 FX_STRSIZE len = FX_ftoa(d, buf); |
1132 return CFX_ByteString(buf, len); | 1132 return CFX_ByteString(buf, len); |
1133 } | 1133 } |
OLD | NEW |