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 _FX_STRING_H_ | 7 #ifndef _FX_STRING_H_ |
| 8 #define _FX_STRING_H_ | 8 #define _FX_STRING_H_ |
| 9 | 9 |
| 10 #include <algorithm> | |
| 11 | |
| 10 #include "fx_memory.h" | 12 #include "fx_memory.h" |
| 11 | 13 |
| 12 class CFX_ByteStringC; | 14 class CFX_ByteStringC; |
| 13 class CFX_ByteString; | 15 class CFX_ByteString; |
| 14 class CFX_WideStringC; | 16 class CFX_WideStringC; |
| 15 class CFX_WideString; | 17 class CFX_WideString; |
| 16 struct CFX_CharMap; | 18 struct CFX_CharMap; |
| 17 class CFX_BinaryBuf; | 19 class CFX_BinaryBuf; |
| 18 typedef int FX_STRSIZE; | 20 typedef int FX_STRSIZE; |
| 19 class CFX_ByteStringL; | 21 class CFX_ByteStringL; |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 477 template<FX_STRSIZE limit> | 479 template<FX_STRSIZE limit> |
| 478 class CFX_StringBufTemplate : public CFX_StringBufBase | 480 class CFX_StringBufTemplate : public CFX_StringBufBase |
| 479 { | 481 { |
| 480 public: | 482 public: |
| 481 | 483 |
| 482 CFX_StringBufTemplate() : CFX_StringBufBase(limit) {} | 484 CFX_StringBufTemplate() : CFX_StringBufBase(limit) {} |
| 483 | 485 |
| 484 FX_CHAR m_Buffer[limit]; | 486 FX_CHAR m_Buffer[limit]; |
| 485 }; | 487 }; |
| 486 typedef CFX_StringBufTemplate<256> CFX_StringBuf256; | 488 typedef CFX_StringBufTemplate<256> CFX_StringBuf256; |
| 487 class CFX_WideStringC | 489 class CFX_WideStringC |
| 488 { | 490 { |
| 489 public: | 491 public: |
| 490 typedef FX_WCHAR value_type; | 492 typedef FX_WCHAR value_type; |
| 491 | 493 |
| 492 CFX_WideStringC() | 494 CFX_WideStringC() |
| 493 { | 495 { |
| 494 m_Ptr = NULL; | 496 m_Ptr = NULL; |
| 495 m_Length = 0; | 497 m_Length = 0; |
| 496 } | 498 } |
| 497 | 499 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 CFX_WideStringC Right(FX_STRSIZE count) const | 601 CFX_WideStringC Right(FX_STRSIZE count) const |
| 600 { | 602 { |
| 601 if (count < 1) { | 603 if (count < 1) { |
| 602 return CFX_WideStringC(); | 604 return CFX_WideStringC(); |
| 603 } | 605 } |
| 604 if (count > m_Length) { | 606 if (count > m_Length) { |
| 605 count = m_Length; | 607 count = m_Length; |
| 606 } | 608 } |
| 607 return CFX_WideStringC(m_Ptr + m_Length - count, count); | 609 return CFX_WideStringC(m_Ptr + m_Length - count, count); |
| 608 } | 610 } |
| 611 | |
| 612 const FX_WCHAR& operator[] (int index) const | |
|
Lei Zhang
2015/04/21 22:07:56
Same as last CL, size_t ?
Tom Sepez
2015/04/22 17:06:45
Done.
| |
| 613 { | |
| 614 return m_Ptr[index]; | |
| 615 } | |
| 616 | |
| 617 bool operator< (const CFX_WideStringC& that) | |
|
brucedawson
2015/04/22 10:47:12
The operator itself needs to be const.
Tom Sepez
2015/04/22 17:06:45
Done.
| |
| 618 { | |
| 619 int result = wmemcmp(m_Ptr, that.m_Ptr, std::min(m_Length, that.m_Length )); | |
|
Tom Sepez
2015/04/22 17:06:45
Bruce, you're OK with wmemcmp, right? No windows
| |
| 620 return result < 0 || (result == 0 && m_Length < that.m_Length); | |
| 621 } | |
| 622 | |
| 609 protected: | 623 protected: |
| 624 FX_LPCWSTR m_Ptr; | |
| 625 FX_STRSIZE m_Length; | |
| 610 | 626 |
| 611 FX_LPCWSTR m_Ptr; | |
| 612 | |
| 613 FX_STRSIZE m_Length; | |
| 614 private: | 627 private: |
| 615 | |
| 616 void* operator new (size_t) throw() | 628 void* operator new (size_t) throw() |
| 617 { | 629 { |
| 618 return NULL; | 630 return NULL; |
| 619 } | 631 } |
| 620 }; | 632 }; |
| 621 typedef const CFX_WideStringC& FX_WSTR; | 633 typedef const CFX_WideStringC& FX_WSTR; |
| 622 #define FX_WSTRC(wstr) CFX_WideStringC(wstr, FX_ArraySize(wstr) - 1) | 634 #define FX_WSTRC(wstr) CFX_WideStringC(wstr, FX_ArraySize(wstr) - 1) |
| 623 struct CFX_StringDataW { | 635 struct CFX_StringDataW { |
| 624 | 636 |
| 625 long m_nRefs; | 637 long m_nRefs; |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 867 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len); | 879 CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len); |
| 868 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr) | 880 inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr) |
| 869 { | 881 { |
| 870 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); | 882 return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); |
| 871 } | 883 } |
| 872 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr) | 884 inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr) |
| 873 { | 885 { |
| 874 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); | 886 return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); |
| 875 } | 887 } |
| 876 #endif | 888 #endif |
| OLD | NEW |