| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "wtf/testing/WTFUnitTestHelpersExport.h" | 27 #include "wtf/testing/WTFUnitTestHelpersExport.h" |
| 28 #include "wtf/text/CString.h" | 28 #include "wtf/text/CString.h" |
| 29 #include "wtf/text/WTFString.h" | 29 #include "wtf/text/WTFString.h" |
| 30 #include <iosfwd> | 30 #include <iosfwd> |
| 31 | 31 |
| 32 namespace WTF { | 32 namespace WTF { |
| 33 | 33 |
| 34 struct AtomicStringHash; | 34 struct AtomicStringHash; |
| 35 | 35 |
| 36 class WTF_EXPORT AtomicString { | 36 class WTF_EXPORT AtomicString { |
| 37 USING_FAST_MALLOC(AtomicString); | 37 USING_FAST_MALLOC(AtomicString); |
| 38 public: | 38 |
| 39 static void init(); | 39 public: |
| 40 static void reserveTableCapacity(size_t); | 40 static void init(); |
| 41 | 41 static void reserveTableCapacity(size_t); |
| 42 AtomicString() { } | 42 |
| 43 AtomicString(const LChar* s) : m_string(add(s)) { } | 43 AtomicString() {} |
| 44 AtomicString(const char* s) : m_string(add(s)) { } | 44 AtomicString(const LChar* s) : m_string(add(s)) {} |
| 45 AtomicString(const LChar* s, unsigned length) : m_string(add(s, length)) { } | 45 AtomicString(const char* s) : m_string(add(s)) {} |
| 46 AtomicString(const UChar* s, unsigned length) : m_string(add(s, length)) { } | 46 AtomicString(const LChar* s, unsigned length) : m_string(add(s, length)) {} |
| 47 AtomicString(const UChar* s, unsigned length, unsigned existingHash) : m_str
ing(add(s, length, existingHash)) { } | 47 AtomicString(const UChar* s, unsigned length) : m_string(add(s, length)) {} |
| 48 AtomicString(const UChar* s) : m_string(add(s)) { } | 48 AtomicString(const UChar* s, unsigned length, unsigned existingHash) |
| 49 | 49 : m_string(add(s, length, existingHash)) {} |
| 50 template<size_t inlineCapacity> | 50 AtomicString(const UChar* s) : m_string(add(s)) {} |
| 51 explicit AtomicString(const Vector<UChar, inlineCapacity>& characters) | 51 |
| 52 : m_string(add(characters.data(), characters.size())) | 52 template <size_t inlineCapacity> |
| 53 { | 53 explicit AtomicString(const Vector<UChar, inlineCapacity>& characters) |
| 54 } | 54 : m_string(add(characters.data(), characters.size())) {} |
| 55 | 55 |
| 56 // Constructing an AtomicString from a String / StringImpl can be expensive
if | 56 // Constructing an AtomicString from a String / StringImpl can be expensive if |
| 57 // the StringImpl is not already atomic. | 57 // the StringImpl is not already atomic. |
| 58 explicit AtomicString(StringImpl* impl) : m_string(add(impl)) { } | 58 explicit AtomicString(StringImpl* impl) : m_string(add(impl)) {} |
| 59 explicit AtomicString(const String& s) : m_string(add(s.impl())) { } | 59 explicit AtomicString(const String& s) : m_string(add(s.impl())) {} |
| 60 | 60 |
| 61 AtomicString(StringImpl* baseString, unsigned start, unsigned length) : m_st
ring(add(baseString, start, length)) { } | 61 AtomicString(StringImpl* baseString, unsigned start, unsigned length) |
| 62 | 62 : m_string(add(baseString, start, length)) {} |
| 63 enum ConstructFromLiteralTag { ConstructFromLiteral }; | 63 |
| 64 AtomicString(const char* characters, unsigned length, ConstructFromLiteralTa
g) | 64 enum ConstructFromLiteralTag { ConstructFromLiteral }; |
| 65 : m_string(addFromLiteralData(characters, length)) | 65 AtomicString(const char* characters, unsigned length, ConstructFromLiteralTag) |
| 66 { | 66 : m_string(addFromLiteralData(characters, length)) {} |
| 67 } | 67 |
| 68 | 68 template <unsigned charactersCount> |
| 69 template<unsigned charactersCount> | 69 ALWAYS_INLINE AtomicString(const char (&characters)[charactersCount], |
| 70 ALWAYS_INLINE AtomicString(const char (&characters)[charactersCount], Constr
uctFromLiteralTag) | 70 ConstructFromLiteralTag) |
| 71 : m_string(addFromLiteralData(characters, charactersCount - 1)) | 71 : m_string(addFromLiteralData(characters, charactersCount - 1)) { |
| 72 { | 72 static_assert(charactersCount > 1, |
| 73 static_assert(charactersCount > 1, "AtomicString FromLiteralData should
not be empty"); | 73 "AtomicString FromLiteralData should not be empty"); |
| 74 static_assert((charactersCount - 1 <= ((unsigned(~0) - sizeof(StringImpl
)) / sizeof(LChar))), "AtomicString FromLiteralData cannot overflow"); | 74 static_assert((charactersCount - 1 <= |
| 75 } | 75 ((unsigned(~0) - sizeof(StringImpl)) / sizeof(LChar))), |
| 76 | 76 "AtomicString FromLiteralData cannot overflow"); |
| 77 // Hash table deleted values, which are only constructed and never copied or
destroyed. | 77 } |
| 78 AtomicString(WTF::HashTableDeletedValueType) : m_string(WTF::HashTableDelete
dValue) { } | 78 |
| 79 bool isHashTableDeletedValue() const { return m_string.isHashTableDeletedVal
ue(); } | 79 // Hash table deleted values, which are only constructed and never copied or d
estroyed. |
| 80 | 80 AtomicString(WTF::HashTableDeletedValueType) |
| 81 static StringImpl* find(const StringImpl*); | 81 : m_string(WTF::HashTableDeletedValue) {} |
| 82 | 82 bool isHashTableDeletedValue() const { |
| 83 operator const String&() const { return m_string; } | 83 return m_string.isHashTableDeletedValue(); |
| 84 const String& string() const { return m_string; } | 84 } |
| 85 | 85 |
| 86 StringImpl* impl() const { return m_string.impl(); } | 86 static StringImpl* find(const StringImpl*); |
| 87 | 87 |
| 88 bool is8Bit() const { return m_string.is8Bit(); } | 88 operator const String&() const { return m_string; } |
| 89 const LChar* characters8() const { return m_string.characters8(); } | 89 const String& string() const { return m_string; } |
| 90 const UChar* characters16() const { return m_string.characters16(); } | 90 |
| 91 unsigned length() const { return m_string.length(); } | 91 StringImpl* impl() const { return m_string.impl(); } |
| 92 | 92 |
| 93 UChar operator[](unsigned i) const { return m_string[i]; } | 93 bool is8Bit() const { return m_string.is8Bit(); } |
| 94 | 94 const LChar* characters8() const { return m_string.characters8(); } |
| 95 bool contains(UChar c) const { return m_string.contains(c); } | 95 const UChar* characters16() const { return m_string.characters16(); } |
| 96 bool contains(const LChar* s, TextCaseSensitivity caseSensitivity = TextCase
Sensitive) const | 96 unsigned length() const { return m_string.length(); } |
| 97 { return m_string.contains(s, caseSensitivity); } | 97 |
| 98 bool contains(const String& s, TextCaseSensitivity caseSensitivity = TextCas
eSensitive) const | 98 UChar operator[](unsigned i) const { return m_string[i]; } |
| 99 { return m_string.contains(s, caseSensitivity); } | 99 |
| 100 | 100 bool contains(UChar c) const { return m_string.contains(c); } |
| 101 size_t find(UChar c, size_t start = 0) const { return m_string.find(c, start
); } | 101 bool contains(const LChar* s, |
| 102 size_t find(const LChar* s, size_t start = 0, TextCaseSensitivity caseSensit
ivity = TextCaseSensitive) const | 102 TextCaseSensitivity caseSensitivity = TextCaseSensitive) const { |
| 103 { return m_string.find(s, start, caseSensitivity); } | 103 return m_string.contains(s, caseSensitivity); |
| 104 size_t find(const String& s, size_t start = 0, TextCaseSensitivity caseSensi
tivity = TextCaseSensitive) const | 104 } |
| 105 { return m_string.find(s, start, caseSensitivity); } | 105 bool contains(const String& s, |
| 106 | 106 TextCaseSensitivity caseSensitivity = TextCaseSensitive) const { |
| 107 bool startsWith(const String& s, TextCaseSensitivity caseSensitivity = TextC
aseSensitive) const | 107 return m_string.contains(s, caseSensitivity); |
| 108 { return m_string.startsWith(s, caseSensitivity); } | 108 } |
| 109 bool startsWith(UChar character) const | 109 |
| 110 { return m_string.startsWith(character); } | 110 size_t find(UChar c, size_t start = 0) const { |
| 111 template<unsigned matchLength> | 111 return m_string.find(c, start); |
| 112 bool startsWith(const char (&prefix)[matchLength], TextCaseSensitivity caseS
ensitivity = TextCaseSensitive) const | 112 } |
| 113 { return m_string.startsWith<matchLength>(prefix, caseSensitivity); } | 113 size_t find(const LChar* s, |
| 114 | 114 size_t start = 0, |
| 115 bool endsWith(const String& s, TextCaseSensitivity caseSensitivity = TextCas
eSensitive) const | 115 TextCaseSensitivity caseSensitivity = TextCaseSensitive) const { |
| 116 { return m_string.endsWith(s, caseSensitivity); } | 116 return m_string.find(s, start, caseSensitivity); |
| 117 bool endsWith(UChar character) const | 117 } |
| 118 { return m_string.endsWith(character); } | 118 size_t find(const String& s, |
| 119 template<unsigned matchLength> | 119 size_t start = 0, |
| 120 bool endsWith(const char (&prefix)[matchLength], TextCaseSensitivity caseSen
sitivity = TextCaseSensitive) const | 120 TextCaseSensitivity caseSensitivity = TextCaseSensitive) const { |
| 121 { return m_string.endsWith<matchLength>(prefix, caseSensitivity); } | 121 return m_string.find(s, start, caseSensitivity); |
| 122 | 122 } |
| 123 AtomicString lower() const; | 123 |
| 124 AtomicString lowerASCII() const; | 124 bool startsWith( |
| 125 AtomicString upper() const { return AtomicString(impl()->upper()); } | 125 const String& s, |
| 126 | 126 TextCaseSensitivity caseSensitivity = TextCaseSensitive) const { |
| 127 int toInt(bool* ok = 0) const { return m_string.toInt(ok); } | 127 return m_string.startsWith(s, caseSensitivity); |
| 128 double toDouble(bool* ok = 0) const { return m_string.toDouble(ok); } | 128 } |
| 129 float toFloat(bool* ok = 0) const { return m_string.toFloat(ok); } | 129 bool startsWith(UChar character) const { |
| 130 | 130 return m_string.startsWith(character); |
| 131 static AtomicString number(int); | 131 } |
| 132 static AtomicString number(unsigned); | 132 template <unsigned matchLength> |
| 133 static AtomicString number(long); | 133 bool startsWith( |
| 134 static AtomicString number(unsigned long); | 134 const char (&prefix)[matchLength], |
| 135 static AtomicString number(long long); | 135 TextCaseSensitivity caseSensitivity = TextCaseSensitive) const { |
| 136 static AtomicString number(unsigned long long); | 136 return m_string.startsWith<matchLength>(prefix, caseSensitivity); |
| 137 | 137 } |
| 138 static AtomicString number(double, unsigned precision = 6, TrailingZerosTrun
catingPolicy = TruncateTrailingZeros); | 138 |
| 139 | 139 bool endsWith(const String& s, |
| 140 bool isNull() const { return m_string.isNull(); } | 140 TextCaseSensitivity caseSensitivity = TextCaseSensitive) const { |
| 141 bool isEmpty() const { return m_string.isEmpty(); } | 141 return m_string.endsWith(s, caseSensitivity); |
| 142 | 142 } |
| 143 static void remove(StringImpl*); | 143 bool endsWith(UChar character) const { return m_string.endsWith(character); } |
| 144 template <unsigned matchLength> |
| 145 bool endsWith(const char (&prefix)[matchLength], |
| 146 TextCaseSensitivity caseSensitivity = TextCaseSensitive) const { |
| 147 return m_string.endsWith<matchLength>(prefix, caseSensitivity); |
| 148 } |
| 149 |
| 150 AtomicString lower() const; |
| 151 AtomicString lowerASCII() const; |
| 152 AtomicString upper() const { return AtomicString(impl()->upper()); } |
| 153 |
| 154 int toInt(bool* ok = 0) const { return m_string.toInt(ok); } |
| 155 double toDouble(bool* ok = 0) const { return m_string.toDouble(ok); } |
| 156 float toFloat(bool* ok = 0) const { return m_string.toFloat(ok); } |
| 157 |
| 158 static AtomicString number(int); |
| 159 static AtomicString number(unsigned); |
| 160 static AtomicString number(long); |
| 161 static AtomicString number(unsigned long); |
| 162 static AtomicString number(long long); |
| 163 static AtomicString number(unsigned long long); |
| 164 |
| 165 static AtomicString number( |
| 166 double, |
| 167 unsigned precision = 6, |
| 168 TrailingZerosTruncatingPolicy = TruncateTrailingZeros); |
| 169 |
| 170 bool isNull() const { return m_string.isNull(); } |
| 171 bool isEmpty() const { return m_string.isEmpty(); } |
| 172 |
| 173 static void remove(StringImpl*); |
| 144 | 174 |
| 145 #ifdef __OBJC__ | 175 #ifdef __OBJC__ |
| 146 AtomicString(NSString* s) : m_string(add((CFStringRef)s)) { } | 176 AtomicString(NSString* s) : m_string(add((CFStringRef)s)) {} |
| 147 operator NSString*() const { return m_string; } | 177 operator NSString*() const { return m_string; } |
| 148 #endif | 178 #endif |
| 149 // AtomicString::fromUTF8 will return a null string if | 179 // AtomicString::fromUTF8 will return a null string if |
| 150 // the input data contains invalid UTF-8 sequences. | 180 // the input data contains invalid UTF-8 sequences. |
| 151 static AtomicString fromUTF8(const char*, size_t); | 181 static AtomicString fromUTF8(const char*, size_t); |
| 152 static AtomicString fromUTF8(const char*); | 182 static AtomicString fromUTF8(const char*); |
| 153 | 183 |
| 154 CString ascii() const { return m_string.ascii(); } | 184 CString ascii() const { return m_string.ascii(); } |
| 155 CString latin1() const { return m_string.latin1(); } | 185 CString latin1() const { return m_string.latin1(); } |
| 156 CString utf8(UTF8ConversionMode mode = LenientUTF8Conversion) const { return
m_string.utf8(mode); } | 186 CString utf8(UTF8ConversionMode mode = LenientUTF8Conversion) const { |
| 187 return m_string.utf8(mode); |
| 188 } |
| 157 | 189 |
| 158 #ifndef NDEBUG | 190 #ifndef NDEBUG |
| 159 void show() const; | 191 void show() const; |
| 160 #endif | 192 #endif |
| 161 | 193 |
| 162 private: | 194 private: |
| 163 String m_string; | 195 String m_string; |
| 164 | 196 |
| 165 static PassRefPtr<StringImpl> add(const LChar*); | 197 static PassRefPtr<StringImpl> add(const LChar*); |
| 166 ALWAYS_INLINE static PassRefPtr<StringImpl> add(const char* s) { return add(
reinterpret_cast<const LChar*>(s)); } | 198 ALWAYS_INLINE static PassRefPtr<StringImpl> add(const char* s) { |
| 167 static PassRefPtr<StringImpl> add(const LChar*, unsigned length); | 199 return add(reinterpret_cast<const LChar*>(s)); |
| 168 static PassRefPtr<StringImpl> add(const UChar*, unsigned length); | 200 } |
| 169 ALWAYS_INLINE static PassRefPtr<StringImpl> add(const char* s, unsigned leng
th) { return add(reinterpret_cast<const LChar*>(s), length); } | 201 static PassRefPtr<StringImpl> add(const LChar*, unsigned length); |
| 170 static PassRefPtr<StringImpl> add(const UChar*, unsigned length, unsigned ex
istingHash); | 202 static PassRefPtr<StringImpl> add(const UChar*, unsigned length); |
| 171 static PassRefPtr<StringImpl> add(const UChar*); | 203 ALWAYS_INLINE static PassRefPtr<StringImpl> add(const char* s, |
| 172 static PassRefPtr<StringImpl> add(StringImpl*, unsigned offset, unsigned len
gth); | 204 unsigned length) { |
| 173 ALWAYS_INLINE static PassRefPtr<StringImpl> add(StringImpl* r) | 205 return add(reinterpret_cast<const LChar*>(s), length); |
| 174 { | 206 } |
| 175 if (!r || r->isAtomic()) | 207 static PassRefPtr<StringImpl> add(const UChar*, |
| 176 return r; | 208 unsigned length, |
| 177 return addSlowCase(r); | 209 unsigned existingHash); |
| 178 } | 210 static PassRefPtr<StringImpl> add(const UChar*); |
| 179 static PassRefPtr<StringImpl> addFromLiteralData(const char* characters, uns
igned length); | 211 static PassRefPtr<StringImpl> add(StringImpl*, |
| 180 static PassRefPtr<StringImpl> addSlowCase(StringImpl*); | 212 unsigned offset, |
| 213 unsigned length); |
| 214 ALWAYS_INLINE static PassRefPtr<StringImpl> add(StringImpl* r) { |
| 215 if (!r || r->isAtomic()) |
| 216 return r; |
| 217 return addSlowCase(r); |
| 218 } |
| 219 static PassRefPtr<StringImpl> addFromLiteralData(const char* characters, |
| 220 unsigned length); |
| 221 static PassRefPtr<StringImpl> addSlowCase(StringImpl*); |
| 181 #if OS(MACOSX) | 222 #if OS(MACOSX) |
| 182 static PassRefPtr<StringImpl> add(CFStringRef); | 223 static PassRefPtr<StringImpl> add(CFStringRef); |
| 183 #endif | 224 #endif |
| 184 | 225 |
| 185 static AtomicString fromUTF8Internal(const char*, const char*); | 226 static AtomicString fromUTF8Internal(const char*, const char*); |
| 186 }; | 227 }; |
| 187 | 228 |
| 188 inline bool operator==(const AtomicString& a, const AtomicString& b) { return a.
impl() == b.impl(); } | 229 inline bool operator==(const AtomicString& a, const AtomicString& b) { |
| 230 return a.impl() == b.impl(); |
| 231 } |
| 189 WTF_EXPORT bool operator==(const AtomicString&, const LChar*); | 232 WTF_EXPORT bool operator==(const AtomicString&, const LChar*); |
| 190 inline bool operator==(const AtomicString& a, const char* b) { return WTF::equal
(a.impl(), reinterpret_cast<const LChar*>(b)); } | 233 inline bool operator==(const AtomicString& a, const char* b) { |
| 191 inline bool operator==(const AtomicString& a, const Vector<UChar>& b) { return a
.impl() && equal(a.impl(), b.data(), b.size()); } | 234 return WTF::equal(a.impl(), reinterpret_cast<const LChar*>(b)); |
| 192 inline bool operator==(const AtomicString& a, const String& b) { return equal(a.
impl(), b.impl()); } | 235 } |
| 193 inline bool operator==(const LChar* a, const AtomicString& b) { return b == a; } | 236 inline bool operator==(const AtomicString& a, const Vector<UChar>& b) { |
| 194 inline bool operator==(const char* a, const AtomicString& b) { return b == a; } | 237 return a.impl() && equal(a.impl(), b.data(), b.size()); |
| 195 inline bool operator==(const String& a, const AtomicString& b) { return equal(a.
impl(), b.impl()); } | 238 } |
| 196 inline bool operator==(const Vector<UChar>& a, const AtomicString& b) { return b
== a; } | 239 inline bool operator==(const AtomicString& a, const String& b) { |
| 197 | 240 return equal(a.impl(), b.impl()); |
| 198 inline bool operator!=(const AtomicString& a, const AtomicString& b) { return a.
impl() != b.impl(); } | 241 } |
| 199 inline bool operator!=(const AtomicString& a, const LChar* b) { return !(a == b)
; } | 242 inline bool operator==(const LChar* a, const AtomicString& b) { |
| 200 inline bool operator!=(const AtomicString& a, const char* b) { return !(a == b);
} | 243 return b == a; |
| 201 inline bool operator!=(const AtomicString& a, const String& b) { return !equal(a
.impl(), b.impl()); } | 244 } |
| 202 inline bool operator!=(const AtomicString& a, const Vector<UChar>& b) { return !
(a == b); } | 245 inline bool operator==(const char* a, const AtomicString& b) { |
| 203 inline bool operator!=(const LChar* a, const AtomicString& b) { return !(b == a)
; } | 246 return b == a; |
| 204 inline bool operator!=(const char* a, const AtomicString& b) { return !(b == a);
} | 247 } |
| 205 inline bool operator!=(const String& a, const AtomicString& b) { return !equal(a
.impl(), b.impl()); } | 248 inline bool operator==(const String& a, const AtomicString& b) { |
| 206 inline bool operator!=(const Vector<UChar>& a, const AtomicString& b) { return !
(a == b); } | 249 return equal(a.impl(), b.impl()); |
| 207 | 250 } |
| 208 inline bool equalIgnoringCase(const AtomicString& a, const AtomicString& b) { re
turn equalIgnoringCase(a.impl(), b.impl()); } | 251 inline bool operator==(const Vector<UChar>& a, const AtomicString& b) { |
| 209 inline bool equalIgnoringCase(const AtomicString& a, const LChar* b) { return eq
ualIgnoringCase(a.impl(), b); } | 252 return b == a; |
| 210 inline bool equalIgnoringCase(const AtomicString& a, const char* b) { return equ
alIgnoringCase(a.impl(), reinterpret_cast<const LChar*>(b)); } | 253 } |
| 211 inline bool equalIgnoringCase(const AtomicString& a, const String& b) { return e
qualIgnoringCase(a.impl(), b.impl()); } | 254 |
| 212 inline bool equalIgnoringCase(const LChar* a, const AtomicString& b) { return eq
ualIgnoringCase(a, b.impl()); } | 255 inline bool operator!=(const AtomicString& a, const AtomicString& b) { |
| 213 inline bool equalIgnoringCase(const char* a, const AtomicString& b) { return equ
alIgnoringCase(reinterpret_cast<const LChar*>(a), b.impl()); } | 256 return a.impl() != b.impl(); |
| 214 inline bool equalIgnoringCase(const String& a, const AtomicString& b) { return e
qualIgnoringCase(a.impl(), b.impl()); } | 257 } |
| 258 inline bool operator!=(const AtomicString& a, const LChar* b) { |
| 259 return !(a == b); |
| 260 } |
| 261 inline bool operator!=(const AtomicString& a, const char* b) { |
| 262 return !(a == b); |
| 263 } |
| 264 inline bool operator!=(const AtomicString& a, const String& b) { |
| 265 return !equal(a.impl(), b.impl()); |
| 266 } |
| 267 inline bool operator!=(const AtomicString& a, const Vector<UChar>& b) { |
| 268 return !(a == b); |
| 269 } |
| 270 inline bool operator!=(const LChar* a, const AtomicString& b) { |
| 271 return !(b == a); |
| 272 } |
| 273 inline bool operator!=(const char* a, const AtomicString& b) { |
| 274 return !(b == a); |
| 275 } |
| 276 inline bool operator!=(const String& a, const AtomicString& b) { |
| 277 return !equal(a.impl(), b.impl()); |
| 278 } |
| 279 inline bool operator!=(const Vector<UChar>& a, const AtomicString& b) { |
| 280 return !(a == b); |
| 281 } |
| 282 |
| 283 inline bool equalIgnoringCase(const AtomicString& a, const AtomicString& b) { |
| 284 return equalIgnoringCase(a.impl(), b.impl()); |
| 285 } |
| 286 inline bool equalIgnoringCase(const AtomicString& a, const LChar* b) { |
| 287 return equalIgnoringCase(a.impl(), b); |
| 288 } |
| 289 inline bool equalIgnoringCase(const AtomicString& a, const char* b) { |
| 290 return equalIgnoringCase(a.impl(), reinterpret_cast<const LChar*>(b)); |
| 291 } |
| 292 inline bool equalIgnoringCase(const AtomicString& a, const String& b) { |
| 293 return equalIgnoringCase(a.impl(), b.impl()); |
| 294 } |
| 295 inline bool equalIgnoringCase(const LChar* a, const AtomicString& b) { |
| 296 return equalIgnoringCase(a, b.impl()); |
| 297 } |
| 298 inline bool equalIgnoringCase(const char* a, const AtomicString& b) { |
| 299 return equalIgnoringCase(reinterpret_cast<const LChar*>(a), b.impl()); |
| 300 } |
| 301 inline bool equalIgnoringCase(const String& a, const AtomicString& b) { |
| 302 return equalIgnoringCase(a.impl(), b.impl()); |
| 303 } |
| 215 | 304 |
| 216 // Define external global variables for the commonly used atomic strings. | 305 // Define external global variables for the commonly used atomic strings. |
| 217 // These are only usable from the main thread. | 306 // These are only usable from the main thread. |
| 218 WTF_EXPORT extern const AtomicString& nullAtom; | 307 WTF_EXPORT extern const AtomicString& nullAtom; |
| 219 WTF_EXPORT extern const AtomicString& emptyAtom; | 308 WTF_EXPORT extern const AtomicString& emptyAtom; |
| 220 WTF_EXPORT extern const AtomicString& starAtom; | 309 WTF_EXPORT extern const AtomicString& starAtom; |
| 221 WTF_EXPORT extern const AtomicString& xmlAtom; | 310 WTF_EXPORT extern const AtomicString& xmlAtom; |
| 222 WTF_EXPORT extern const AtomicString& xmlnsAtom; | 311 WTF_EXPORT extern const AtomicString& xmlnsAtom; |
| 223 WTF_EXPORT extern const AtomicString& xlinkAtom; | 312 WTF_EXPORT extern const AtomicString& xlinkAtom; |
| 224 | 313 |
| 225 inline AtomicString AtomicString::fromUTF8(const char* characters, size_t length
) | 314 inline AtomicString AtomicString::fromUTF8(const char* characters, |
| 226 { | 315 size_t length) { |
| 227 if (!characters) | 316 if (!characters) |
| 228 return nullAtom; | 317 return nullAtom; |
| 229 if (!length) | 318 if (!length) |
| 230 return emptyAtom; | 319 return emptyAtom; |
| 231 return fromUTF8Internal(characters, characters + length); | 320 return fromUTF8Internal(characters, characters + length); |
| 232 } | 321 } |
| 233 | 322 |
| 234 inline AtomicString AtomicString::fromUTF8(const char* characters) | 323 inline AtomicString AtomicString::fromUTF8(const char* characters) { |
| 235 { | 324 if (!characters) |
| 236 if (!characters) | 325 return nullAtom; |
| 237 return nullAtom; | 326 if (!*characters) |
| 238 if (!*characters) | 327 return emptyAtom; |
| 239 return emptyAtom; | 328 return fromUTF8Internal(characters, 0); |
| 240 return fromUTF8Internal(characters, 0); | |
| 241 } | 329 } |
| 242 | 330 |
| 243 // AtomicStringHash is the default hash for AtomicString | 331 // AtomicStringHash is the default hash for AtomicString |
| 244 template<typename T> struct DefaultHash; | 332 template <typename T> |
| 245 template<> struct DefaultHash<AtomicString> { | 333 struct DefaultHash; |
| 246 typedef AtomicStringHash Hash; | 334 template <> |
| 335 struct DefaultHash<AtomicString> { |
| 336 typedef AtomicStringHash Hash; |
| 247 }; | 337 }; |
| 248 | 338 |
| 249 // Pretty printer for gtest. | 339 // Pretty printer for gtest. |
| 250 WTF_UNITTEST_HELPERS_EXPORT std::ostream& operator<<(std::ostream&, const Atomic
String&); | 340 WTF_UNITTEST_HELPERS_EXPORT std::ostream& operator<<(std::ostream&, |
| 341 const AtomicString&); |
| 251 | 342 |
| 252 } // namespace WTF | 343 } // namespace WTF |
| 253 | 344 |
| 254 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(AtomicString); | 345 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(AtomicString); |
| 255 | 346 |
| 256 using WTF::AtomicString; | 347 using WTF::AtomicString; |
| 257 using WTF::nullAtom; | 348 using WTF::nullAtom; |
| 258 using WTF::emptyAtom; | 349 using WTF::emptyAtom; |
| 259 using WTF::starAtom; | 350 using WTF::starAtom; |
| 260 using WTF::xmlAtom; | 351 using WTF::xmlAtom; |
| 261 using WTF::xmlnsAtom; | 352 using WTF::xmlnsAtom; |
| 262 using WTF::xlinkAtom; | 353 using WTF::xlinkAtom; |
| 263 | 354 |
| 264 #include "wtf/text/StringConcatenate.h" | 355 #include "wtf/text/StringConcatenate.h" |
| 265 #endif // AtomicString_h | 356 #endif // AtomicString_h |
| OLD | NEW |