| 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 // This method should be used ONLY to pass a WTFString to methods outside |
| 69 // of blink which take a std::string as an argument. |
| 70 std::string toStdString() const |
| 71 { |
| 72 return std::string(data(), length()); |
| 73 } |
| 74 |
| 67 const char* data() const | 75 const char* data() const |
| 68 { | 76 { |
| 69 return m_buffer ? m_buffer->data() : 0; | 77 return m_buffer ? m_buffer->data() : 0; |
| 70 } | 78 } |
| 71 char* mutableData(); | 79 char* mutableData(); |
| 72 size_t length() const | 80 size_t length() const |
| 73 { | 81 { |
| 74 return m_buffer ? m_buffer->length() : 0; | 82 return m_buffer ? m_buffer->length() : 0; |
| 75 } | 83 } |
| 76 | 84 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 88 WTF_EXPORT bool operator==(const CString& a, const CString& b); | 96 WTF_EXPORT bool operator==(const CString& a, const CString& b); |
| 89 inline bool operator!=(const CString& a, const CString& b) { return !(a == b); } | 97 inline bool operator!=(const CString& a, const CString& b) { return !(a == b); } |
| 90 WTF_EXPORT bool operator==(const CString& a, const char* b); | 98 WTF_EXPORT bool operator==(const CString& a, const char* b); |
| 91 inline bool operator!=(const CString& a, const char* b) { return !(a == b); } | 99 inline bool operator!=(const CString& a, const char* b) { return !(a == b); } |
| 92 | 100 |
| 93 } // namespace WTF | 101 } // namespace WTF |
| 94 | 102 |
| 95 using WTF::CString; | 103 using WTF::CString; |
| 96 | 104 |
| 97 #endif // CString_h | 105 #endif // CString_h |
| OLD | NEW |