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 #ifndef CORE_FXCRT_INCLUDE_FX_STRING_H_ | 7 #ifndef CORE_FXCRT_INCLUDE_FX_STRING_H_ |
8 #define CORE_FXCRT_INCLUDE_FX_STRING_H_ | 8 #define CORE_FXCRT_INCLUDE_FX_STRING_H_ |
9 | 9 |
10 #include <stdint.h> // For intptr_t. | 10 #include <stdint.h> // For intptr_t. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 return other.m_Length == m_Length && | 83 return other.m_Length == m_Length && |
84 FXSYS_memcmp(other.m_Ptr, m_Ptr, m_Length) == 0; | 84 FXSYS_memcmp(other.m_Ptr, m_Ptr, m_Length) == 0; |
85 } | 85 } |
86 bool operator!=(const char* ptr) const { return !(*this == ptr); } | 86 bool operator!=(const char* ptr) const { return !(*this == ptr); } |
87 bool operator!=(const CFX_ByteStringC& other) const { | 87 bool operator!=(const CFX_ByteStringC& other) const { |
88 return !(*this == other); | 88 return !(*this == other); |
89 } | 89 } |
90 | 90 |
91 uint32_t GetID(FX_STRSIZE start_pos = 0) const; | 91 uint32_t GetID(FX_STRSIZE start_pos = 0) const; |
92 | 92 |
93 const uint8_t* GetPtr() const { return m_Ptr; } | 93 const uint8_t* raw_str() const { return m_Ptr; } |
94 const FX_CHAR* GetCStr() const { return (const FX_CHAR*)m_Ptr; } | 94 const FX_CHAR* c_str() const { |
| 95 return reinterpret_cast<const FX_CHAR*>(m_Ptr); |
| 96 } |
95 | 97 |
96 FX_STRSIZE GetLength() const { return m_Length; } | 98 FX_STRSIZE GetLength() const { return m_Length; } |
97 bool IsEmpty() const { return m_Length == 0; } | 99 bool IsEmpty() const { return m_Length == 0; } |
98 | 100 |
99 uint8_t GetAt(FX_STRSIZE index) const { return m_Ptr[index]; } | 101 uint8_t GetAt(FX_STRSIZE index) const { return m_Ptr[index]; } |
100 | 102 |
101 CFX_ByteStringC Mid(FX_STRSIZE index, FX_STRSIZE count = -1) const { | 103 CFX_ByteStringC Mid(FX_STRSIZE index, FX_STRSIZE count = -1) const { |
102 if (index < 0) { | 104 if (index < 0) { |
103 index = 0; | 105 index = 0; |
104 } | 106 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 // Implicit conversion to C-style string -- deprecated. | 173 // Implicit conversion to C-style string -- deprecated. |
172 operator const FX_CHAR*() const { return m_pData ? m_pData->m_String : ""; } | 174 operator const FX_CHAR*() const { return m_pData ? m_pData->m_String : ""; } |
173 | 175 |
174 // Explicit conversion to uint8_t*. | 176 // Explicit conversion to uint8_t*. |
175 // Note: |this| must outlive the use of the result. | 177 // Note: |this| must outlive the use of the result. |
176 const uint8_t* raw_str() const { | 178 const uint8_t* raw_str() const { |
177 return m_pData ? reinterpret_cast<const uint8_t*>(m_pData->m_String) | 179 return m_pData ? reinterpret_cast<const uint8_t*>(m_pData->m_String) |
178 : nullptr; | 180 : nullptr; |
179 } | 181 } |
180 | 182 |
181 // Implicit conversiont to uint8_t* -- deprecated. | 183 // Implicit conversion to uint8_t* -- deprecated. |
182 operator const uint8_t*() const { | 184 operator const uint8_t*() const { |
183 return m_pData ? reinterpret_cast<const uint8_t*>(m_pData->m_String) | 185 return m_pData ? reinterpret_cast<const uint8_t*>(m_pData->m_String) |
184 : nullptr; | 186 : nullptr; |
185 } | 187 } |
186 | 188 |
187 // Explicit conversion to CFX_ByteStringC. | 189 // Explicit conversion to CFX_ByteStringC. |
188 // Note: |this| must outlive the use of the result. | 190 // Note: |this| must outlive the use of the result. |
189 CFX_ByteStringC AsByteStringC() const { | 191 CFX_ByteStringC AsByteStringC() const { |
190 return CFX_ByteStringC(raw_str(), GetLength()); | 192 return CFX_ByteStringC(raw_str(), GetLength()); |
191 } | 193 } |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 | 449 |
448 bool operator==(const wchar_t* ptr) const { | 450 bool operator==(const wchar_t* ptr) const { |
449 return FXSYS_wcslen(ptr) == m_Length && wmemcmp(ptr, m_Ptr, m_Length) == 0; | 451 return FXSYS_wcslen(ptr) == m_Length && wmemcmp(ptr, m_Ptr, m_Length) == 0; |
450 } | 452 } |
451 bool operator==(const CFX_WideStringC& str) const { | 453 bool operator==(const CFX_WideStringC& str) const { |
452 return str.m_Length == m_Length && wmemcmp(str.m_Ptr, m_Ptr, m_Length) == 0; | 454 return str.m_Length == m_Length && wmemcmp(str.m_Ptr, m_Ptr, m_Length) == 0; |
453 } | 455 } |
454 bool operator!=(const wchar_t* ptr) const { return !(*this == ptr); } | 456 bool operator!=(const wchar_t* ptr) const { return !(*this == ptr); } |
455 bool operator!=(const CFX_WideStringC& str) const { return !(*this == str); } | 457 bool operator!=(const CFX_WideStringC& str) const { return !(*this == str); } |
456 | 458 |
457 const FX_WCHAR* GetPtr() const { return m_Ptr; } | 459 const FX_WCHAR* raw_str() const { return m_Ptr; } |
458 | 460 |
459 FX_STRSIZE GetLength() const { return m_Length; } | 461 FX_STRSIZE GetLength() const { return m_Length; } |
460 bool IsEmpty() const { return m_Length == 0; } | 462 bool IsEmpty() const { return m_Length == 0; } |
461 | 463 |
462 FX_WCHAR GetAt(FX_STRSIZE index) const { return m_Ptr[index]; } | 464 FX_WCHAR GetAt(FX_STRSIZE index) const { return m_Ptr[index]; } |
463 | 465 |
464 CFX_WideStringC Left(FX_STRSIZE count) const { | 466 CFX_WideStringC Left(FX_STRSIZE count) const { |
465 if (count < 1) { | 467 if (count < 1) { |
466 return CFX_WideStringC(); | 468 return CFX_WideStringC(); |
467 } | 469 } |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 } | 747 } |
746 inline bool operator!=(const wchar_t* lhs, const CFX_WideString& rhs) { | 748 inline bool operator!=(const wchar_t* lhs, const CFX_WideString& rhs) { |
747 return rhs != lhs; | 749 return rhs != lhs; |
748 } | 750 } |
749 inline bool operator!=(const CFX_WideStringC& lhs, const CFX_WideString& rhs) { | 751 inline bool operator!=(const CFX_WideStringC& lhs, const CFX_WideString& rhs) { |
750 return rhs != lhs; | 752 return rhs != lhs; |
751 } | 753 } |
752 | 754 |
753 CFX_ByteString FX_UTF8Encode(const FX_WCHAR* pwsStr, FX_STRSIZE len); | 755 CFX_ByteString FX_UTF8Encode(const FX_WCHAR* pwsStr, FX_STRSIZE len); |
754 inline CFX_ByteString FX_UTF8Encode(const CFX_WideStringC& wsStr) { | 756 inline CFX_ByteString FX_UTF8Encode(const CFX_WideStringC& wsStr) { |
755 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); | 757 return FX_UTF8Encode(wsStr.raw_str(), wsStr.GetLength()); |
756 } | 758 } |
757 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString& wsStr) { | 759 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString& wsStr) { |
758 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); | 760 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); |
759 } | 761 } |
760 | 762 |
761 FX_FLOAT FX_atof(const CFX_ByteStringC& str); | 763 FX_FLOAT FX_atof(const CFX_ByteStringC& str); |
762 inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) { | 764 inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) { |
763 return FX_atof(FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()).c_str()); | 765 return FX_atof(FX_UTF8Encode(wsStr.raw_str(), wsStr.GetLength()).c_str()); |
764 } | 766 } |
765 void FX_atonum(const CFX_ByteStringC& str, FX_BOOL& bInteger, void* pData); | 767 void FX_atonum(const CFX_ByteStringC& str, FX_BOOL& bInteger, void* pData); |
766 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); | 768 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); |
767 | 769 |
768 #endif // CORE_FXCRT_INCLUDE_FX_STRING_H_ | 770 #endif // CORE_FXCRT_INCLUDE_FX_STRING_H_ |
OLD | NEW |