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 20 matching lines...) Expand all Loading... |
31 #include "public/platform/WebString.h" | 31 #include "public/platform/WebString.h" |
32 | 32 |
33 #include "base/strings/string_util.h" | 33 #include "base/strings/string_util.h" |
34 #include "wtf/text/ASCIIFastPath.h" | 34 #include "wtf/text/ASCIIFastPath.h" |
35 #include "wtf/text/AtomicString.h" | 35 #include "wtf/text/AtomicString.h" |
36 #include "wtf/text/CString.h" | 36 #include "wtf/text/CString.h" |
37 #include "wtf/text/StringUTF8Adaptor.h" | 37 #include "wtf/text/StringUTF8Adaptor.h" |
38 #include "wtf/text/StringView.h" | 38 #include "wtf/text/StringView.h" |
39 #include "wtf/text/WTFString.h" | 39 #include "wtf/text/WTFString.h" |
40 | 40 |
| 41 #define STATIC_ASSERT_ENUM(a, b) \ |
| 42 static_assert(static_cast<int>(a) == static_cast<int>(b), \ |
| 43 "mismatching enums: " #a) |
| 44 |
| 45 STATIC_ASSERT_ENUM(WTF::LenientUTF8Conversion, |
| 46 blink::WebString::UTF8ConversionMode::kLenient); |
| 47 STATIC_ASSERT_ENUM(WTF::StrictUTF8Conversion, |
| 48 blink::WebString::UTF8ConversionMode::kStrict); |
| 49 STATIC_ASSERT_ENUM( |
| 50 WTF::StrictUTF8ConversionReplacingUnpairedSurrogatesWithFFFD, |
| 51 blink::WebString::UTF8ConversionMode::kStrictReplacingErrorsWithFFFD); |
| 52 |
41 namespace blink { | 53 namespace blink { |
42 | 54 |
43 void WebString::reset() { | 55 void WebString::reset() { |
44 m_private.reset(); | 56 m_private.reset(); |
45 } | 57 } |
46 | 58 |
47 void WebString::assign(const WebString& other) { | 59 void WebString::assign(const WebString& other) { |
48 assign(other.m_private.get()); | 60 assign(other.m_private.get()); |
49 } | 61 } |
50 | 62 |
(...skipping 10 matching lines...) Expand all Loading... |
61 } | 73 } |
62 | 74 |
63 const WebLChar* WebString::data8() const { | 75 const WebLChar* WebString::data8() const { |
64 return !m_private.isNull() && is8Bit() ? m_private->characters8() : 0; | 76 return !m_private.isNull() && is8Bit() ? m_private->characters8() : 0; |
65 } | 77 } |
66 | 78 |
67 const WebUChar* WebString::data16() const { | 79 const WebUChar* WebString::data16() const { |
68 return !m_private.isNull() && !is8Bit() ? m_private->characters16() : 0; | 80 return !m_private.isNull() && !is8Bit() ? m_private->characters16() : 0; |
69 } | 81 } |
70 | 82 |
71 std::string WebString::utf8() const { | 83 std::string WebString::utf8(UTF8ConversionMode mode) const { |
72 StringUTF8Adaptor utf8(m_private.get()); | 84 StringUTF8Adaptor utf8(m_private.get(), |
| 85 static_cast<WTF::UTF8ConversionMode>(mode)); |
73 return std::string(utf8.data(), utf8.length()); | 86 return std::string(utf8.data(), utf8.length()); |
74 } | 87 } |
75 | 88 |
76 WebString WebString::fromUTF8(const char* data, size_t length) { | 89 WebString WebString::fromUTF8(const char* data, size_t length) { |
77 return String::fromUTF8(data, length); | 90 return String::fromUTF8(data, length); |
78 } | 91 } |
79 | 92 |
80 WebString WebString::fromUTF8(const char* data) { | 93 WebString WebString::fromUTF8(const char* data) { |
81 return String::fromUTF8(data); | 94 return String::fromUTF8(data); |
82 } | 95 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 185 |
173 WebString::operator WTF::AtomicString() const { | 186 WebString::operator WTF::AtomicString() const { |
174 return WTF::AtomicString(m_private.get()); | 187 return WTF::AtomicString(m_private.get()); |
175 } | 188 } |
176 | 189 |
177 void WebString::assign(WTF::StringImpl* p) { | 190 void WebString::assign(WTF::StringImpl* p) { |
178 m_private = p; | 191 m_private = p; |
179 } | 192 } |
180 | 193 |
181 } // namespace blink | 194 } // namespace blink |
OLD | NEW |