OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights
reserved. | 3 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights
reserved. |
4 * Copyright (C) 2009 Google Inc. All rights reserved. | 4 * Copyright (C) 2009 Google Inc. All rights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 friend struct WTF::LCharBufferTranslator; | 115 friend struct WTF::LCharBufferTranslator; |
116 friend struct WTF::SubstringTranslator; | 116 friend struct WTF::SubstringTranslator; |
117 friend struct WTF::UCharBufferTranslator; | 117 friend struct WTF::UCharBufferTranslator; |
118 | 118 |
119 private: | 119 private: |
120 // StringImpls are allocated out of the WTF buffer partition. | 120 // StringImpls are allocated out of the WTF buffer partition. |
121 void* operator new(size_t); | 121 void* operator new(size_t); |
122 void* operator new(size_t, void* ptr) { return ptr; } | 122 void* operator new(size_t, void* ptr) { return ptr; } |
123 void operator delete(void*); | 123 void operator delete(void*); |
124 | 124 |
125 // Used to construct static strings, which have an special refCount that can
never hit zero. | 125 // Used to construct static strings, which have an special refCount that can |
126 // This means that the static string will never be destroyed, which is impor
tant because | 126 // never hit zero. This means that the static string will never be |
127 // static strings will be shared across threads & ref-counted in a non-threa
dsafe manner. | 127 // destroyed, which is important because static strings will be shared |
| 128 // across threads & ref-counted in a non-threadsafe manner. |
128 enum ConstructEmptyStringTag { ConstructEmptyString }; | 129 enum ConstructEmptyStringTag { ConstructEmptyString }; |
129 explicit StringImpl(ConstructEmptyStringTag) | 130 explicit StringImpl(ConstructEmptyStringTag) |
130 : m_refCount(1) | 131 : m_refCount(1) |
131 , m_length(0) | 132 , m_length(0) |
132 , m_hash(0) | 133 , m_hash(0) |
133 , m_isAtomic(false) | 134 , m_isAtomic(false) |
134 , m_is8Bit(true) | 135 , m_is8Bit(true) |
135 , m_isStatic(true) | 136 , m_isStatic(true) |
136 { | 137 { |
137 // Ensure that the hash is computed so that AtomicStringHash can call ex
istingHash() | 138 // Ensure that the hash is computed so that AtomicStringHash can call |
138 // with impunity. The empty string is special because it is never entere
d into | 139 // existingHash() with impunity. The empty string is special because it |
139 // AtomicString's HashKey, but still needs to compare correctly. | 140 // is never entered into AtomicString's HashKey, but still needs to |
| 141 // compare correctly. |
140 STRING_STATS_ADD_8BIT_STRING(m_length); | 142 STRING_STATS_ADD_8BIT_STRING(m_length); |
141 hash(); | 143 hash(); |
142 } | 144 } |
143 | 145 |
144 enum ConstructEmptyString16BitTag { ConstructEmptyString16Bit }; | 146 enum ConstructEmptyString16BitTag { ConstructEmptyString16Bit }; |
145 explicit StringImpl(ConstructEmptyString16BitTag) | 147 explicit StringImpl(ConstructEmptyString16BitTag) |
146 : m_refCount(1) | 148 : m_refCount(1) |
147 , m_length(0) | 149 , m_length(0) |
148 , m_hash(0) | 150 , m_hash(0) |
149 , m_isAtomic(false) | 151 , m_isAtomic(false) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 return create8BitIfPossible(vector.data(), vector.size()); | 210 return create8BitIfPossible(vector.data(), vector.size()); |
209 } | 211 } |
210 | 212 |
211 ALWAYS_INLINE static PassRefPtr<StringImpl> create(const char* s, unsigned l
ength) { return create(reinterpret_cast<const LChar*>(s), length); } | 213 ALWAYS_INLINE static PassRefPtr<StringImpl> create(const char* s, unsigned l
ength) { return create(reinterpret_cast<const LChar*>(s), length); } |
212 static PassRefPtr<StringImpl> create(const LChar*); | 214 static PassRefPtr<StringImpl> create(const LChar*); |
213 ALWAYS_INLINE static PassRefPtr<StringImpl> create(const char* s) { return c
reate(reinterpret_cast<const LChar*>(s)); } | 215 ALWAYS_INLINE static PassRefPtr<StringImpl> create(const char* s) { return c
reate(reinterpret_cast<const LChar*>(s)); } |
214 | 216 |
215 static PassRefPtr<StringImpl> createUninitialized(unsigned length, LChar*& d
ata); | 217 static PassRefPtr<StringImpl> createUninitialized(unsigned length, LChar*& d
ata); |
216 static PassRefPtr<StringImpl> createUninitialized(unsigned length, UChar*& d
ata); | 218 static PassRefPtr<StringImpl> createUninitialized(unsigned length, UChar*& d
ata); |
217 | 219 |
218 // Reallocate the StringImpl. The originalString must be only owned by the P
assRefPtr. | 220 // Reallocate the StringImpl. The originalString must be only owned by the |
219 // Just like the input pointer of realloc(), the originalString can't be use
d after this function. | 221 // PassRefPtr. Just like the input pointer of realloc(), the originalString |
| 222 // can't be used after this function. |
220 static PassRefPtr<StringImpl> reallocate(PassRefPtr<StringImpl> originalStri
ng, unsigned length); | 223 static PassRefPtr<StringImpl> reallocate(PassRefPtr<StringImpl> originalStri
ng, unsigned length); |
221 | 224 |
222 // If this StringImpl has only one reference, we can truncate the string by
updating | 225 // If this StringImpl has only one reference, we can truncate the string by |
223 // its m_length property without actually re-allocating its buffer. | 226 // updating its m_length property without actually re-allocating its buffer. |
224 void truncateAssumingIsolated(unsigned length) | 227 void truncateAssumingIsolated(unsigned length) |
225 { | 228 { |
226 ASSERT(hasOneRef()); | 229 ASSERT(hasOneRef()); |
227 ASSERT(length <= m_length); | 230 ASSERT(length <= m_length); |
228 m_length = length; | 231 m_length = length; |
229 } | 232 } |
230 | 233 |
231 unsigned length() const { return m_length; } | 234 unsigned length() const { return m_length; } |
232 bool is8Bit() const { return m_is8Bit; } | 235 bool is8Bit() const { return m_is8Bit; } |
233 | 236 |
234 ALWAYS_INLINE const LChar* characters8() const { ASSERT(is8Bit()); return re
interpret_cast<const LChar*>(this + 1); } | 237 ALWAYS_INLINE const LChar* characters8() const { ASSERT(is8Bit()); return re
interpret_cast<const LChar*>(this + 1); } |
235 ALWAYS_INLINE const UChar* characters16() const { ASSERT(!is8Bit()); return
reinterpret_cast<const UChar*>(this + 1); } | 238 ALWAYS_INLINE const UChar* characters16() const { ASSERT(!is8Bit()); return
reinterpret_cast<const UChar*>(this + 1); } |
236 | 239 |
237 template <typename CharType> | 240 template <typename CharType> |
238 ALWAYS_INLINE const CharType * getCharacters() const; | 241 ALWAYS_INLINE const CharType * getCharacters() const; |
239 | 242 |
240 size_t sizeInBytes() const; | 243 size_t sizeInBytes() const; |
241 | 244 |
242 bool isAtomic() const { return m_isAtomic; } | 245 bool isAtomic() const { return m_isAtomic; } |
243 void setIsAtomic(bool isAtomic) { m_isAtomic = isAtomic; } | 246 void setIsAtomic(bool isAtomic) { m_isAtomic = isAtomic; } |
244 | 247 |
245 bool isStatic() const { return m_isStatic; } | 248 bool isStatic() const { return m_isStatic; } |
246 | 249 |
247 private: | 250 private: |
248 // The high bits of 'hash' are always empty, but we prefer to store our flag
s | 251 // The high bits of 'hash' are always empty, but we prefer to store our |
249 // in the low bits because it makes them slightly more efficient to access. | 252 // flags in the low bits because it makes them slightly more efficient to |
250 // So, we shift left and right when setting and getting our hash code. | 253 // access. So, we shift left and right when setting and getting our hash |
| 254 // code. |
251 void setHash(unsigned hash) const | 255 void setHash(unsigned hash) const |
252 { | 256 { |
253 ASSERT(!hasHash()); | 257 ASSERT(!hasHash()); |
254 // Multiple clients assume that StringHasher is the canonical string has
h function. | 258 // Multiple clients assume that StringHasher is the canonical string |
| 259 // hash function. |
255 ASSERT(hash == (is8Bit() ? StringHasher::computeHashAndMaskTop8Bits(char
acters8(), m_length) : StringHasher::computeHashAndMaskTop8Bits(characters16(),
m_length))); | 260 ASSERT(hash == (is8Bit() ? StringHasher::computeHashAndMaskTop8Bits(char
acters8(), m_length) : StringHasher::computeHashAndMaskTop8Bits(characters16(),
m_length))); |
256 m_hash = hash; | 261 m_hash = hash; |
257 ASSERT(hash); // Verify that 0 is a valid sentinel hash value. | 262 ASSERT(hash); // Verify that 0 is a valid sentinel hash value. |
258 } | 263 } |
259 | 264 |
260 unsigned rawHash() const | 265 unsigned rawHash() const |
261 { | 266 { |
262 return m_hash; | 267 return m_hash; |
263 } | 268 } |
264 | 269 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 int toIntStrict(bool* ok = 0, int base = 10); | 344 int toIntStrict(bool* ok = 0, int base = 10); |
340 unsigned toUIntStrict(bool* ok = 0, int base = 10); | 345 unsigned toUIntStrict(bool* ok = 0, int base = 10); |
341 int64_t toInt64Strict(bool* ok = 0, int base = 10); | 346 int64_t toInt64Strict(bool* ok = 0, int base = 10); |
342 uint64_t toUInt64Strict(bool* ok = 0, int base = 10); | 347 uint64_t toUInt64Strict(bool* ok = 0, int base = 10); |
343 | 348 |
344 int toInt(bool* ok = 0); // ignores trailing garbage | 349 int toInt(bool* ok = 0); // ignores trailing garbage |
345 unsigned toUInt(bool* ok = 0); // ignores trailing garbage | 350 unsigned toUInt(bool* ok = 0); // ignores trailing garbage |
346 int64_t toInt64(bool* ok = 0); // ignores trailing garbage | 351 int64_t toInt64(bool* ok = 0); // ignores trailing garbage |
347 uint64_t toUInt64(bool* ok = 0); // ignores trailing garbage | 352 uint64_t toUInt64(bool* ok = 0); // ignores trailing garbage |
348 | 353 |
349 // FIXME: Like the strict functions above, these give false for "ok" when th
ere is trailing garbage. | 354 // FIXME: Like the strict functions above, these give false for "ok" when |
350 // Like the non-strict functions above, these return the value when there is
trailing garbage. | 355 // there is trailing garbage. Like the non-strict functions above, these |
351 // It would be better if these were more consistent with the above functions
instead. | 356 // return the value when there is trailing garbage. It would be better if |
| 357 // these were more consistent with the above functions instead. |
352 double toDouble(bool* ok = 0); | 358 double toDouble(bool* ok = 0); |
353 float toFloat(bool* ok = 0); | 359 float toFloat(bool* ok = 0); |
354 | 360 |
355 PassRefPtr<StringImpl> lower(); | 361 PassRefPtr<StringImpl> lower(); |
356 PassRefPtr<StringImpl> upper(); | 362 PassRefPtr<StringImpl> upper(); |
357 PassRefPtr<StringImpl> lower(const AtomicString& localeIdentifier); | 363 PassRefPtr<StringImpl> lower(const AtomicString& localeIdentifier); |
358 PassRefPtr<StringImpl> upper(const AtomicString& localeIdentifier); | 364 PassRefPtr<StringImpl> upper(const AtomicString& localeIdentifier); |
359 | 365 |
360 PassRefPtr<StringImpl> fill(UChar); | 366 PassRefPtr<StringImpl> fill(UChar); |
361 // FIXME: Do we need fill(char) or can we just do the right thing if UChar i
s ASCII? | 367 // FIXME: Do we need fill(char) or can we just do the right thing if UChar i
s ASCII? |
362 PassRefPtr<StringImpl> foldCase(); | 368 PassRefPtr<StringImpl> foldCase(); |
363 | 369 |
364 PassRefPtr<StringImpl> stripWhiteSpace(); | 370 PassRefPtr<StringImpl> stripWhiteSpace(); |
365 PassRefPtr<StringImpl> stripWhiteSpace(IsWhiteSpaceFunctionPtr); | 371 PassRefPtr<StringImpl> stripWhiteSpace(IsWhiteSpaceFunctionPtr); |
366 PassRefPtr<StringImpl> simplifyWhiteSpace(StripBehavior stripBehavior = Stri
pExtraWhiteSpace); | 372 PassRefPtr<StringImpl> simplifyWhiteSpace(StripBehavior = StripExtraWhiteSpa
ce); |
367 PassRefPtr<StringImpl> simplifyWhiteSpace(IsWhiteSpaceFunctionPtr, StripBeha
vior stripBehavior = StripExtraWhiteSpace); | 373 PassRefPtr<StringImpl> simplifyWhiteSpace(IsWhiteSpaceFunctionPtr, StripBeha
vior = StripExtraWhiteSpace); |
368 | 374 |
369 PassRefPtr<StringImpl> removeCharacters(CharacterMatchFunctionPtr); | 375 PassRefPtr<StringImpl> removeCharacters(CharacterMatchFunctionPtr); |
370 template <typename CharType> | 376 template <typename CharType> |
371 ALWAYS_INLINE PassRefPtr<StringImpl> removeCharacters(const CharType* charac
ters, CharacterMatchFunctionPtr); | 377 ALWAYS_INLINE PassRefPtr<StringImpl> removeCharacters(const CharType* charac
ters, CharacterMatchFunctionPtr); |
372 | 378 |
373 size_t find(LChar character, unsigned start = 0); | 379 size_t find(LChar character, unsigned start = 0); |
374 size_t find(char character, unsigned start = 0); | 380 size_t find(char character, unsigned start = 0); |
375 size_t find(UChar character, unsigned start = 0); | 381 size_t find(UChar character, unsigned start = 0); |
376 size_t find(CharacterMatchFunctionPtr, unsigned index = 0); | 382 size_t find(CharacterMatchFunctionPtr, unsigned index = 0); |
377 size_t find(const LChar*, unsigned index = 0); | 383 size_t find(const LChar*, unsigned index = 0); |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 } | 781 } |
776 | 782 |
777 using WTF::StringImpl; | 783 using WTF::StringImpl; |
778 using WTF::equal; | 784 using WTF::equal; |
779 using WTF::equalNonNull; | 785 using WTF::equalNonNull; |
780 using WTF::TextCaseSensitivity; | 786 using WTF::TextCaseSensitivity; |
781 using WTF::TextCaseSensitive; | 787 using WTF::TextCaseSensitive; |
782 using WTF::TextCaseInsensitive; | 788 using WTF::TextCaseInsensitive; |
783 | 789 |
784 #endif | 790 #endif |
OLD | NEW |