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

Side by Side Diff: public/platform/WebCString.h

Issue 15079005: Create a minimal webkit_common static library for use in browser process (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 /* 1 #include "../common/WebCString.h"
2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef WebCString_h
32 #define WebCString_h
33
34 #include "WebCommon.h"
35 #include "WebPrivatePtr.h"
36
37 #if WEBKIT_IMPLEMENTATION
38 #include <wtf/Forward.h>
39 #else
40 #include <string>
41 #endif
42
43 namespace WTF {
44 class CString;
45 class CStringBuffer;
46 }
47
48 namespace WebKit {
49
50 class WebString;
51
52 // A single-byte string container with unspecified encoding. It is
53 // inexpensive to copy a WebCString object.
54 //
55 // WARNING: It is not safe to pass a WebCString across threads!!!
56 //
57 class WebCString {
58 public:
59 ~WebCString() { reset(); }
60
61 WebCString() { }
62
63 WebCString(const char* data, size_t len)
64 {
65 assign(data, len);
66 }
67
68 WebCString(const WebCString& s) { assign(s); }
69
70 WebCString& operator=(const WebCString& s)
71 {
72 assign(s);
73 return *this;
74 }
75
76 // Returns 0 if both strings are equals, a value greater than zero if the
77 // first character that does not match has a greater value in this string
78 // than in |other|, or a value less than zero to indicate the opposite.
79 WEBKIT_EXPORT int compare(const WebCString& other) const;
80
81 WEBKIT_EXPORT void reset();
82 WEBKIT_EXPORT void assign(const WebCString&);
83 WEBKIT_EXPORT void assign(const char* data, size_t len);
84
85 WEBKIT_EXPORT size_t length() const;
86 WEBKIT_EXPORT const char* data() const;
87
88 bool isEmpty() const { return !length(); }
89 bool isNull() const { return m_private.isNull(); }
90
91 WEBKIT_EXPORT WebString utf16() const;
92
93 #if WEBKIT_IMPLEMENTATION
94 WebCString(const WTF::CString&);
95 WebCString& operator=(const WTF::CString&);
96 operator WTF::CString() const;
97 #else
98 WebCString(const std::string& s)
99 {
100 assign(s.data(), s.length());
101 }
102
103 WebCString& operator=(const std::string& s)
104 {
105 assign(s.data(), s.length());
106 return *this;
107 }
108
109 operator std::string() const
110 {
111 size_t len = length();
112 return len ? std::string(data(), len) : std::string();
113 }
114
115 template <class UTF16String>
116 static WebCString fromUTF16(const UTF16String& s)
117 {
118 return fromUTF16(s.data(), s.length());
119 }
120 #endif
121
122 private:
123 void assign(WTF::CStringBuffer*);
124 WebPrivatePtr<WTF::CStringBuffer> m_private;
125 };
126
127 inline bool operator<(const WebCString& a, const WebCString& b)
128 {
129 return a.compare(b) < 0;
130 }
131
132 } // namespace WebKit
133
134 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698