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 16 matching lines...) Expand all Loading... |
27 CFX_ByteStringC() { | 27 CFX_ByteStringC() { |
28 m_Ptr = NULL; | 28 m_Ptr = NULL; |
29 m_Length = 0; | 29 m_Length = 0; |
30 } | 30 } |
31 | 31 |
32 CFX_ByteStringC(const uint8_t* ptr, FX_STRSIZE size) { | 32 CFX_ByteStringC(const uint8_t* ptr, FX_STRSIZE size) { |
33 m_Ptr = ptr; | 33 m_Ptr = ptr; |
34 m_Length = size; | 34 m_Length = size; |
35 } | 35 } |
36 | 36 |
| 37 // Deliberately implicit to avoid calling on every string literal. |
37 CFX_ByteStringC(const FX_CHAR* ptr) { | 38 CFX_ByteStringC(const FX_CHAR* ptr) { |
38 m_Ptr = (const uint8_t*)ptr; | 39 m_Ptr = (const uint8_t*)ptr; |
39 m_Length = ptr ? FXSYS_strlen(ptr) : 0; | 40 m_Length = ptr ? FXSYS_strlen(ptr) : 0; |
40 } | 41 } |
41 | 42 |
| 43 // Deliberately implicit to avoid calling on every string literal. |
42 // |ch| must be an lvalue that outlives the the CFX_ByteStringC. However, | 44 // |ch| must be an lvalue that outlives the the CFX_ByteStringC. However, |
43 // the use of char rvalues are not caught at compile time. They are | 45 // the use of char rvalues are not caught at compile time. They are |
44 // implicitly promoted to CFX_ByteString (see below) and then the | 46 // implicitly promoted to CFX_ByteString (see below) and then the |
45 // CFX_ByteStringC is constructed from the CFX_ByteString via the alternate | 47 // CFX_ByteStringC is constructed from the CFX_ByteString via the alternate |
46 // constructor below. The CFX_ByteString then typically goes out of scope | 48 // constructor below. The CFX_ByteString then typically goes out of scope |
47 // and |m_Ptr| may be left pointing to invalid memory. Beware. | 49 // and |m_Ptr| may be left pointing to invalid memory. Beware. |
48 // TODO(tsepez): Mark single-argument string constructors as explicit. | |
49 CFX_ByteStringC(FX_CHAR& ch) { | 50 CFX_ByteStringC(FX_CHAR& ch) { |
50 m_Ptr = (const uint8_t*)&ch; | 51 m_Ptr = (const uint8_t*)&ch; |
51 m_Length = 1; | 52 m_Length = 1; |
52 } | 53 } |
53 | 54 |
54 CFX_ByteStringC(const FX_CHAR* ptr, FX_STRSIZE len) { | 55 CFX_ByteStringC(const FX_CHAR* ptr, FX_STRSIZE len) { |
55 m_Ptr = (const uint8_t*)ptr; | 56 m_Ptr = (const uint8_t*)ptr; |
56 m_Length = (len == -1) ? FXSYS_strlen(ptr) : len; | 57 m_Length = (len == -1) ? FXSYS_strlen(ptr) : len; |
57 } | 58 } |
58 | 59 |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 351 |
351 class CFX_WideStringC { | 352 class CFX_WideStringC { |
352 public: | 353 public: |
353 typedef FX_WCHAR value_type; | 354 typedef FX_WCHAR value_type; |
354 | 355 |
355 CFX_WideStringC() { | 356 CFX_WideStringC() { |
356 m_Ptr = NULL; | 357 m_Ptr = NULL; |
357 m_Length = 0; | 358 m_Length = 0; |
358 } | 359 } |
359 | 360 |
| 361 // Deliberately implicit to avoid calling on every string literal. |
360 CFX_WideStringC(const FX_WCHAR* ptr) { | 362 CFX_WideStringC(const FX_WCHAR* ptr) { |
361 m_Ptr = ptr; | 363 m_Ptr = ptr; |
362 m_Length = ptr ? FXSYS_wcslen(ptr) : 0; | 364 m_Length = ptr ? FXSYS_wcslen(ptr) : 0; |
363 } | 365 } |
364 | 366 |
| 367 // Deliberately implicit to avoid calling on every string literal. |
| 368 // |ch| must be an lvalue that outlives the the CFX_WideStringC. However, |
| 369 // the use of char rvalues are not caught at compile time. They are |
| 370 // implicitly promoted to CFX_WideString (see below) and then the |
| 371 // CFX_WideStringC is constructed from the CFX_WideString via the alternate |
| 372 // constructor below. The CFX_WideString then typically goes out of scope |
| 373 // and |m_Ptr| may be left pointing to invalid memory. Beware. |
365 CFX_WideStringC(FX_WCHAR& ch) { | 374 CFX_WideStringC(FX_WCHAR& ch) { |
366 m_Ptr = &ch; | 375 m_Ptr = &ch; |
367 m_Length = 1; | 376 m_Length = 1; |
368 } | 377 } |
369 | 378 |
370 CFX_WideStringC(const FX_WCHAR* ptr, FX_STRSIZE len) { | 379 CFX_WideStringC(const FX_WCHAR* ptr, FX_STRSIZE len) { |
371 m_Ptr = ptr; | 380 m_Ptr = ptr; |
372 m_Length = (len == -1) ? FXSYS_wcslen(ptr) : len; | 381 m_Length = (len == -1) ? FXSYS_wcslen(ptr) : len; |
373 } | 382 } |
374 | 383 |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 } | 683 } |
675 | 684 |
676 FX_FLOAT FX_atof(const CFX_ByteStringC& str); | 685 FX_FLOAT FX_atof(const CFX_ByteStringC& str); |
677 inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) { | 686 inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) { |
678 return FX_atof(FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()).c_str()); | 687 return FX_atof(FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()).c_str()); |
679 } | 688 } |
680 void FX_atonum(const CFX_ByteStringC& str, FX_BOOL& bInteger, void* pData); | 689 void FX_atonum(const CFX_ByteStringC& str, FX_BOOL& bInteger, void* pData); |
681 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); | 690 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); |
682 | 691 |
683 #endif // CORE_FXCRT_INCLUDE_FX_STRING_H_ | 692 #endif // CORE_FXCRT_INCLUDE_FX_STRING_H_ |
OLD | NEW |