| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 CFX_ByteStringC(const FX_CHAR* ptr, FX_STRSIZE len) { | 54 CFX_ByteStringC(const FX_CHAR* ptr, FX_STRSIZE len) { |
| 55 m_Ptr = (const uint8_t*)ptr; | 55 m_Ptr = (const uint8_t*)ptr; |
| 56 m_Length = (len == -1) ? FXSYS_strlen(ptr) : len; | 56 m_Length = (len == -1) ? FXSYS_strlen(ptr) : len; |
| 57 } | 57 } |
| 58 | 58 |
| 59 CFX_ByteStringC(const CFX_ByteStringC& src) { | 59 CFX_ByteStringC(const CFX_ByteStringC& src) { |
| 60 m_Ptr = src.m_Ptr; | 60 m_Ptr = src.m_Ptr; |
| 61 m_Length = src.m_Length; | 61 m_Length = src.m_Length; |
| 62 } | 62 } |
| 63 | 63 |
| 64 CFX_ByteStringC(const CFX_ByteString& src); | |
| 65 | |
| 66 CFX_ByteStringC& operator=(const FX_CHAR* src) { | 64 CFX_ByteStringC& operator=(const FX_CHAR* src) { |
| 67 m_Ptr = (const uint8_t*)src; | 65 m_Ptr = (const uint8_t*)src; |
| 68 m_Length = m_Ptr ? FXSYS_strlen(src) : 0; | 66 m_Length = m_Ptr ? FXSYS_strlen(src) : 0; |
| 69 return *this; | 67 return *this; |
| 70 } | 68 } |
| 71 | 69 |
| 72 CFX_ByteStringC& operator=(const CFX_ByteStringC& src) { | 70 CFX_ByteStringC& operator=(const CFX_ByteStringC& src) { |
| 73 m_Ptr = src.m_Ptr; | 71 m_Ptr = src.m_Ptr; |
| 74 m_Length = src.m_Length; | 72 m_Length = src.m_Length; |
| 75 return *this; | 73 return *this; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 ~CFX_ByteString(); | 158 ~CFX_ByteString(); |
| 161 | 159 |
| 162 // Deprecated -- use clear(). | 160 // Deprecated -- use clear(). |
| 163 void Empty() { m_pData.Reset(); } | 161 void Empty() { m_pData.Reset(); } |
| 164 void clear() { m_pData.Reset(); } | 162 void clear() { m_pData.Reset(); } |
| 165 | 163 |
| 166 static CFX_ByteString FromUnicode(const FX_WCHAR* ptr, FX_STRSIZE len = -1); | 164 static CFX_ByteString FromUnicode(const FX_WCHAR* ptr, FX_STRSIZE len = -1); |
| 167 static CFX_ByteString FromUnicode(const CFX_WideString& str); | 165 static CFX_ByteString FromUnicode(const CFX_WideString& str); |
| 168 | 166 |
| 169 // Explicit conversion to C-style string. | 167 // Explicit conversion to C-style string. |
| 168 // Note: |this| must outlive the use of the result. |
| 170 const FX_CHAR* c_str() const { return m_pData ? m_pData->m_String : ""; } | 169 const FX_CHAR* c_str() const { return m_pData ? m_pData->m_String : ""; } |
| 171 | 170 |
| 172 // Implicit conversion to C-style string -- deprecated. | 171 // Implicit conversion to C-style string -- deprecated. |
| 173 operator const FX_CHAR*() const { return m_pData ? m_pData->m_String : ""; } | 172 operator const FX_CHAR*() const { return m_pData ? m_pData->m_String : ""; } |
| 174 | 173 |
| 175 // Explicit conversion to uint8_t*. | 174 // Explicit conversion to uint8_t*. |
| 175 // Note: |this| must outlive the use of the result. |
| 176 const uint8_t* raw_str() const { | 176 const uint8_t* raw_str() const { |
| 177 return m_pData ? reinterpret_cast<const uint8_t*>(m_pData->m_String) | 177 return m_pData ? reinterpret_cast<const uint8_t*>(m_pData->m_String) |
| 178 : nullptr; | 178 : nullptr; |
| 179 } | 179 } |
| 180 | 180 |
| 181 // Implicit conversiont to uint8_t* -- deprecated. | 181 // Implicit conversiont to uint8_t* -- deprecated. |
| 182 operator const uint8_t*() const { | 182 operator const uint8_t*() const { |
| 183 return m_pData ? reinterpret_cast<const uint8_t*>(m_pData->m_String) | 183 return m_pData ? reinterpret_cast<const uint8_t*>(m_pData->m_String) |
| 184 : nullptr; | 184 : nullptr; |
| 185 } | 185 } |
| 186 | 186 |
| 187 // Explicit conversion to CFX_ByteStringC. |
| 188 // Note: |this| must outlive the use of the result. |
| 189 CFX_ByteStringC AsByteStringC() const { |
| 190 return CFX_ByteStringC(raw_str(), GetLength()); |
| 191 } |
| 192 |
| 187 FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } | 193 FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } |
| 188 bool IsEmpty() const { return !GetLength(); } | 194 bool IsEmpty() const { return !GetLength(); } |
| 189 | 195 |
| 190 int Compare(const CFX_ByteStringC& str) const; | 196 int Compare(const CFX_ByteStringC& str) const; |
| 191 bool EqualNoCase(const CFX_ByteStringC& str) const; | 197 bool EqualNoCase(const CFX_ByteStringC& str) const; |
| 192 | 198 |
| 193 bool operator==(const char* ptr) const; | 199 bool operator==(const char* ptr) const; |
| 194 bool operator==(const CFX_ByteStringC& str) const; | 200 bool operator==(const CFX_ByteStringC& str) const; |
| 195 bool operator==(const CFX_ByteString& other) const; | 201 bool operator==(const CFX_ByteString& other) const; |
| 196 | 202 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 void AllocCopy(CFX_ByteString& dest, | 329 void AllocCopy(CFX_ByteString& dest, |
| 324 FX_STRSIZE nCopyLen, | 330 FX_STRSIZE nCopyLen, |
| 325 FX_STRSIZE nCopyIndex) const; | 331 FX_STRSIZE nCopyIndex) const; |
| 326 void AssignCopy(const FX_CHAR* pSrcData, FX_STRSIZE nSrcLen); | 332 void AssignCopy(const FX_CHAR* pSrcData, FX_STRSIZE nSrcLen); |
| 327 void Concat(const FX_CHAR* lpszSrcData, FX_STRSIZE nSrcLen); | 333 void Concat(const FX_CHAR* lpszSrcData, FX_STRSIZE nSrcLen); |
| 328 | 334 |
| 329 CFX_RetainPtr<StringData> m_pData; | 335 CFX_RetainPtr<StringData> m_pData; |
| 330 friend class fxcrt_ByteStringConcat_Test; | 336 friend class fxcrt_ByteStringConcat_Test; |
| 331 }; | 337 }; |
| 332 | 338 |
| 333 inline CFX_ByteStringC::CFX_ByteStringC(const CFX_ByteString& src) { | |
| 334 m_Ptr = (const uint8_t*)src; | |
| 335 m_Length = src.GetLength(); | |
| 336 } | |
| 337 inline CFX_ByteStringC& CFX_ByteStringC::operator=(const CFX_ByteString& src) { | 339 inline CFX_ByteStringC& CFX_ByteStringC::operator=(const CFX_ByteString& src) { |
| 338 m_Ptr = (const uint8_t*)src; | 340 m_Ptr = (const uint8_t*)src; |
| 339 m_Length = src.GetLength(); | 341 m_Length = src.GetLength(); |
| 340 return *this; | 342 return *this; |
| 341 } | 343 } |
| 342 | 344 |
| 343 inline bool operator==(const char* lhs, const CFX_ByteString& rhs) { | 345 inline bool operator==(const char* lhs, const CFX_ByteString& rhs) { |
| 344 return rhs == lhs; | 346 return rhs == lhs; |
| 345 } | 347 } |
| 346 inline bool operator==(const CFX_ByteStringC& lhs, const CFX_ByteString& rhs) { | 348 inline bool operator==(const CFX_ByteStringC& lhs, const CFX_ByteString& rhs) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 366 return CFX_ByteString(str1, str2); | 368 return CFX_ByteString(str1, str2); |
| 367 } | 369 } |
| 368 inline CFX_ByteString operator+(const CFX_ByteStringC& str1, FX_CHAR ch) { | 370 inline CFX_ByteString operator+(const CFX_ByteStringC& str1, FX_CHAR ch) { |
| 369 return CFX_ByteString(str1, CFX_ByteStringC(ch)); | 371 return CFX_ByteString(str1, CFX_ByteStringC(ch)); |
| 370 } | 372 } |
| 371 inline CFX_ByteString operator+(FX_CHAR ch, const CFX_ByteStringC& str2) { | 373 inline CFX_ByteString operator+(FX_CHAR ch, const CFX_ByteStringC& str2) { |
| 372 return CFX_ByteString(ch, str2); | 374 return CFX_ByteString(ch, str2); |
| 373 } | 375 } |
| 374 inline CFX_ByteString operator+(const CFX_ByteString& str1, | 376 inline CFX_ByteString operator+(const CFX_ByteString& str1, |
| 375 const CFX_ByteString& str2) { | 377 const CFX_ByteString& str2) { |
| 376 return CFX_ByteString(str1, str2); | 378 return CFX_ByteString(str1.AsByteStringC(), str2.AsByteStringC()); |
| 377 } | 379 } |
| 378 inline CFX_ByteString operator+(const CFX_ByteString& str1, FX_CHAR ch) { | 380 inline CFX_ByteString operator+(const CFX_ByteString& str1, FX_CHAR ch) { |
| 379 return CFX_ByteString(str1, CFX_ByteStringC(ch)); | 381 return CFX_ByteString(str1.AsByteStringC(), CFX_ByteStringC(ch)); |
| 380 } | 382 } |
| 381 inline CFX_ByteString operator+(FX_CHAR ch, const CFX_ByteString& str2) { | 383 inline CFX_ByteString operator+(FX_CHAR ch, const CFX_ByteString& str2) { |
| 382 return CFX_ByteString(ch, str2); | 384 return CFX_ByteString(ch, str2.AsByteStringC()); |
| 383 } | 385 } |
| 384 inline CFX_ByteString operator+(const CFX_ByteString& str1, | 386 inline CFX_ByteString operator+(const CFX_ByteString& str1, |
| 385 const FX_CHAR* str2) { | 387 const FX_CHAR* str2) { |
| 386 return CFX_ByteString(str1, str2); | 388 return CFX_ByteString(str1.AsByteStringC(), str2); |
| 387 } | 389 } |
| 388 inline CFX_ByteString operator+(const FX_CHAR* str1, | 390 inline CFX_ByteString operator+(const FX_CHAR* str1, |
| 389 const CFX_ByteString& str2) { | 391 const CFX_ByteString& str2) { |
| 390 return CFX_ByteString(str1, str2); | 392 return CFX_ByteString(str1, str2.AsByteStringC()); |
| 391 } | 393 } |
| 392 inline CFX_ByteString operator+(const CFX_ByteString& str1, | 394 inline CFX_ByteString operator+(const CFX_ByteString& str1, |
| 393 const CFX_ByteStringC& str2) { | 395 const CFX_ByteStringC& str2) { |
| 394 return CFX_ByteString(str1, str2); | 396 return CFX_ByteString(str1.AsByteStringC(), str2); |
| 395 } | 397 } |
| 396 inline CFX_ByteString operator+(const CFX_ByteStringC& str1, | 398 inline CFX_ByteString operator+(const CFX_ByteStringC& str1, |
| 397 const CFX_ByteString& str2) { | 399 const CFX_ByteString& str2) { |
| 398 return CFX_ByteString(str1, str2); | 400 return CFX_ByteString(str1, str2.AsByteStringC()); |
| 399 } | 401 } |
| 400 | 402 |
| 401 class CFX_WideStringC { | 403 class CFX_WideStringC { |
| 402 public: | 404 public: |
| 403 typedef FX_WCHAR value_type; | 405 typedef FX_WCHAR value_type; |
| 404 | 406 |
| 405 CFX_WideStringC() { | 407 CFX_WideStringC() { |
| 406 m_Ptr = NULL; | 408 m_Ptr = NULL; |
| 407 m_Length = 0; | 409 m_Length = 0; |
| 408 } | 410 } |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 CFX_ByteString FX_UTF8Encode(const FX_WCHAR* pwsStr, FX_STRSIZE len); | 753 CFX_ByteString FX_UTF8Encode(const FX_WCHAR* pwsStr, FX_STRSIZE len); |
| 752 inline CFX_ByteString FX_UTF8Encode(const CFX_WideStringC& wsStr) { | 754 inline CFX_ByteString FX_UTF8Encode(const CFX_WideStringC& wsStr) { |
| 753 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); | 755 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); |
| 754 } | 756 } |
| 755 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString& wsStr) { | 757 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString& wsStr) { |
| 756 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); | 758 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); |
| 757 } | 759 } |
| 758 | 760 |
| 759 FX_FLOAT FX_atof(const CFX_ByteStringC& str); | 761 FX_FLOAT FX_atof(const CFX_ByteStringC& str); |
| 760 inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) { | 762 inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) { |
| 761 return FX_atof(FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength())); | 763 return FX_atof(FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()).c_str()); |
| 762 } | 764 } |
| 763 void FX_atonum(const CFX_ByteStringC& str, FX_BOOL& bInteger, void* pData); | 765 void FX_atonum(const CFX_ByteStringC& str, FX_BOOL& bInteger, void* pData); |
| 764 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); | 766 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); |
| 765 | 767 |
| 766 #endif // CORE_FXCRT_INCLUDE_FX_STRING_H_ | 768 #endif // CORE_FXCRT_INCLUDE_FX_STRING_H_ |
| OLD | NEW |