Changeset 277355 in webkit
- Timestamp:
- May 11, 2021, 9:23:30 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 25 edited
-
Source/WTF/ChangeLog (modified) (1 diff)
-
Source/WTF/wtf/text/AtomString.h (modified) (1 diff)
-
Source/WTF/wtf/text/StringImpl.cpp (modified) (1 diff)
-
Source/WTF/wtf/text/StringImpl.h (modified) (1 diff)
-
Source/WTF/wtf/text/StringToIntegerConversion.h (modified) (1 diff)
-
Source/WTF/wtf/text/StringView.cpp (modified) (1 diff)
-
Source/WTF/wtf/text/StringView.h (modified) (4 diffs)
-
Source/WTF/wtf/text/WTFString.cpp (modified) (2 diffs)
-
Source/WTF/wtf/text/WTFString.h (modified) (3 diffs)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/platform/graphics/GLContext.cpp (modified) (2 diffs)
-
Source/WebCore/platform/graphics/GlyphBuffer.h (modified) (1 diff)
-
Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp (modified) (1 diff)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/Shared/win/AuxiliaryProcessMainWin.cpp (modified) (2 diffs)
-
Source/WebKit/UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp (modified) (2 diffs)
-
Source/WebKit/UIProcess/Inspector/socket/RemoteInspectorProtocolHandler.cpp (modified) (2 diffs)
-
Source/WebKit/UIProcess/win/WebProcessPoolWin.cpp (modified) (2 diffs)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/CMakeLists.txt (modified) (1 diff)
-
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (modified) (4 diffs)
-
Tools/TestWebKitAPI/Tests/WTF/StringToIntegerConversion.cpp (added)
-
Tools/TestWebKitAPI/Tests/WTF/StringView.cpp (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm (modified) (2 diffs)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r277354 r277355 1 2021-05-11 Darin Adler <darin@apple.com> 2 3 Remove the String::toInt family of functions 4 https://bugs.webkit.org/show_bug.cgi?id=225599 5 6 Reviewed by Anders Carlsson. 7 8 * wtf/text/AtomString.h: Deleted AtomString::toInt. 9 10 * wtf/text/StringImpl.cpp: 11 (WTF::StringImpl::toIntStrict): Deleted. 12 (WTF::StringImpl::toUIntStrict): Deleted. 13 (WTF::StringImpl::toInt64Strict): Deleted. 14 (WTF::StringImpl::toUInt64Strict): Deleted. 15 (WTF::StringImpl::toIntPtrStrict): Deleted. 16 (WTF::StringImpl::toInt): Deleted. 17 (WTF::StringImpl::toUInt): Deleted. 18 (WTF::StringImpl::toInt64): Deleted. 19 (WTF::StringImpl::toUInt64): Deleted. 20 (WTF::StringImpl::toIntPtr): Deleted. 21 * wtf/text/StringImpl.h: Deleted the above functions. 22 23 * wtf/text/StringToIntegerConversion.h: Removed toIntegralType. 24 25 * wtf/text/StringView.cpp: 26 (WTF::parseUInt16): Deleted. 27 28 * wtf/text/StringView.h: Deleted StringView::toInt, 29 StringView::toIntStrict, StringView::toUInt64Strict, 30 StringView::toInt64Strict, and parseUInt16. Changed the constructor 31 that takes a const char* to work when passed nullptr. StringView has 32 a null value, and converting a null const char* should produce that. 33 34 * wtf/text/WTFString.cpp: 35 (WTF::String::toIntStrict const): Deleted. 36 (WTF::String::toUIntStrict const): Deleted. 37 (WTF::String::toInt64Strict const): Deleted. 38 (WTF::String::toUInt64Strict const): Deleted. 39 (WTF::String::toIntPtrStrict const): Deleted. 40 (WTF::String::toInt const): Deleted. 41 (WTF::String::toUInt const): Deleted. 42 (WTF::String::toInt64 const): Deleted. 43 (WTF::String::toUInt64 const): Deleted. 44 (WTF::String::toIntPtr const): Deleted. 45 (WTF::lengthOfCharactersAsInteger): Deleted. 46 (WTF::charactersToIntStrict): Deleted. 47 (WTF::charactersToUIntStrict): Deleted. 48 (WTF::charactersToInt64Strict): Deleted. 49 (WTF::charactersToUInt64Strict): Deleted. 50 (WTF::charactersToIntPtrStrict): Deleted. 51 (WTF::charactersToInt): Deleted. 52 (WTF::charactersToUInt): Deleted. 53 (WTF::charactersToInt64): Deleted. 54 (WTF::charactersToUInt64): Deleted. 55 (WTF::charactersToIntPtr): Deleted. 56 * wtf/text/WTFString.h: Deleted the above functions. 57 1 58 2021-05-11 Devin Rousso <drousso@apple.com> 2 59 -
trunk/Source/WTF/wtf/text/AtomString.h
r275457 r277355 138 138 WTF_EXPORT_PRIVATE AtomString convertToASCIIUppercase() const; 139 139 140 int toInt(bool* ok = nullptr) const { return m_string.toInt(ok); }141 140 double toDouble(bool* ok = nullptr) const { return m_string.toDouble(ok); } 142 141 float toFloat(bool* ok = nullptr) const { return m_string.toFloat(ok); } -
trunk/Source/WTF/wtf/text/StringImpl.cpp
r272084 r277355 810 810 return StringImpl::simplifyMatchedCharactersToSpace<LChar>(isWhiteSpace); 811 811 return StringImpl::simplifyMatchedCharactersToSpace<UChar>(isWhiteSpace); 812 }813 814 int StringImpl::toIntStrict(bool* ok, int base)815 {816 if (is8Bit())817 return charactersToIntStrict(characters8(), m_length, ok, base);818 return charactersToIntStrict(characters16(), m_length, ok, base);819 }820 821 unsigned StringImpl::toUIntStrict(bool* ok, int base)822 {823 if (is8Bit())824 return charactersToUIntStrict(characters8(), m_length, ok, base);825 return charactersToUIntStrict(characters16(), m_length, ok, base);826 }827 828 int64_t StringImpl::toInt64Strict(bool* ok, int base)829 {830 if (is8Bit())831 return charactersToInt64Strict(characters8(), m_length, ok, base);832 return charactersToInt64Strict(characters16(), m_length, ok, base);833 }834 835 uint64_t StringImpl::toUInt64Strict(bool* ok, int base)836 {837 if (is8Bit())838 return charactersToUInt64Strict(characters8(), m_length, ok, base);839 return charactersToUInt64Strict(characters16(), m_length, ok, base);840 }841 842 intptr_t StringImpl::toIntPtrStrict(bool* ok, int base)843 {844 if (is8Bit())845 return charactersToIntPtrStrict(characters8(), m_length, ok, base);846 return charactersToIntPtrStrict(characters16(), m_length, ok, base);847 }848 849 int StringImpl::toInt(bool* ok)850 {851 if (is8Bit())852 return charactersToInt(characters8(), m_length, ok);853 return charactersToInt(characters16(), m_length, ok);854 }855 856 unsigned StringImpl::toUInt(bool* ok)857 {858 if (is8Bit())859 return charactersToUInt(characters8(), m_length, ok);860 return charactersToUInt(characters16(), m_length, ok);861 }862 863 int64_t StringImpl::toInt64(bool* ok)864 {865 if (is8Bit())866 return charactersToInt64(characters8(), m_length, ok);867 return charactersToInt64(characters16(), m_length, ok);868 }869 870 uint64_t StringImpl::toUInt64(bool* ok)871 {872 if (is8Bit())873 return charactersToUInt64(characters8(), m_length, ok);874 return charactersToUInt64(characters16(), m_length, ok);875 }876 877 intptr_t StringImpl::toIntPtr(bool* ok)878 {879 if (is8Bit())880 return charactersToIntPtr(characters8(), m_length, ok);881 return charactersToIntPtr(characters16(), m_length, ok);882 812 } 883 813 -
trunk/Source/WTF/wtf/text/StringImpl.h
r274997 r277355 393 393 WTF_EXPORT_PRIVATE UChar32 characterStartingAt(unsigned); 394 394 395 int toIntStrict(bool* ok = nullptr, int base = 10);396 unsigned toUIntStrict(bool* ok = nullptr, int base = 10);397 int64_t toInt64Strict(bool* ok = nullptr, int base = 10);398 uint64_t toUInt64Strict(bool* ok = nullptr, int base = 10);399 intptr_t toIntPtrStrict(bool* ok = nullptr, int base = 10);400 401 WTF_EXPORT_PRIVATE int toInt(bool* ok = nullptr); // ignores trailing garbage402 unsigned toUInt(bool* ok = nullptr); // ignores trailing garbage403 int64_t toInt64(bool* ok = nullptr); // ignores trailing garbage404 uint64_t toUInt64(bool* ok = nullptr); // ignores trailing garbage405 intptr_t toIntPtr(bool* ok = nullptr); // ignores trailing garbage406 407 395 // FIXME: Like the strict functions above, these give false for "ok" when there is trailing garbage. 408 396 // Like the non-strict functions above, these return the value when there is trailing garbage. -
trunk/Source/WTF/wtf/text/StringToIntegerConversion.h
r277234 r277355 111 111 } 112 112 113 // FIXME: Deprecated. Remove toIntegralType entirely once we get move all callers to parseInteger.114 template<typename IntegralType, typename StringOrStringView> IntegralType toIntegralType(const StringOrStringView& stringView, bool* ok, int base = 10)115 {116 auto result = parseInteger<IntegralType>(stringView, base);117 if (ok)118 *ok = result.hasValue();119 return result.valueOr(0);120 }121 122 // FIXME: Deprecated. Remove toIntegralType entirely once we get move all callers to parseInteger.123 template<typename IntegralType, typename CharacterType> IntegralType toIntegralType(const CharacterType* data, unsigned length, bool* ok, int base = 10)124 {125 return toIntegralType<IntegralType>(StringView { data, length }, ok, base);126 }127 128 // FIXME: Deprecated. Remove toIntegralType entirely once we get move all callers to parseInteger.129 template<typename IntegralType, typename StringOrStringView> Optional<IntegralType> toIntegralType(const StringOrStringView& stringView, int base = 10)130 {131 return parseInteger<IntegralType>(stringView, base);132 }133 134 // FIXME: Deprecated. Remove toIntegralType entirely once we get move all callers to parseInteger.135 template<typename IntegralType, typename CharacterType> Optional<IntegralType> toIntegralType(const CharacterType* data, unsigned length, int base = 10)136 {137 return parseInteger<IntegralType>(StringView { data, length }, base);138 }139 140 113 } 141 114 142 115 using WTF::parseInteger; 143 116 using WTF::parseIntegerAllowingTrailingJunk; 144 using WTF::toIntegralType; -
trunk/Source/WTF/wtf/text/StringView.cpp
r265735 r277355 310 310 return string; 311 311 return result.underlyingString; 312 }313 314 // FIXME: Should this be named parseNumber<uint16_t> instead?315 // FIXME: Should we replace the toInt family of functions with this style?316 Optional<uint16_t> parseUInt16(StringView string)317 {318 bool ok = false;319 auto number = toIntegralType<uint16_t>(string, &ok);320 if (!ok)321 return WTF::nullopt;322 return number;323 312 } 324 313 -
trunk/Source/WTF/wtf/text/StringView.h
r274872 r277355 169 169 WTF_EXPORT_PRIVATE bool endsWithIgnoringASCIICase(const StringView&) const; 170 170 171 int toInt() const;172 int toInt(bool& isValid) const;173 int toIntStrict(bool& isValid) const;174 Optional<uint64_t> toUInt64Strict() const;175 Optional<int64_t> toInt64Strict() const;176 171 float toFloat(bool& isValid) const; 177 172 … … 247 242 WTF_EXPORT_PRIVATE String normalizedNFC(const String&); 248 243 249 WTF_EXPORT_PRIVATE Optional<uint16_t> parseUInt16(StringView);250 251 244 } 252 245 … … 353 346 inline StringView::StringView(const char* characters) 354 347 { 355 initialize(reinterpret_cast<const LChar*>(characters), strlen(characters));348 initialize(reinterpret_cast<const LChar*>(characters), characters ? strlen(characters) : 0); 356 349 } 357 350 … … 587 580 return charactersToFloat(characters8(), m_length, &isValid); 588 581 return charactersToFloat(characters16(), m_length, &isValid); 589 }590 591 inline int StringView::toInt() const592 {593 bool isValid;594 return toInt(isValid);595 }596 597 inline int StringView::toInt(bool& isValid) const598 {599 if (is8Bit())600 return charactersToInt(characters8(), m_length, &isValid);601 return charactersToInt(characters16(), m_length, &isValid);602 }603 604 inline int StringView::toIntStrict(bool& isValid) const605 {606 if (is8Bit())607 return charactersToIntStrict(characters8(), m_length, &isValid);608 return charactersToIntStrict(characters16(), m_length, &isValid);609 }610 611 inline Optional<uint64_t> StringView::toUInt64Strict() const612 {613 bool isValid;614 uint64_t result = is8Bit() ? charactersToUInt64Strict(characters8(), m_length, &isValid) : charactersToUInt64Strict(characters16(), m_length, &isValid);615 return isValid ? makeOptional(result) : WTF::nullopt;616 }617 618 inline Optional<int64_t> StringView::toInt64Strict() const619 {620 bool isValid;621 int64_t result = is8Bit() ? charactersToInt64Strict(characters8(), m_length, &isValid) : charactersToInt64Strict(characters16(), m_length, &isValid);622 return isValid ? makeOptional(result) : WTF::nullopt;623 582 } 624 583 -
trunk/Source/WTF/wtf/text/WTFString.cpp
r277234 r277355 493 493 } 494 494 495 int String::toIntStrict(bool* ok, int base) const496 {497 if (!m_impl) {498 if (ok)499 *ok = false;500 return 0;501 }502 return m_impl->toIntStrict(ok, base);503 }504 505 unsigned String::toUIntStrict(bool* ok, int base) const506 {507 if (!m_impl) {508 if (ok)509 *ok = false;510 return 0;511 }512 return m_impl->toUIntStrict(ok, base);513 }514 515 int64_t String::toInt64Strict(bool* ok, int base) const516 {517 if (!m_impl) {518 if (ok)519 *ok = false;520 return 0;521 }522 return m_impl->toInt64Strict(ok, base);523 }524 525 uint64_t String::toUInt64Strict(bool* ok, int base) const526 {527 if (!m_impl) {528 if (ok)529 *ok = false;530 return 0;531 }532 return m_impl->toUInt64Strict(ok, base);533 }534 535 intptr_t String::toIntPtrStrict(bool* ok, int base) const536 {537 if (!m_impl) {538 if (ok)539 *ok = false;540 return 0;541 }542 return m_impl->toIntPtrStrict(ok, base);543 }544 545 int String::toInt(bool* ok) const546 {547 if (!m_impl) {548 if (ok)549 *ok = false;550 return 0;551 }552 return m_impl->toInt(ok);553 }554 555 unsigned String::toUInt(bool* ok) const556 {557 if (!m_impl) {558 if (ok)559 *ok = false;560 return 0;561 }562 return m_impl->toUInt(ok);563 }564 565 int64_t String::toInt64(bool* ok) const566 {567 if (!m_impl) {568 if (ok)569 *ok = false;570 return 0;571 }572 return m_impl->toInt64(ok);573 }574 575 uint64_t String::toUInt64(bool* ok) const576 {577 if (!m_impl) {578 if (ok)579 *ok = false;580 return 0;581 }582 return m_impl->toUInt64(ok);583 }584 585 intptr_t String::toIntPtr(bool* ok) const586 {587 if (!m_impl) {588 if (ok)589 *ok = false;590 return 0;591 }592 return m_impl->toIntPtr(ok);593 }594 595 495 double String::toDouble(bool* ok) const 596 496 { … … 893 793 894 794 // String Operations 895 template<typename CharacterType>896 static unsigned lengthOfCharactersAsInteger(const CharacterType* data, size_t length)897 {898 size_t i = 0;899 900 // Allow leading spaces.901 for (; i != length; ++i) {902 if (!isSpaceOrNewline(data[i]))903 break;904 }905 906 // Allow sign.907 if (i != length && (data[i] == '+' || data[i] == '-'))908 ++i;909 910 // Allow digits.911 for (; i != length; ++i) {912 if (!isASCIIDigit(data[i]))913 break;914 }915 916 return i;917 }918 919 int charactersToIntStrict(const LChar* data, size_t length, bool* ok, int base)920 {921 return toIntegralType<int>(data, length, ok, base);922 }923 924 int charactersToIntStrict(const UChar* data, size_t length, bool* ok, int base)925 {926 return toIntegralType<int>(data, length, ok, base);927 }928 929 unsigned charactersToUIntStrict(const LChar* data, size_t length, bool* ok, int base)930 {931 return toIntegralType<unsigned>(data, length, ok, base);932 }933 934 unsigned charactersToUIntStrict(const UChar* data, size_t length, bool* ok, int base)935 {936 return toIntegralType<unsigned>(data, length, ok, base);937 }938 939 int64_t charactersToInt64Strict(const LChar* data, size_t length, bool* ok, int base)940 {941 return toIntegralType<int64_t>(data, length, ok, base);942 }943 944 int64_t charactersToInt64Strict(const UChar* data, size_t length, bool* ok, int base)945 {946 return toIntegralType<int64_t>(data, length, ok, base);947 }948 949 uint64_t charactersToUInt64Strict(const LChar* data, size_t length, bool* ok, int base)950 {951 return toIntegralType<uint64_t>(data, length, ok, base);952 }953 954 uint64_t charactersToUInt64Strict(const UChar* data, size_t length, bool* ok, int base)955 {956 return toIntegralType<uint64_t>(data, length, ok, base);957 }958 959 intptr_t charactersToIntPtrStrict(const LChar* data, size_t length, bool* ok, int base)960 {961 return toIntegralType<intptr_t>(data, length, ok, base);962 }963 964 intptr_t charactersToIntPtrStrict(const UChar* data, size_t length, bool* ok, int base)965 {966 return toIntegralType<intptr_t>(data, length, ok, base);967 }968 969 int charactersToInt(const LChar* data, size_t length, bool* ok)970 {971 return toIntegralType<int>(data, lengthOfCharactersAsInteger<LChar>(data, length), ok, 10);972 }973 974 int charactersToInt(const UChar* data, size_t length, bool* ok)975 {976 return toIntegralType<int>(data, lengthOfCharactersAsInteger(data, length), ok, 10);977 }978 979 unsigned charactersToUInt(const LChar* data, size_t length, bool* ok)980 {981 return toIntegralType<unsigned>(data, lengthOfCharactersAsInteger<LChar>(data, length), ok, 10);982 }983 984 unsigned charactersToUInt(const UChar* data, size_t length, bool* ok)985 {986 return toIntegralType<unsigned>(data, lengthOfCharactersAsInteger<UChar>(data, length), ok, 10);987 }988 989 int64_t charactersToInt64(const LChar* data, size_t length, bool* ok)990 {991 return toIntegralType<int64_t>(data, lengthOfCharactersAsInteger<LChar>(data, length), ok, 10);992 }993 994 int64_t charactersToInt64(const UChar* data, size_t length, bool* ok)995 {996 return toIntegralType<int64_t>(data, lengthOfCharactersAsInteger<UChar>(data, length), ok, 10);997 }998 999 uint64_t charactersToUInt64(const LChar* data, size_t length, bool* ok)1000 {1001 return toIntegralType<uint64_t>(data, lengthOfCharactersAsInteger<LChar>(data, length), ok, 10);1002 }1003 1004 uint64_t charactersToUInt64(const UChar* data, size_t length, bool* ok)1005 {1006 return toIntegralType<uint64_t>(data, lengthOfCharactersAsInteger<UChar>(data, length), ok, 10);1007 }1008 1009 intptr_t charactersToIntPtr(const LChar* data, size_t length, bool* ok)1010 {1011 return toIntegralType<intptr_t>(data, lengthOfCharactersAsInteger<LChar>(data, length), ok, 10);1012 }1013 1014 intptr_t charactersToIntPtr(const UChar* data, size_t length, bool* ok)1015 {1016 return toIntegralType<intptr_t>(data, lengthOfCharactersAsInteger<UChar>(data, length), ok, 10);1017 }1018 795 1019 796 template<typename CharacterType, TrailingJunkPolicy policy> -
trunk/Source/WTF/wtf/text/WTFString.h
r274896 r277355 43 43 // Declarations of string operations 44 44 45 WTF_EXPORT_PRIVATE int charactersToIntStrict(const LChar*, size_t, bool* ok = nullptr, int base = 10);46 WTF_EXPORT_PRIVATE int charactersToIntStrict(const UChar*, size_t, bool* ok = nullptr, int base = 10);47 WTF_EXPORT_PRIVATE unsigned charactersToUIntStrict(const LChar*, size_t, bool* ok = nullptr, int base = 10);48 WTF_EXPORT_PRIVATE unsigned charactersToUIntStrict(const UChar*, size_t, bool* ok = nullptr, int base = 10);49 WTF_EXPORT_PRIVATE int64_t charactersToInt64Strict(const LChar*, size_t, bool* ok = nullptr, int base = 10);50 WTF_EXPORT_PRIVATE int64_t charactersToInt64Strict(const UChar*, size_t, bool* ok = nullptr, int base = 10);51 WTF_EXPORT_PRIVATE uint64_t charactersToUInt64Strict(const LChar*, size_t, bool* ok = nullptr, int base = 10);52 WTF_EXPORT_PRIVATE uint64_t charactersToUInt64Strict(const UChar*, size_t, bool* ok = nullptr, int base = 10);53 intptr_t charactersToIntPtrStrict(const LChar*, size_t, bool* ok = nullptr, int base = 10);54 intptr_t charactersToIntPtrStrict(const UChar*, size_t, bool* ok = nullptr, int base = 10);55 56 WTF_EXPORT_PRIVATE int charactersToInt(const LChar*, size_t, bool* ok = nullptr); // ignores trailing garbage57 WTF_EXPORT_PRIVATE int charactersToInt(const UChar*, size_t, bool* ok = nullptr); // ignores trailing garbage58 unsigned charactersToUInt(const LChar*, size_t, bool* ok = nullptr); // ignores trailing garbage59 unsigned charactersToUInt(const UChar*, size_t, bool* ok = nullptr); // ignores trailing garbage60 int64_t charactersToInt64(const LChar*, size_t, bool* ok = nullptr); // ignores trailing garbage61 int64_t charactersToInt64(const UChar*, size_t, bool* ok = nullptr); // ignores trailing garbage62 uint64_t charactersToUInt64(const LChar*, size_t, bool* ok = nullptr); // ignores trailing garbage63 WTF_EXPORT_PRIVATE uint64_t charactersToUInt64(const UChar*, size_t, bool* ok = nullptr); // ignores trailing garbage64 intptr_t charactersToIntPtr(const LChar*, size_t, bool* ok = nullptr); // ignores trailing garbage65 intptr_t charactersToIntPtr(const UChar*, size_t, bool* ok = nullptr); // ignores trailing garbage66 67 // FIXME: Like the strict functions above, these give false for "ok" when there is trailing garbage.68 // Like the non-strict functions above, these return the value when there is trailing garbage.69 // It would be better if these were more consistent with the above functions instead.70 45 WTF_EXPORT_PRIVATE double charactersToDouble(const LChar*, size_t, bool* ok = nullptr); 71 46 WTF_EXPORT_PRIVATE double charactersToDouble(const UChar*, size_t, bool* ok = nullptr); … … 282 257 WTF_EXPORT_PRIVATE Vector<String> splitAllowingEmptyEntries(const String& separator) const; 283 258 284 WTF_EXPORT_PRIVATE int toIntStrict(bool* ok = nullptr, int base = 10) const;285 WTF_EXPORT_PRIVATE unsigned toUIntStrict(bool* ok = nullptr, int base = 10) const;286 WTF_EXPORT_PRIVATE int64_t toInt64Strict(bool* ok = nullptr, int base = 10) const;287 WTF_EXPORT_PRIVATE uint64_t toUInt64Strict(bool* ok = nullptr, int base = 10) const;288 WTF_EXPORT_PRIVATE intptr_t toIntPtrStrict(bool* ok = nullptr, int base = 10) const;289 290 WTF_EXPORT_PRIVATE int toInt(bool* ok = nullptr) const;291 WTF_EXPORT_PRIVATE unsigned toUInt(bool* ok = nullptr) const;292 WTF_EXPORT_PRIVATE int64_t toInt64(bool* ok = nullptr) const;293 WTF_EXPORT_PRIVATE uint64_t toUInt64(bool* ok = nullptr) const;294 WTF_EXPORT_PRIVATE intptr_t toIntPtr(bool* ok = nullptr) const;295 296 // FIXME: Like the strict functions above, these give false for "ok" when there is trailing garbage.297 // Like the non-strict functions above, these return the value when there is trailing garbage.298 // It would be better if these were more consistent with the above functions instead.299 259 WTF_EXPORT_PRIVATE double toDouble(bool* ok = nullptr) const; 300 260 WTF_EXPORT_PRIVATE float toFloat(bool* ok = nullptr) const; … … 681 641 using WTF::charactersToDouble; 682 642 using WTF::charactersToFloat; 683 using WTF::charactersToInt64;684 using WTF::charactersToInt64Strict;685 using WTF::charactersToInt;686 using WTF::charactersToIntPtr;687 using WTF::charactersToIntPtrStrict;688 using WTF::charactersToIntStrict;689 using WTF::charactersToUInt64;690 using WTF::charactersToUInt64Strict;691 using WTF::charactersToUInt;692 using WTF::charactersToUIntStrict;693 643 using WTF::emptyString; 694 644 using WTF::nullString; -
trunk/Source/WebCore/ChangeLog
r277353 r277355 1 2021-05-11 Darin Adler <darin@apple.com> 2 3 Remove the String::toInt family of functions 4 https://bugs.webkit.org/show_bug.cgi?id=225599 5 6 Reviewed by Anders Carlsson. 7 8 * platform/graphics/GLContext.cpp: 9 (WebCore::GLContext::version): Use 10 parseIntegerAllowingTrailingJunk<unsigned> instead of String::toUInt. 11 12 * platform/graphics/GlyphBuffer.h: 13 (WebCore::GlyphBuffer::checkedStringOffsetAt const): Fix code that was 14 assuming GlyphBufferStringOffset was signed to compile without a warning 15 regardless of whether it's signed or unsigned. This was making GTK 16 builds have tons and tons of warnings, which was distracting while 17 working on the other fixes here. 18 19 * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp: 20 (CachedResourceStreamingClient::responseReceived): Use 21 parseIntegerAllowingTrailingJunk<uint64_t> instead of String::toUInt64. 22 1 23 2021-05-11 Commit Queue <commit-queue@webkit.org> 2 24 -
trunk/Source/WebCore/platform/graphics/GLContext.cpp
r276528 r277355 20 20 21 21 #if USE(OPENGL) || USE(OPENGL_ES) 22 22 23 #include "GLContext.h" 24 23 25 #include <wtf/ThreadSpecific.h> 26 #include <wtf/text/StringToIntegerConversion.h> 24 27 25 28 #if USE(EGL) … … 184 187 } 185 188 186 m_version = versionDigits[0].toUInt() * 100 + versionDigits[1].toUInt() * 10; 189 m_version = parseIntegerAllowingTrailingJunk<unsigned>(versionDigits[0]).valueOr(0) * 100 190 + parseIntegerAllowingTrailingJunk<unsigned>(versionDigits[1]).valueOr(0) * 10; 187 191 } 188 192 return m_version; -
trunk/Source/WebCore/platform/graphics/GlyphBuffer.h
r277232 r277355 79 79 { 80 80 auto result = uncheckedStringOffsetAt(index); 81 if ( result < 0 || static_cast<unsigned>(result) >= stringLength)81 if (static_cast<std::make_unsigned_t<GlyphBufferStringOffset>>(result) >= stringLength) 82 82 return WTF::nullopt; 83 83 return result; -
trunk/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp
r277269 r277355 1026 1026 headers.reset(gst_structure_new_empty("response-headers")); 1027 1027 for (const auto& header : response.httpHeaderFields()) { 1028 bool ok = false; 1029 uint64_t convertedValue = header.value.toUInt64(&ok); 1030 if (ok) 1031 gst_structure_set(headers.get(), header.key.utf8().data(), G_TYPE_UINT64, convertedValue, nullptr); 1028 if (auto convertedValue = parseIntegerAllowingTrailingJunk<uint64_t>(header.value)) 1029 gst_structure_set(headers.get(), header.key.utf8().data(), G_TYPE_UINT64, *convertedValue, nullptr); 1032 1030 else 1033 1031 gst_structure_set(headers.get(), header.key.utf8().data(), G_TYPE_STRING, header.value.utf8().data(), nullptr); -
trunk/Source/WebKit/ChangeLog
r277354 r277355 1 2021-05-11 Darin Adler <darin@apple.com> 2 3 Remove the String::toInt family of functions 4 https://bugs.webkit.org/show_bug.cgi?id=225599 5 6 Reviewed by Anders Carlsson. 7 8 * Shared/win/AuxiliaryProcessMainWin.cpp: 9 (WebKit::AuxiliaryProcessMainCommon::parseCommandLine): Use 10 parseIntegerAllowingTrailingJunk<uint64_t> instead of String::toUInt64. 11 * UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp: 12 (WebKit::ScriptMessageClient::didPostMessage): Ditto. 13 * UIProcess/win/WebProcessPoolWin.cpp: 14 (WebKit::initializeRemoteInspectorServer): Use 15 parseIntegerAllowingTrailingJunk<uint16_t> instead of StringView::toUInt64. 16 This is a 16-bit port number, so not valuable to parse larger integers. 17 1 18 2021-05-11 Devin Rousso <drousso@apple.com> 2 19 -
trunk/Source/WebKit/Shared/win/AuxiliaryProcessMainWin.cpp
r271563 r277355 29 29 #include <JavaScriptCore/ExecutableAllocator.h> 30 30 #include <cstring> 31 #include <wtf/text/ WTFString.h>31 #include <wtf/text/StringToIntegerConversion.h> 32 32 33 33 namespace WebKit { … … 36 36 { 37 37 for (int i = 0; i < argc; i++) { 38 if (!strcmp(argv[i], "-clientIdentifier") && i + 1 < argc) { 39 String str(argv[++i]); 40 m_parameters.connectionIdentifier = reinterpret_cast<HANDLE>(str.toUInt64()); 41 } else if (!strcmp(argv[i], "-processIdentifier") && i + 1 < argc) { 42 String str(argv[++i]); 43 m_parameters.processIdentifier = makeObjectIdentifier<WebCore::ProcessIdentifierType>(str.toUInt64()); 44 } else if (!strcmp(argv[i], "-configure-jsc-for-testing")) 38 if (!strcmp(argv[i], "-clientIdentifier") && i + 1 < argc) 39 m_parameters.connectionIdentifier = reinterpret_cast<HANDLE>(parseIntegerAllowingTrailingJunk<uint64_t>(argv[++i]).valueOr(0)); 40 else if (!strcmp(argv[i], "-processIdentifier") && i + 1 < argc) 41 m_parameters.processIdentifier = makeObjectIdentifier<WebCore::ProcessIdentifierType>(parseIntegerAllowingTrailingJunk<uint64_t>(argv[++i]).valueOr(0)); 42 else if (!strcmp(argv[i], "-configure-jsc-for-testing")) 45 43 JSC::Config::configureForTesting(); 46 44 else if (!strcmp(argv[i], "-disable-jit")) -
trunk/Source/WebKit/UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp
r260350 r277355 31 31 #include "WebScriptMessageHandler.h" 32 32 #include <wtf/URL.h> 33 #include <wtf/text/StringToIntegerConversion.h> 33 34 34 35 namespace WebKit { … … 51 52 52 53 URL requestURL = URL({ }, page.pageLoadState().url()); 53 m_inspectorProtocolHandler.inspect(requestURL.hostAndPort(), tokens[0].toUInt64(), tokens[1].toUInt64(), tokens[2]);54 m_inspectorProtocolHandler.inspect(requestURL.hostAndPort(), parseIntegerAllowingTrailingJunk<uint64_t>(tokens[0]).valueOr(0), parseIntegerAllowingTrailingJunk<uint64_t>(tokens[1]).valueOr(0), tokens[2]); 54 55 } 55 56 -
trunk/Source/WebKit/UIProcess/Inspector/socket/RemoteInspectorProtocolHandler.cpp
r268074 r277355 40 40 #include <wtf/URL.h> 41 41 #include <wtf/text/StringBuilder.h> 42 #include <wtf/text/StringToIntegerConversion.h> 42 43 43 44 namespace WebKit { … … 60 61 61 62 URL requestURL { { }, page.pageLoadState().url() }; 62 m_inspectorProtocolHandler.inspect(requestURL.hostAndPort(), tokens[0].toUIntStrict(), tokens[1].toUIntStrict(), tokens[2]);63 m_inspectorProtocolHandler.inspect(requestURL.hostAndPort(), parseInteger<int>(tokens[0]).valueOr(0), parseInteger<int>(tokens[1]).valueOr(0), tokens[2]); 63 64 } 64 65 -
trunk/Source/WebKit/UIProcess/win/WebProcessPoolWin.cpp
r250988 r277355 34 34 #include <JavaScriptCore/RemoteInspectorServer.h> 35 35 #include <WebCore/WebCoreBundleWin.h> 36 #include <wtf/text/StringToIntegerConversion.h> 36 37 #endif 37 38 … … 62 63 63 64 auto host = address.substring(0, pos); 64 auto port = address.substring(pos + 1).toUInt64Strict();65 auto port = parseInteger<uint16_t>(address.substring(pos + 1)); 65 66 if (!port) 66 67 return; -
trunk/Tools/ChangeLog
r277354 r277355 1 2021-05-11 Darin Adler <darin@apple.com> 2 3 Remove the String::toInt family of functions 4 https://bugs.webkit.org/show_bug.cgi?id=225599 5 6 Reviewed by Anders Carlsson. 7 8 * TestWebKitAPI/CMakeLists.txt: Added StringToIntegerConversion.cpp. 9 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Ditto. 10 11 * TestWebKitAPI/Tests/WTF/StringToIntegerConversion.cpp: Added. 12 Contains tests moved and adapted from the files below so we don't 13 lose test coverage. We and and should add many more tests. 14 15 * TestWebKitAPI/Tests/WTF/StringView.cpp: Removed tests for parseUInt16 16 and StringView::toIntStrict. 17 18 * TestWebKitAPI/Tests/WTF/WTFString.cpp: Removed tests for String::toInt. 19 20 * TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm: Use 21 parseInteger<uint64_t> instead of StringView::toUInt64Strict. 22 * TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm: Ditto. 23 1 24 2021-05-11 Devin Rousso <drousso@apple.com> 2 25 -
trunk/Tools/TestWebKitAPI/CMakeLists.txt
r276247 r277355 94 94 Tests/WTF/StringOperators.cpp 95 95 Tests/WTF/StringParsingBuffer.cpp 96 Tests/WTF/StringToIntegerConversion.cpp 96 97 Tests/WTF/StringView.cpp 97 98 Tests/WTF/SynchronizedFixedQueue.cpp -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r277353 r277355 832 832 9329AA291DE3F81E003ABD07 /* TextBreakIterator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9329AA281DE3F81E003ABD07 /* TextBreakIterator.cpp */; }; 833 833 932AE53D1D371047005DFFAF /* focus-inputs.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 93575C551D30366E000D604D /* focus-inputs.html */; }; 834 9332EF942649BB68009F5D6D /* StringToIntegerConversion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9332EF932649BB68009F5D6D /* StringToIntegerConversion.cpp */; }; 834 835 933D631D1FCB76200032ECD6 /* Hasher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 933D631B1FCB76180032ECD6 /* Hasher.cpp */; }; 835 836 9342589C255B609B0059EEDD /* SpeechRecognition.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9342589B255B609A0059EEDD /* SpeechRecognition.mm */; }; … … 2513 2514 9329AA281DE3F81E003ABD07 /* TextBreakIterator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextBreakIterator.cpp; sourceTree = "<group>"; }; 2514 2515 9331407B17B4419000F083B1 /* DidNotHandleKeyDown.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DidNotHandleKeyDown.cpp; sourceTree = "<group>"; }; 2516 9332EF932649BB68009F5D6D /* StringToIntegerConversion.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringToIntegerConversion.cpp; sourceTree = "<group>"; }; 2515 2517 933D631B1FCB76180032ECD6 /* Hasher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Hasher.cpp; sourceTree = "<group>"; }; 2516 2518 9342589B255B609A0059EEDD /* SpeechRecognition.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SpeechRecognition.mm; sourceTree = "<group>"; }; … … 4465 4467 C01363C713C3997300EF3964 /* StringOperators.cpp */, 4466 4468 7CD70C4E24A436EE00E61040 /* StringParsingBuffer.cpp */, 4469 9332EF932649BB68009F5D6D /* StringToIntegerConversion.cpp */, 4467 4470 7C74D42D188228F300E5ED57 /* StringView.cpp */, 4468 4471 5597F8341D9596C80066BC21 /* SynchronizedFixedQueue.cpp */, … … 5221 5224 7C83DF381D0A590C00FEBCF3 /* StringOperators.cpp in Sources */, 5222 5225 7CD70C4F24A436EE00E61040 /* StringParsingBuffer.cpp in Sources */, 5226 9332EF942649BB68009F5D6D /* StringToIntegerConversion.cpp in Sources */, 5223 5227 7C83DF3A1D0A590C00FEBCF3 /* StringView.cpp in Sources */, 5224 5228 5597F8361D9596C80066BC21 /* SynchronizedFixedQueue.cpp in Sources */, -
trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp
r274959 r277355 991 991 } 992 992 993 TEST(WTF, StringViewParseUInt16)994 {995 EXPECT_EQ(0U, *WTF::parseUInt16("0"));996 EXPECT_EQ(3U, *WTF::parseUInt16("3"));997 EXPECT_EQ(12345U, *WTF::parseUInt16("12345"));998 EXPECT_EQ(65535U, *WTF::parseUInt16("65535"));999 EXPECT_TRUE(!WTF::parseUInt16("-1"));1000 EXPECT_TRUE(!WTF::parseUInt16("-3"));1001 EXPECT_TRUE(!WTF::parseUInt16("65536"));1002 }1003 1004 TEST(WTF, StringViewToIntStrict)1005 {1006 auto test = [](ASCIILiteral string) {1007 bool isValid = false;1008 int result = StringView(string).toIntStrict(isValid);1009 return isValid ? makeOptional(result) : WTF::nullopt;1010 };1011 EXPECT_EQ(0, *test("0"_s));1012 EXPECT_EQ(3, *test("3"_s));1013 EXPECT_EQ(-3, *test("-3"_s));1014 EXPECT_EQ(12345, *test("12345"_s));1015 EXPECT_EQ(-12345, *test("-12345"_s));1016 if (std::numeric_limits<int>::max() == 2147483647) {1017 EXPECT_EQ(2147483647, *test("2147483647"_s));1018 EXPECT_TRUE(!test("2147483648"_s));1019 }1020 if (std::numeric_limits<int>::min() == -2147483648) {1021 EXPECT_EQ(-2147483648, *test("-2147483648"_s));1022 EXPECT_TRUE(!test("-2147483649"_s));1023 }1024 }1025 1026 993 } // namespace TestWebKitAPI -
trunk/Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp
r274878 r277355 288 288 } 289 289 290 TEST(WTF, StringToInt)291 {292 bool ok = false;293 294 EXPECT_EQ(0, String().toInt());295 EXPECT_EQ(0, String().toInt(&ok));296 EXPECT_FALSE(ok);297 298 EXPECT_EQ(0, emptyString().toInt());299 EXPECT_EQ(0, emptyString().toInt(&ok));300 EXPECT_FALSE(ok);301 302 EXPECT_EQ(0, String("0").toInt());303 EXPECT_EQ(0, String("0").toInt(&ok));304 EXPECT_TRUE(ok);305 306 EXPECT_EQ(1, String("1").toInt());307 EXPECT_EQ(1, String("1").toInt(&ok));308 EXPECT_TRUE(ok);309 310 EXPECT_EQ(2147483647, String("2147483647").toInt());311 EXPECT_EQ(2147483647, String("2147483647").toInt(&ok));312 EXPECT_TRUE(ok);313 314 EXPECT_EQ(0, String("2147483648").toInt());315 EXPECT_EQ(0, String("2147483648").toInt(&ok));316 EXPECT_FALSE(ok);317 318 EXPECT_EQ(-2147483648, String("-2147483648").toInt());319 EXPECT_EQ(-2147483648, String("-2147483648").toInt(&ok));320 EXPECT_TRUE(ok);321 322 EXPECT_EQ(0, String("-2147483649").toInt());323 EXPECT_EQ(0, String("-2147483649").toInt(&ok));324 EXPECT_FALSE(ok);325 326 // fail if we see leading junk327 EXPECT_EQ(0, String("x1").toInt());328 EXPECT_EQ(0, String("x1").toInt(&ok));329 EXPECT_FALSE(ok);330 331 // succeed if we see leading spaces332 EXPECT_EQ(1, String(" 1").toInt());333 EXPECT_EQ(1, String(" 1").toInt(&ok));334 EXPECT_TRUE(ok);335 336 // silently ignore trailing junk337 EXPECT_EQ(1, String("1x").toInt());338 EXPECT_EQ(1, String("1x").toInt(&ok));339 EXPECT_TRUE(ok);340 }341 342 290 TEST(WTF, StringToDouble) 343 291 { -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm
r277336 r277355 51 51 #import <wtf/text/StringConcatenateNumbers.h> 52 52 #import <wtf/text/StringHash.h> 53 #import <wtf/text/StringToIntegerConversion.h> 53 54 #import <wtf/text/WTFString.h> 54 55 … … 1602 1603 auto rangeBeginString = requestRangeString.substring(begin + rangeBytes.length(), dash - begin - rangeBytes.length()); 1603 1604 auto rangeEndString = requestRangeString.substring(dash + 1, end - dash - 1); 1604 auto rangeBegin = rangeBeginString.toUInt64Strict();1605 auto rangeEnd = rangeEndString == "*" ? [videoData length] : rangeEndString.toUInt64Strict();1605 auto rangeBegin = parseInteger<uint64_t>(rangeBeginString).valueOr(0); 1606 auto rangeEnd = rangeEndString == "*" ? [videoData length] : parseInteger<uint64_t>(rangeEndString).valueOr(0); 1606 1607 1607 1608 auto response = adoptNS([[NSHTTPURLResponse alloc] initWithURL:[NSURL URLWithString:@"https://webkit.org/"] statusCode:206 HTTPVersion:@"HTTP/1.1" headerFields:@{ -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm
r276862 r277355 48 48 #import <wtf/Deque.h> 49 49 #import <wtf/RetainPtr.h> 50 #import <wtf/text/StringToIntegerConversion.h> 50 51 #import <wtf/text/WTFString.h> 51 52 … … 771 772 ASSERT(end != notFound); 772 773 773 auto rangeBegin = *request.substring(begin + rangeBytes.length(), dash - begin - rangeBytes.length()).toUInt64Strict();774 auto rangeEnd = *request.substring(dash + 1, end - dash - 1).toUInt64Strict();774 auto rangeBegin = parseInteger<uint64_t>(request.substring(begin + rangeBytes.length(), dash - begin - rangeBytes.length())).value(); 775 auto rangeEnd = parseInteger<uint64_t>(request.substring(dash + 1, end - dash - 1)).value(); 775 776 776 777 NSString *responseHeaderString = [NSString stringWithFormat:
Note:
See TracChangeset
for help on using the changeset viewer.