| OLD | NEW |
| 1 /* | 1 /* |
| 2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc.
All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc.
All rights reserved. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 WTF_EXPORT int charactersToInt(const LChar*, size_t, bool* ok = 0); // ignores t
railing garbage | 57 WTF_EXPORT int charactersToInt(const LChar*, size_t, bool* ok = 0); // ignores t
railing garbage |
| 58 WTF_EXPORT int charactersToInt(const UChar*, size_t, bool* ok = 0); // ignores t
railing garbage | 58 WTF_EXPORT int charactersToInt(const UChar*, size_t, bool* ok = 0); // ignores t
railing garbage |
| 59 WTF_EXPORT unsigned charactersToUInt(const LChar*, size_t, bool* ok = 0); // ign
ores trailing garbage | 59 WTF_EXPORT unsigned charactersToUInt(const LChar*, size_t, bool* ok = 0); // ign
ores trailing garbage |
| 60 WTF_EXPORT unsigned charactersToUInt(const UChar*, size_t, bool* ok = 0); // ign
ores trailing garbage | 60 WTF_EXPORT unsigned charactersToUInt(const UChar*, size_t, bool* ok = 0); // ign
ores trailing garbage |
| 61 WTF_EXPORT int64_t charactersToInt64(const LChar*, size_t, bool* ok = 0); // ign
ores trailing garbage | 61 WTF_EXPORT int64_t charactersToInt64(const LChar*, size_t, bool* ok = 0); // ign
ores trailing garbage |
| 62 WTF_EXPORT int64_t charactersToInt64(const UChar*, size_t, bool* ok = 0); // ign
ores trailing garbage | 62 WTF_EXPORT int64_t charactersToInt64(const UChar*, size_t, bool* ok = 0); // ign
ores trailing garbage |
| 63 WTF_EXPORT uint64_t charactersToUInt64(const LChar*, size_t, bool* ok = 0); // i
gnores trailing garbage | 63 WTF_EXPORT uint64_t charactersToUInt64(const LChar*, size_t, bool* ok = 0); // i
gnores trailing garbage |
| 64 WTF_EXPORT uint64_t charactersToUInt64(const UChar*, size_t, bool* ok = 0); // i
gnores trailing garbage | 64 WTF_EXPORT uint64_t charactersToUInt64(const UChar*, size_t, bool* ok = 0); // i
gnores trailing garbage |
| 65 | 65 |
| 66 // FIXME: Like the strict functions above, these give false for "ok" when there
is trailing garbage. | 66 // FIXME: Like the strict functions above, these give false for "ok" when there |
| 67 // Like the non-strict functions above, these return the value when there is tra
iling garbage. | 67 // is trailing garbage. Like the non-strict functions above, these return the |
| 68 // It would be better if these were more consistent with the above functions ins
tead. | 68 // value when there is trailing garbage. It would be better if these were more |
| 69 // consistent with the above functions instead. |
| 69 WTF_EXPORT double charactersToDouble(const LChar*, size_t, bool* ok = 0); | 70 WTF_EXPORT double charactersToDouble(const LChar*, size_t, bool* ok = 0); |
| 70 WTF_EXPORT double charactersToDouble(const UChar*, size_t, bool* ok = 0); | 71 WTF_EXPORT double charactersToDouble(const UChar*, size_t, bool* ok = 0); |
| 71 WTF_EXPORT float charactersToFloat(const LChar*, size_t, bool* ok = 0); | 72 WTF_EXPORT float charactersToFloat(const LChar*, size_t, bool* ok = 0); |
| 72 WTF_EXPORT float charactersToFloat(const UChar*, size_t, bool* ok = 0); | 73 WTF_EXPORT float charactersToFloat(const UChar*, size_t, bool* ok = 0); |
| 73 WTF_EXPORT float charactersToFloat(const LChar*, size_t, size_t& parsedLength); | 74 WTF_EXPORT float charactersToFloat(const LChar*, size_t, size_t& parsedLength); |
| 74 WTF_EXPORT float charactersToFloat(const UChar*, size_t, size_t& parsedLength); | 75 WTF_EXPORT float charactersToFloat(const UChar*, size_t, size_t& parsedLength); |
| 75 | 76 |
| 76 enum TrailingZerosTruncatingPolicy { | 77 enum TrailingZerosTruncatingPolicy { |
| 77 KeepTrailingZeros, | 78 KeepTrailingZeros, |
| 78 TruncateTrailingZeros | 79 TruncateTrailingZeros |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 static String number(unsigned long); | 192 static String number(unsigned long); |
| 192 static String number(long long); | 193 static String number(long long); |
| 193 static String number(unsigned long long); | 194 static String number(unsigned long long); |
| 194 | 195 |
| 195 static String number(double, unsigned precision = 6, TrailingZerosTruncating
Policy = TruncateTrailingZeros); | 196 static String number(double, unsigned precision = 6, TrailingZerosTruncating
Policy = TruncateTrailingZeros); |
| 196 | 197 |
| 197 // Number to String conversion following the ECMAScript definition. | 198 // Number to String conversion following the ECMAScript definition. |
| 198 static String numberToStringECMAScript(double); | 199 static String numberToStringECMAScript(double); |
| 199 static String numberToStringFixedWidth(double, unsigned decimalPlaces); | 200 static String numberToStringFixedWidth(double, unsigned decimalPlaces); |
| 200 | 201 |
| 201 // Find a single character or string, also with match function & latin1 form
s. | 202 // Find a single character or string, also with match function & latin1 |
| 203 // forms. |
| 202 size_t find(UChar c, unsigned start = 0) const | 204 size_t find(UChar c, unsigned start = 0) const |
| 203 { return m_impl ? m_impl->find(c, start) : kNotFound; } | 205 { return m_impl ? m_impl->find(c, start) : kNotFound; } |
| 204 size_t find(LChar c, unsigned start = 0) const | 206 size_t find(LChar c, unsigned start = 0) const |
| 205 { return m_impl ? m_impl->find(c, start) : kNotFound; } | 207 { return m_impl ? m_impl->find(c, start) : kNotFound; } |
| 206 size_t find(char c, unsigned start = 0) const { return find(static_cast<LCha
r>(c), start); } | 208 size_t find(char c, unsigned start = 0) const { return find(static_cast<LCha
r>(c), start); } |
| 207 | 209 |
| 208 size_t find(const String& str) const | 210 size_t find(const String& str) const |
| 209 { return m_impl ? m_impl->find(str.impl()) : kNotFound; } | 211 { return m_impl ? m_impl->find(str.impl()) : kNotFound; } |
| 210 size_t find(const String& str, unsigned start) const | 212 size_t find(const String& str, unsigned start) const |
| 211 { return m_impl ? m_impl->find(str.impl(), start) : kNotFound; } | 213 { return m_impl ? m_impl->find(str.impl(), start) : kNotFound; } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 void append(LChar); | 280 void append(LChar); |
| 279 void append(char c) { append(static_cast<LChar>(c)); } | 281 void append(char c) { append(static_cast<LChar>(c)); } |
| 280 void append(UChar); | 282 void append(UChar); |
| 281 void append(const LChar*, unsigned length); | 283 void append(const LChar*, unsigned length); |
| 282 void append(const char* charactersToAppend, unsigned length) { append(reinte
rpret_cast<const LChar*>(charactersToAppend), length); } | 284 void append(const char* charactersToAppend, unsigned length) { append(reinte
rpret_cast<const LChar*>(charactersToAppend), length); } |
| 283 void append(const UChar*, unsigned length); | 285 void append(const UChar*, unsigned length); |
| 284 void insert(const String&, unsigned pos); | 286 void insert(const String&, unsigned pos); |
| 285 void insert(const LChar*, unsigned length, unsigned pos); | 287 void insert(const LChar*, unsigned length, unsigned pos); |
| 286 void insert(const UChar*, unsigned length, unsigned pos); | 288 void insert(const UChar*, unsigned length, unsigned pos); |
| 287 | 289 |
| 288 String& replace(UChar a, UChar b) { if (m_impl) m_impl = m_impl->replace(a,
b); return *this; } | 290 String& replace(UChar a, UChar b) |
| 289 String& replace(UChar a, const String& b) { if (m_impl) m_impl = m_impl->rep
lace(a, b.impl()); return *this; } | 291 { |
| 290 String& replace(const String& a, const String& b) { if (m_impl) m_impl = m_i
mpl->replace(a.impl(), b.impl()); return *this; } | 292 if (m_impl) |
| 291 String& replace(unsigned index, unsigned len, const String& b) { if (m_impl)
m_impl = m_impl->replace(index, len, b.impl()); return *this; } | 293 m_impl = m_impl->replace(a, b); |
| 294 return *this; |
| 295 } |
| 296 String& replace(UChar a, const String& b) |
| 297 { |
| 298 if (m_impl) |
| 299 m_impl = m_impl->replace(a, b.impl()); |
| 300 return *this; |
| 301 } |
| 302 String& replace(const String& a, const String& b) |
| 303 { |
| 304 if (m_impl) |
| 305 m_impl = m_impl->replace(a.impl(), b.impl()); |
| 306 return *this; |
| 307 } |
| 308 String& replace(unsigned index, unsigned len, const String& b) |
| 309 { |
| 310 if (m_impl) |
| 311 m_impl = m_impl->replace(index, len, b.impl()); |
| 312 return *this; |
| 313 } |
| 292 | 314 |
| 293 template<unsigned charactersCount> | 315 template<unsigned charactersCount> |
| 294 ALWAYS_INLINE String& replaceWithLiteral(UChar a, const char (&characters)[c
haractersCount]) | 316 ALWAYS_INLINE String& replaceWithLiteral(UChar a, const char (&characters)[c
haractersCount]) |
| 295 { | 317 { |
| 296 if (m_impl) | 318 if (m_impl) |
| 297 m_impl = m_impl->replace(a, characters, charactersCount - 1); | 319 m_impl = m_impl->replace(a, characters, charactersCount - 1); |
| 298 | 320 |
| 299 return *this; | 321 return *this; |
| 300 } | 322 } |
| 301 | 323 |
| 302 void fill(UChar c) { if (m_impl) m_impl = m_impl->fill(c); } | 324 void fill(UChar c) |
| 325 { |
| 326 if (m_impl) |
| 327 m_impl = m_impl->fill(c); |
| 328 } |
| 303 | 329 |
| 304 void ensure16Bit(); | 330 void ensure16Bit(); |
| 305 | 331 |
| 306 void truncate(unsigned len); | 332 void truncate(unsigned len); |
| 307 void remove(unsigned pos, int len = 1); | 333 void remove(unsigned pos, int len = 1); |
| 308 | 334 |
| 309 String substring(unsigned pos, unsigned len = UINT_MAX) const; | 335 String substring(unsigned pos, unsigned len = UINT_MAX) const; |
| 310 String left(unsigned len) const { return substring(0, len); } | 336 String left(unsigned len) const { return substring(0, len); } |
| 311 String right(unsigned len) const { return substring(length() - len, len); } | 337 String right(unsigned len) const { return substring(length() - len, len); } |
| 312 | 338 |
| 313 StringView createView() const { return StringView(impl()); } | 339 StringView createView() const { return StringView(impl()); } |
| 314 StringView createView(unsigned offset, unsigned length) const { return Strin
gView(impl(), offset, length); } | 340 StringView createView(unsigned offset, unsigned length) const { return Strin
gView(impl(), offset, length); } |
| 315 | 341 |
| 316 // Returns a lowercase/uppercase version of the string | 342 // Returns a lowercase/uppercase version of the string |
| 317 String lower() const; | 343 String lower() const; |
| 318 String upper() const; | 344 String upper() const; |
| 319 | 345 |
| 320 String lower(const AtomicString& localeIdentifier) const; | 346 String lower(const AtomicString& localeIdentifier) const; |
| 321 String upper(const AtomicString& localeIdentifier) const; | 347 String upper(const AtomicString& localeIdentifier) const; |
| 322 | 348 |
| 323 String stripWhiteSpace() const; | 349 String stripWhiteSpace() const; |
| 324 String stripWhiteSpace(IsWhiteSpaceFunctionPtr) const; | 350 String stripWhiteSpace(IsWhiteSpaceFunctionPtr) const; |
| 325 String simplifyWhiteSpace(StripBehavior stripBehavior = StripExtraWhiteSpace
) const; | 351 String simplifyWhiteSpace(StripBehavior = StripExtraWhiteSpace) const; |
| 326 String simplifyWhiteSpace(IsWhiteSpaceFunctionPtr, StripBehavior stripBehavi
or = StripExtraWhiteSpace) const; | 352 String simplifyWhiteSpace(IsWhiteSpaceFunctionPtr, StripBehavior = StripExtr
aWhiteSpace) const; |
| 327 | 353 |
| 328 String removeCharacters(CharacterMatchFunctionPtr) const; | 354 String removeCharacters(CharacterMatchFunctionPtr) const; |
| 329 template<bool isSpecialCharacter(UChar)> bool isAllSpecialCharacters() const
; | 355 template<bool isSpecialCharacter(UChar)> bool isAllSpecialCharacters() const
; |
| 330 | 356 |
| 331 // Return the string with case folded for case insensitive comparison. | 357 // Return the string with case folded for case insensitive comparison. |
| 332 String foldCase() const; | 358 String foldCase() const; |
| 333 | 359 |
| 334 static String format(const char *, ...) WTF_ATTRIBUTE_PRINTF(1, 2); | 360 static String format(const char *, ...) WTF_ATTRIBUTE_PRINTF(1, 2); |
| 335 | 361 |
| 336 // Returns an uninitialized string. The characters needs to be written | 362 // Returns an uninitialized string. The characters needs to be written |
| (...skipping 16 matching lines...) Expand all Loading... |
| 353 int toIntStrict(bool* ok = 0, int base = 10) const; | 379 int toIntStrict(bool* ok = 0, int base = 10) const; |
| 354 unsigned toUIntStrict(bool* ok = 0, int base = 10) const; | 380 unsigned toUIntStrict(bool* ok = 0, int base = 10) const; |
| 355 int64_t toInt64Strict(bool* ok = 0, int base = 10) const; | 381 int64_t toInt64Strict(bool* ok = 0, int base = 10) const; |
| 356 uint64_t toUInt64Strict(bool* ok = 0, int base = 10) const; | 382 uint64_t toUInt64Strict(bool* ok = 0, int base = 10) const; |
| 357 | 383 |
| 358 int toInt(bool* ok = 0) const; | 384 int toInt(bool* ok = 0) const; |
| 359 unsigned toUInt(bool* ok = 0) const; | 385 unsigned toUInt(bool* ok = 0) const; |
| 360 int64_t toInt64(bool* ok = 0) const; | 386 int64_t toInt64(bool* ok = 0) const; |
| 361 uint64_t toUInt64(bool* ok = 0) const; | 387 uint64_t toUInt64(bool* ok = 0) const; |
| 362 | 388 |
| 363 // FIXME: Like the strict functions above, these give false for "ok" when th
ere is trailing garbage. | 389 // FIXME: Like the strict functions above, these give false for "ok" when |
| 364 // Like the non-strict functions above, these return the value when there is
trailing garbage. | 390 // there is trailing garbage. Like the non-strict functions above, these |
| 365 // It would be better if these were more consistent with the above functions
instead. | 391 // return the value when there is trailing garbage. It would be better if |
| 392 // these were more consistent with the above functions instead. |
| 366 double toDouble(bool* ok = 0) const; | 393 double toDouble(bool* ok = 0) const; |
| 367 float toFloat(bool* ok = 0) const; | 394 float toFloat(bool* ok = 0) const; |
| 368 | 395 |
| 369 String isolatedCopy() const; | 396 String isolatedCopy() const; |
| 370 bool isSafeToSendToAnotherThread() const; | 397 bool isSafeToSendToAnotherThread() const; |
| 371 | 398 |
| 372 #if USE(CF) | 399 #if USE(CF) |
| 373 String(CFStringRef); | 400 String(CFStringRef); |
| 374 RetainPtr<CFStringRef> createCFString() const; | 401 RetainPtr<CFStringRef> createCFString() const; |
| 375 #endif | 402 #endif |
| 376 | 403 |
| 377 #ifdef __OBJC__ | 404 #ifdef __OBJC__ |
| 378 String(NSString*); | 405 String(NSString*); |
| 379 | 406 |
| 380 // This conversion maps NULL to "", which loses the meaning of NULL, but we | 407 // This conversion maps null string to "", which loses the meaning of null |
| 381 // need this mapping because AppKit crashes when passed nil NSStrings. | 408 // string, but we need this mapping because AppKit crashes when passed nil |
| 382 operator NSString*() const { if (!m_impl) return @""; return *m_impl; } | 409 // NSStrings. |
| 410 operator NSString*() const |
| 411 { |
| 412 if (!m_impl) |
| 413 return @""; |
| 414 return *m_impl; |
| 415 } |
| 383 #endif | 416 #endif |
| 384 | 417 |
| 385 static String make8BitFrom16BitSource(const UChar*, size_t); | 418 static String make8BitFrom16BitSource(const UChar*, size_t); |
| 386 template<size_t inlineCapacity> | 419 template<size_t inlineCapacity> |
| 387 static String make8BitFrom16BitSource(const Vector<UChar, inlineCapacity>& b
uffer) | 420 static String make8BitFrom16BitSource(const Vector<UChar, inlineCapacity>& b
uffer) |
| 388 { | 421 { |
| 389 return make8BitFrom16BitSource(buffer.data(), buffer.size()); | 422 return make8BitFrom16BitSource(buffer.data(), buffer.size()); |
| 390 } | 423 } |
| 391 | 424 |
| 392 static String make16BitFrom8BitSource(const LChar*, size_t); | 425 static String make16BitFrom8BitSource(const LChar*, size_t); |
| 393 | 426 |
| 394 // String::fromUTF8 will return a null string if | 427 // String::fromUTF8 will return a null string if |
| 395 // the input data contains invalid UTF-8 sequences. | 428 // the input data contains invalid UTF-8 sequences. |
| 396 static String fromUTF8(const LChar*, size_t); | 429 static String fromUTF8(const LChar*, size_t); |
| 397 static String fromUTF8(const LChar*); | 430 static String fromUTF8(const LChar*); |
| 398 static String fromUTF8(const char* s, size_t length) { return fromUTF8(reint
erpret_cast<const LChar*>(s), length); } | 431 static String fromUTF8(const char* s, size_t length) { return fromUTF8(reint
erpret_cast<const LChar*>(s), length); } |
| 399 static String fromUTF8(const char* s) { return fromUTF8(reinterpret_cast<con
st LChar*>(s)); } | 432 static String fromUTF8(const char* s) { return fromUTF8(reinterpret_cast<con
st LChar*>(s)); } |
| 400 static String fromUTF8(const CString&); | 433 static String fromUTF8(const CString&); |
| 401 | 434 |
| 402 // Tries to convert the passed in string to UTF-8, but will fall back to Lat
in-1 if the string is not valid UTF-8. | 435 // Tries to convert the passed in string to UTF-8, but will fall back to |
| 436 // Latin-1 if the string is not valid UTF-8. |
| 403 static String fromUTF8WithLatin1Fallback(const LChar*, size_t); | 437 static String fromUTF8WithLatin1Fallback(const LChar*, size_t); |
| 404 static String fromUTF8WithLatin1Fallback(const char* s, size_t length) { ret
urn fromUTF8WithLatin1Fallback(reinterpret_cast<const LChar*>(s), length); } | 438 static String fromUTF8WithLatin1Fallback(const char* s, size_t length) { ret
urn fromUTF8WithLatin1Fallback(reinterpret_cast<const LChar*>(s), length); } |
| 405 | 439 |
| 406 bool containsOnlyASCII() const; | 440 bool containsOnlyASCII() const; |
| 407 bool containsOnlyLatin1() const; | 441 bool containsOnlyLatin1() const; |
| 408 bool containsOnlyWhitespace() const { return !m_impl || m_impl->containsOnly
Whitespace(); } | 442 bool containsOnlyWhitespace() const { return !m_impl || m_impl->containsOnly
Whitespace(); } |
| 409 | 443 |
| 410 // Hash table deleted values, which are only constructed and never copied or
destroyed. | 444 // Hash table deleted values, which are only constructed and never copied or |
| 445 // destroyed. |
| 411 String(WTF::HashTableDeletedValueType) : m_impl(WTF::HashTableDeletedValue)
{ } | 446 String(WTF::HashTableDeletedValueType) : m_impl(WTF::HashTableDeletedValue)
{ } |
| 412 bool isHashTableDeletedValue() const { return m_impl.isHashTableDeletedValue
(); } | 447 bool isHashTableDeletedValue() const { return m_impl.isHashTableDeletedValue
(); } |
| 413 | 448 |
| 414 #ifndef NDEBUG | 449 #ifndef NDEBUG |
| 415 void show() const; | 450 void show() const; |
| 416 #endif | 451 #endif |
| 417 | 452 |
| 418 // Workaround for a compiler bug. Use operator[] instead. | 453 // Workaround for a compiler bug. Use operator[] instead. |
| 419 UChar characterAt(unsigned index) const | 454 UChar characterAt(unsigned index) const |
| 420 { | 455 { |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 using WTF::charactersToFloat; | 698 using WTF::charactersToFloat; |
| 664 using WTF::equal; | 699 using WTF::equal; |
| 665 using WTF::equalIgnoringCase; | 700 using WTF::equalIgnoringCase; |
| 666 using WTF::find; | 701 using WTF::find; |
| 667 using WTF::isAllSpecialCharacters; | 702 using WTF::isAllSpecialCharacters; |
| 668 using WTF::isSpaceOrNewline; | 703 using WTF::isSpaceOrNewline; |
| 669 using WTF::reverseFind; | 704 using WTF::reverseFind; |
| 670 | 705 |
| 671 #include "wtf/text/AtomicString.h" | 706 #include "wtf/text/AtomicString.h" |
| 672 #endif // WTFString_h | 707 #endif // WTFString_h |
| OLD | NEW |