Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: third_party/WebKit/Source/wtf/text/CString.h

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 18 matching lines...) Expand all
29 #include "wtf/Allocator.h" 29 #include "wtf/Allocator.h"
30 #include "wtf/RefCounted.h" 30 #include "wtf/RefCounted.h"
31 #include "wtf/RefPtr.h" 31 #include "wtf/RefPtr.h"
32 #include "wtf/WTFExport.h" 32 #include "wtf/WTFExport.h"
33 33
34 namespace WTF { 34 namespace WTF {
35 35
36 // 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.
37 // 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.
38 class WTF_EXPORT CStringBuffer : public RefCounted<CStringBuffer> { 38 class WTF_EXPORT CStringBuffer : public RefCounted<CStringBuffer> {
39 public: 39 public:
40 const char* data() { return mutableData(); } 40 const char* data() { return mutableData(); }
41 size_t length() const { return m_length; } 41 size_t length() const { return m_length; }
42 42
43 private: 43 private:
44 friend class CString; 44 friend class CString;
45 friend class RefCounted<CStringBuffer>; 45 friend class RefCounted<CStringBuffer>;
46 // CStringBuffers are allocated out of the WTF buffer partition. 46 // CStringBuffers are allocated out of the WTF buffer partition.
47 void* operator new(size_t, void* ptr) { return ptr; } 47 void* operator new(size_t, void* ptr) { return ptr; }
48 void operator delete(void*); 48 void operator delete(void*);
49 49
50 static PassRefPtr<CStringBuffer> createUninitialized(size_t length); 50 static PassRefPtr<CStringBuffer> createUninitialized(size_t length);
51 51
52 CStringBuffer(size_t length) : m_length(length) { } 52 CStringBuffer(size_t length) : m_length(length) {}
53 char* mutableData() { return reinterpret_cast<char*>(this + 1); } 53 char* mutableData() { return reinterpret_cast<char*>(this + 1); }
54 54
55 const unsigned m_length; 55 const unsigned m_length;
56 }; 56 };
57 57
58 // 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
59 // assignment. The contained char array may be null. 59 // assignment. The contained char array may be null.
60 class WTF_EXPORT CString { 60 class WTF_EXPORT CString {
61 USING_FAST_MALLOC(CString); 61 USING_FAST_MALLOC(CString);
62 public:
63 CString() { }
64 CString(const char*);
65 CString(const char*, size_t length);
66 CString(CStringBuffer* buffer) : m_buffer(buffer) { }
67 static CString newUninitialized(size_t length, char*& characterBuffer);
68 62
69 const char* data() const 63 public:
70 { 64 CString() {}
71 return m_buffer ? m_buffer->data() : 0; 65 CString(const char*);
72 } 66 CString(const char*, size_t length);
73 char* mutableData(); 67 CString(CStringBuffer* buffer) : m_buffer(buffer) {}
74 size_t length() const 68 static CString newUninitialized(size_t length, char*& characterBuffer);
75 {
76 return m_buffer ? m_buffer->length() : 0;
77 }
78 69
79 bool isNull() const { return !m_buffer; } 70 const char* data() const { return m_buffer ? m_buffer->data() : 0; }
80 bool isSafeToSendToAnotherThread() const; 71 char* mutableData();
72 size_t length() const { return m_buffer ? m_buffer->length() : 0; }
81 73
82 CStringBuffer* buffer() const { return m_buffer.get(); } 74 bool isNull() const { return !m_buffer; }
75 bool isSafeToSendToAnotherThread() const;
83 76
84 private: 77 CStringBuffer* buffer() const { return m_buffer.get(); }
85 void copyBufferIfNeeded(); 78
86 void init(const char*, size_t length); 79 private:
87 RefPtr<CStringBuffer> m_buffer; 80 void copyBufferIfNeeded();
81 void init(const char*, size_t length);
82 RefPtr<CStringBuffer> m_buffer;
88 }; 83 };
89 84
90 WTF_EXPORT bool operator==(const CString& a, const CString& b); 85 WTF_EXPORT bool operator==(const CString& a, const CString& b);
91 inline bool operator!=(const CString& a, const CString& b) { return !(a == b); } 86 inline bool operator!=(const CString& a, const CString& b) {
87 return !(a == b);
88 }
92 WTF_EXPORT bool operator==(const CString& a, const char* b); 89 WTF_EXPORT bool operator==(const CString& a, const char* b);
93 inline bool operator!=(const CString& a, const char* b) { return !(a == b); } 90 inline bool operator!=(const CString& a, const char* b) {
91 return !(a == b);
92 }
94 93
95 } // namespace WTF 94 } // namespace WTF
96 95
97 using WTF::CString; 96 using WTF::CString;
98 97
99 #endif // CString_h 98 #endif // CString_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/Base64.cpp ('k') | third_party/WebKit/Source/wtf/text/CString.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698