OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2003, 2006, 2008, 2009, 2010, 2012 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2003, 2006, 2008, 2009, 2010, 2012 Apple Inc. All rights reserv
ed. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 11 matching lines...) Expand all Loading... |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef CString_h | 26 #ifndef CString_h |
27 #define CString_h | 27 #define CString_h |
28 | 28 |
29 #include "wtf/RefCounted.h" | 29 #include "wtf/RefCounted.h" |
30 #include "wtf/RefPtr.h" | 30 #include "wtf/RefPtr.h" |
31 #include "wtf/WTFExport.h" | 31 #include "wtf/WTFExport.h" |
| 32 #include <string> |
32 | 33 |
33 namespace WTF { | 34 namespace WTF { |
34 | 35 |
35 // CStringBuffer is the ref-counted storage class for the characters in a CStrin
g. | 36 // CStringBuffer is the ref-counted storage class for the characters in a CStrin
g. |
36 // The data is implicitly allocated 1 character longer than length(), as it is z
ero-terminated. | 37 // The data is implicitly allocated 1 character longer than length(), as it is z
ero-terminated. |
37 class WTF_EXPORT CStringBuffer : public RefCounted<CStringBuffer> { | 38 class WTF_EXPORT CStringBuffer : public RefCounted<CStringBuffer> { |
38 public: | 39 public: |
39 const char* data() { return mutableData(); } | 40 const char* data() { return mutableData(); } |
40 size_t length() const { return m_length; } | 41 size_t length() const { return m_length; } |
41 | 42 |
(...skipping 15 matching lines...) Expand all Loading... |
57 // A container for a null-terminated char array supporting copy-on-write | 58 // A container for a null-terminated char array supporting copy-on-write |
58 // assignment. The contained char array may be null. | 59 // assignment. The contained char array may be null. |
59 class WTF_EXPORT CString { | 60 class WTF_EXPORT CString { |
60 public: | 61 public: |
61 CString() { } | 62 CString() { } |
62 CString(const char*); | 63 CString(const char*); |
63 CString(const char*, size_t length); | 64 CString(const char*, size_t length); |
64 CString(CStringBuffer* buffer) : m_buffer(buffer) { } | 65 CString(CStringBuffer* buffer) : m_buffer(buffer) { } |
65 static CString newUninitialized(size_t length, char*& characterBuffer); | 66 static CString newUninitialized(size_t length, char*& characterBuffer); |
66 | 67 |
| 68 std::string toStdString() const |
| 69 { |
| 70 return std::string(data(), length()); |
| 71 } |
| 72 |
67 const char* data() const | 73 const char* data() const |
68 { | 74 { |
69 return m_buffer ? m_buffer->data() : 0; | 75 return m_buffer ? m_buffer->data() : 0; |
70 } | 76 } |
71 char* mutableData(); | 77 char* mutableData(); |
72 size_t length() const | 78 size_t length() const |
73 { | 79 { |
74 return m_buffer ? m_buffer->length() : 0; | 80 return m_buffer ? m_buffer->length() : 0; |
75 } | 81 } |
76 | 82 |
(...skipping 11 matching lines...) Expand all Loading... |
88 WTF_EXPORT bool operator==(const CString& a, const CString& b); | 94 WTF_EXPORT bool operator==(const CString& a, const CString& b); |
89 inline bool operator!=(const CString& a, const CString& b) { return !(a == b); } | 95 inline bool operator!=(const CString& a, const CString& b) { return !(a == b); } |
90 WTF_EXPORT bool operator==(const CString& a, const char* b); | 96 WTF_EXPORT bool operator==(const CString& a, const char* b); |
91 inline bool operator!=(const CString& a, const char* b) { return !(a == b); } | 97 inline bool operator!=(const CString& a, const char* b) { return !(a == b); } |
92 | 98 |
93 } // namespace WTF | 99 } // namespace WTF |
94 | 100 |
95 using WTF::CString; | 101 using WTF::CString; |
96 | 102 |
97 #endif // CString_h | 103 #endif // CString_h |
OLD | NEW |