OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 12 matching lines...) Expand all Loading... |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "public/platform/WebString.h" | 31 #include "public/platform/WebString.h" |
32 | 32 |
| 33 #include "base/strings/string_util.h" |
| 34 #include "wtf/text/ASCIIFastPath.h" |
33 #include "wtf/text/AtomicString.h" | 35 #include "wtf/text/AtomicString.h" |
34 #include "wtf/text/CString.h" | 36 #include "wtf/text/CString.h" |
35 #include "wtf/text/StringUTF8Adaptor.h" | 37 #include "wtf/text/StringUTF8Adaptor.h" |
36 #include "wtf/text/StringView.h" | 38 #include "wtf/text/StringView.h" |
37 #include "wtf/text/WTFString.h" | 39 #include "wtf/text/WTFString.h" |
38 | 40 |
39 namespace blink { | 41 namespace blink { |
40 | 42 |
41 void WebString::reset() { | 43 void WebString::reset() { |
42 m_private.reset(); | 44 m_private.reset(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 string.length()); | 92 string.length()); |
91 | 93 |
92 CString latin1 = string.latin1(); | 94 CString latin1 = string.latin1(); |
93 return std::string(latin1.data(), latin1.length()); | 95 return std::string(latin1.data(), latin1.length()); |
94 } | 96 } |
95 | 97 |
96 WebString WebString::fromLatin1(const WebLChar* data, size_t length) { | 98 WebString WebString::fromLatin1(const WebLChar* data, size_t length) { |
97 return String(data, length); | 99 return String(data, length); |
98 } | 100 } |
99 | 101 |
| 102 std::string WebString::ascii() const { |
| 103 DCHECK(containsOnlyASCII()); |
| 104 |
| 105 if (isEmpty()) |
| 106 return std::string(); |
| 107 |
| 108 if (m_private->is8Bit()) { |
| 109 return std::string(reinterpret_cast<const char*>(m_private->characters8()), |
| 110 m_private->length()); |
| 111 } |
| 112 |
| 113 return std::string(m_private->characters16(), |
| 114 m_private->characters16() + m_private->length()); |
| 115 } |
| 116 |
| 117 bool WebString::containsOnlyASCII() const { |
| 118 return String(m_private.get()).containsOnlyASCII(); |
| 119 } |
| 120 |
| 121 WebString WebString::fromASCII(const std::string& s) { |
| 122 DCHECK(base::IsStringASCII(s)); |
| 123 return fromLatin1(s); |
| 124 } |
| 125 |
100 bool WebString::equals(const WebString& s) const { | 126 bool WebString::equals(const WebString& s) const { |
101 return equal(m_private.get(), s.m_private.get()); | 127 return equal(m_private.get(), s.m_private.get()); |
102 } | 128 } |
103 | 129 |
104 bool WebString::equals(const char* characters) const { | 130 bool WebString::equals(const char* characters) const { |
105 return equal(m_private.get(), reinterpret_cast<const LChar*>(characters)); | 131 return equal(m_private.get(), reinterpret_cast<const LChar*>(characters)); |
106 } | 132 } |
107 | 133 |
108 WebString::WebString(const WTF::String& s) : m_private(s.impl()) {} | 134 WebString::WebString(const WTF::String& s) : m_private(s.impl()) {} |
109 | 135 |
(...skipping 21 matching lines...) Expand all Loading... |
131 | 157 |
132 WebString::operator WTF::AtomicString() const { | 158 WebString::operator WTF::AtomicString() const { |
133 return WTF::AtomicString(m_private.get()); | 159 return WTF::AtomicString(m_private.get()); |
134 } | 160 } |
135 | 161 |
136 void WebString::assign(WTF::StringImpl* p) { | 162 void WebString::assign(WTF::StringImpl* p) { |
137 m_private = p; | 163 m_private = p; |
138 } | 164 } |
139 | 165 |
140 } // namespace blink | 166 } // namespace blink |
OLD | NEW |