Chromium Code Reviews| 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. |
| 11 | |
| 11 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <functional> | |
| 12 | 14 |
| 13 #include "core/fxcrt/cfx_string_c_template.h" | 15 #include "core/fxcrt/cfx_string_c_template.h" |
| 14 #include "core/fxcrt/cfx_string_data_template.h" | 16 #include "core/fxcrt/cfx_string_data_template.h" |
| 15 #include "core/fxcrt/include/cfx_retain_ptr.h" | 17 #include "core/fxcrt/include/cfx_retain_ptr.h" |
| 16 #include "core/fxcrt/include/fx_memory.h" | 18 #include "core/fxcrt/include/fx_memory.h" |
| 17 #include "core/fxcrt/include/fx_system.h" | 19 #include "core/fxcrt/include/fx_system.h" |
| 18 | 20 |
| 19 class CFX_ByteString; | 21 class CFX_ByteString; |
| 20 class CFX_WideString; | 22 class CFX_WideString; |
| 21 | 23 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 | 165 |
| 164 void ReallocBeforeWrite(FX_STRSIZE nNewLen); | 166 void ReallocBeforeWrite(FX_STRSIZE nNewLen); |
| 165 void AllocBeforeWrite(FX_STRSIZE nNewLen); | 167 void AllocBeforeWrite(FX_STRSIZE nNewLen); |
| 166 void AllocCopy(CFX_ByteString& dest, | 168 void AllocCopy(CFX_ByteString& dest, |
| 167 FX_STRSIZE nCopyLen, | 169 FX_STRSIZE nCopyLen, |
| 168 FX_STRSIZE nCopyIndex) const; | 170 FX_STRSIZE nCopyIndex) const; |
| 169 void AssignCopy(const FX_CHAR* pSrcData, FX_STRSIZE nSrcLen); | 171 void AssignCopy(const FX_CHAR* pSrcData, FX_STRSIZE nSrcLen); |
| 170 void Concat(const FX_CHAR* lpszSrcData, FX_STRSIZE nSrcLen); | 172 void Concat(const FX_CHAR* lpszSrcData, FX_STRSIZE nSrcLen); |
| 171 | 173 |
| 172 CFX_RetainPtr<StringData> m_pData; | 174 CFX_RetainPtr<StringData> m_pData; |
| 175 | |
| 173 friend class fxcrt_ByteStringConcat_Test; | 176 friend class fxcrt_ByteStringConcat_Test; |
| 177 friend class fxcrt_ByteStringPool_Test; | |
| 174 }; | 178 }; |
| 175 | 179 |
| 176 inline bool operator==(const char* lhs, const CFX_ByteString& rhs) { | 180 inline bool operator==(const char* lhs, const CFX_ByteString& rhs) { |
| 177 return rhs == lhs; | 181 return rhs == lhs; |
| 178 } | 182 } |
| 179 inline bool operator==(const CFX_ByteStringC& lhs, const CFX_ByteString& rhs) { | 183 inline bool operator==(const CFX_ByteStringC& lhs, const CFX_ByteString& rhs) { |
| 180 return rhs == lhs; | 184 return rhs == lhs; |
| 181 } | 185 } |
| 182 inline bool operator!=(const char* lhs, const CFX_ByteString& rhs) { | 186 inline bool operator!=(const char* lhs, const CFX_ByteString& rhs) { |
| 183 return rhs != lhs; | 187 return rhs != lhs; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 | 362 |
| 359 void ReallocBeforeWrite(FX_STRSIZE nLen); | 363 void ReallocBeforeWrite(FX_STRSIZE nLen); |
| 360 void AllocBeforeWrite(FX_STRSIZE nLen); | 364 void AllocBeforeWrite(FX_STRSIZE nLen); |
| 361 void AllocCopy(CFX_WideString& dest, | 365 void AllocCopy(CFX_WideString& dest, |
| 362 FX_STRSIZE nCopyLen, | 366 FX_STRSIZE nCopyLen, |
| 363 FX_STRSIZE nCopyIndex) const; | 367 FX_STRSIZE nCopyIndex) const; |
| 364 void AssignCopy(const FX_WCHAR* pSrcData, FX_STRSIZE nSrcLen); | 368 void AssignCopy(const FX_WCHAR* pSrcData, FX_STRSIZE nSrcLen); |
| 365 void Concat(const FX_WCHAR* lpszSrcData, FX_STRSIZE nSrcLen); | 369 void Concat(const FX_WCHAR* lpszSrcData, FX_STRSIZE nSrcLen); |
| 366 | 370 |
| 367 CFX_RetainPtr<StringData> m_pData; | 371 CFX_RetainPtr<StringData> m_pData; |
| 372 | |
| 368 friend class fxcrt_WideStringConcatInPlace_Test; | 373 friend class fxcrt_WideStringConcatInPlace_Test; |
| 374 friend class fxcrt_WideStringPool_Test; | |
| 369 }; | 375 }; |
| 370 | 376 |
| 371 inline CFX_WideString operator+(const CFX_WideStringC& str1, | 377 inline CFX_WideString operator+(const CFX_WideStringC& str1, |
| 372 const CFX_WideStringC& str2) { | 378 const CFX_WideStringC& str2) { |
| 373 return CFX_WideString(str1, str2); | 379 return CFX_WideString(str1, str2); |
| 374 } | 380 } |
| 375 inline CFX_WideString operator+(const CFX_WideStringC& str1, | 381 inline CFX_WideString operator+(const CFX_WideStringC& str1, |
| 376 const FX_WCHAR* str2) { | 382 const FX_WCHAR* str2) { |
| 377 return CFX_WideString(str1, str2); | 383 return CFX_WideString(str1, str2); |
| 378 } | 384 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); | 439 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); |
| 434 } | 440 } |
| 435 | 441 |
| 436 FX_FLOAT FX_atof(const CFX_ByteStringC& str); | 442 FX_FLOAT FX_atof(const CFX_ByteStringC& str); |
| 437 inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) { | 443 inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) { |
| 438 return FX_atof(FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()).c_str()); | 444 return FX_atof(FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()).c_str()); |
| 439 } | 445 } |
| 440 bool FX_atonum(const CFX_ByteStringC& str, void* pData); | 446 bool FX_atonum(const CFX_ByteStringC& str, void* pData); |
| 441 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); | 447 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); |
| 442 | 448 |
| 449 uint32_t FX_HashCode_GetA(const CFX_ByteStringC& str, bool bIgnoreCase); | |
| 450 uint32_t FX_HashCode_GetW(const CFX_WideStringC& str, bool bIgnoreCase); | |
| 451 | |
| 452 namespace std { | |
|
dsinclair
2016/09/15 20:23:26
Are we allowed to put things into namespace std?
Tom Sepez
2016/09/15 20:51:24
See https://cs.chromium.org/chromium/src/base/opti
| |
| 453 | |
| 454 template <> | |
| 455 struct hash<CFX_ByteString> { | |
| 456 std::size_t operator()(const CFX_ByteString& str) const { | |
| 457 return FX_HashCode_GetA(str.AsStringC(), false); | |
| 458 } | |
| 459 }; | |
| 460 | |
| 461 template <> | |
| 462 struct hash<CFX_WideString> { | |
| 463 std::size_t operator()(const CFX_WideString& str) const { | |
| 464 return FX_HashCode_GetW(str.AsStringC(), false); | |
| 465 } | |
| 466 }; | |
| 467 | |
| 468 } // namespace std | |
| 469 | |
| 470 extern template struct std::hash<CFX_ByteString>; | |
| 471 extern template struct std::hash<CFX_WideString>; | |
| 472 | |
| 443 #endif // CORE_FXCRT_INCLUDE_FX_STRING_H_ | 473 #endif // CORE_FXCRT_INCLUDE_FX_STRING_H_ |
| OLD | NEW |