Diff
Modified: trunk/Source/WTF/ChangeLog (277354 => 277355)
--- trunk/Source/WTF/ChangeLog 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Source/WTF/ChangeLog 2021-05-12 04:23:30 UTC (rev 277355)
@@ -1,3 +1,60 @@
+2021-05-11 Darin Adler <da...@apple.com>
+
+ Remove the String::toInt family of functions
+ https://bugs.webkit.org/show_bug.cgi?id=225599
+
+ Reviewed by Anders Carlsson.
+
+ * wtf/text/AtomString.h: Deleted AtomString::toInt.
+
+ * wtf/text/StringImpl.cpp:
+ (WTF::StringImpl::toIntStrict): Deleted.
+ (WTF::StringImpl::toUIntStrict): Deleted.
+ (WTF::StringImpl::toInt64Strict): Deleted.
+ (WTF::StringImpl::toUInt64Strict): Deleted.
+ (WTF::StringImpl::toIntPtrStrict): Deleted.
+ (WTF::StringImpl::toInt): Deleted.
+ (WTF::StringImpl::toUInt): Deleted.
+ (WTF::StringImpl::toInt64): Deleted.
+ (WTF::StringImpl::toUInt64): Deleted.
+ (WTF::StringImpl::toIntPtr): Deleted.
+ * wtf/text/StringImpl.h: Deleted the above functions.
+
+ * wtf/text/StringToIntegerConversion.h: Removed toIntegralType.
+
+ * wtf/text/StringView.cpp:
+ (WTF::parseUInt16): Deleted.
+
+ * wtf/text/StringView.h: Deleted StringView::toInt,
+ StringView::toIntStrict, StringView::toUInt64Strict,
+ StringView::toInt64Strict, and parseUInt16. Changed the constructor
+ that takes a const char* to work when passed nullptr. StringView has
+ a null value, and converting a null const char* should produce that.
+
+ * wtf/text/WTFString.cpp:
+ (WTF::String::toIntStrict const): Deleted.
+ (WTF::String::toUIntStrict const): Deleted.
+ (WTF::String::toInt64Strict const): Deleted.
+ (WTF::String::toUInt64Strict const): Deleted.
+ (WTF::String::toIntPtrStrict const): Deleted.
+ (WTF::String::toInt const): Deleted.
+ (WTF::String::toUInt const): Deleted.
+ (WTF::String::toInt64 const): Deleted.
+ (WTF::String::toUInt64 const): Deleted.
+ (WTF::String::toIntPtr const): Deleted.
+ (WTF::lengthOfCharactersAsInteger): Deleted.
+ (WTF::charactersToIntStrict): Deleted.
+ (WTF::charactersToUIntStrict): Deleted.
+ (WTF::charactersToInt64Strict): Deleted.
+ (WTF::charactersToUInt64Strict): Deleted.
+ (WTF::charactersToIntPtrStrict): Deleted.
+ (WTF::charactersToInt): Deleted.
+ (WTF::charactersToUInt): Deleted.
+ (WTF::charactersToInt64): Deleted.
+ (WTF::charactersToUInt64): Deleted.
+ (WTF::charactersToIntPtr): Deleted.
+ * wtf/text/WTFString.h: Deleted the above functions.
+
2021-05-11 Devin Rousso <drou...@apple.com>
[macCatalyst] should have CSS `hover: hover` and `pointer: fine`
Modified: trunk/Source/WTF/wtf/text/AtomString.h (277354 => 277355)
--- trunk/Source/WTF/wtf/text/AtomString.h 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Source/WTF/wtf/text/AtomString.h 2021-05-12 04:23:30 UTC (rev 277355)
@@ -137,7 +137,6 @@
WTF_EXPORT_PRIVATE AtomString convertToASCIILowercase() const;
WTF_EXPORT_PRIVATE AtomString convertToASCIIUppercase() const;
- int toInt(bool* ok = nullptr) const { return m_string.toInt(ok); }
double toDouble(bool* ok = nullptr) const { return m_string.toDouble(ok); }
float toFloat(bool* ok = nullptr) const { return m_string.toFloat(ok); }
Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (277354 => 277355)
--- trunk/Source/WTF/wtf/text/StringImpl.cpp 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Source/WTF/wtf/text/StringImpl.cpp 2021-05-12 04:23:30 UTC (rev 277355)
@@ -811,76 +811,6 @@
return StringImpl::simplifyMatchedCharactersToSpace<UChar>(isWhiteSpace);
}
-int StringImpl::toIntStrict(bool* ok, int base)
-{
- if (is8Bit())
- return charactersToIntStrict(characters8(), m_length, ok, base);
- return charactersToIntStrict(characters16(), m_length, ok, base);
-}
-
-unsigned StringImpl::toUIntStrict(bool* ok, int base)
-{
- if (is8Bit())
- return charactersToUIntStrict(characters8(), m_length, ok, base);
- return charactersToUIntStrict(characters16(), m_length, ok, base);
-}
-
-int64_t StringImpl::toInt64Strict(bool* ok, int base)
-{
- if (is8Bit())
- return charactersToInt64Strict(characters8(), m_length, ok, base);
- return charactersToInt64Strict(characters16(), m_length, ok, base);
-}
-
-uint64_t StringImpl::toUInt64Strict(bool* ok, int base)
-{
- if (is8Bit())
- return charactersToUInt64Strict(characters8(), m_length, ok, base);
- return charactersToUInt64Strict(characters16(), m_length, ok, base);
-}
-
-intptr_t StringImpl::toIntPtrStrict(bool* ok, int base)
-{
- if (is8Bit())
- return charactersToIntPtrStrict(characters8(), m_length, ok, base);
- return charactersToIntPtrStrict(characters16(), m_length, ok, base);
-}
-
-int StringImpl::toInt(bool* ok)
-{
- if (is8Bit())
- return charactersToInt(characters8(), m_length, ok);
- return charactersToInt(characters16(), m_length, ok);
-}
-
-unsigned StringImpl::toUInt(bool* ok)
-{
- if (is8Bit())
- return charactersToUInt(characters8(), m_length, ok);
- return charactersToUInt(characters16(), m_length, ok);
-}
-
-int64_t StringImpl::toInt64(bool* ok)
-{
- if (is8Bit())
- return charactersToInt64(characters8(), m_length, ok);
- return charactersToInt64(characters16(), m_length, ok);
-}
-
-uint64_t StringImpl::toUInt64(bool* ok)
-{
- if (is8Bit())
- return charactersToUInt64(characters8(), m_length, ok);
- return charactersToUInt64(characters16(), m_length, ok);
-}
-
-intptr_t StringImpl::toIntPtr(bool* ok)
-{
- if (is8Bit())
- return charactersToIntPtr(characters8(), m_length, ok);
- return charactersToIntPtr(characters16(), m_length, ok);
-}
-
double StringImpl::toDouble(bool* ok)
{
if (is8Bit())
Modified: trunk/Source/WTF/wtf/text/StringImpl.h (277354 => 277355)
--- trunk/Source/WTF/wtf/text/StringImpl.h 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Source/WTF/wtf/text/StringImpl.h 2021-05-12 04:23:30 UTC (rev 277355)
@@ -392,18 +392,6 @@
UChar operator[](unsigned i) const { return at(i); }
WTF_EXPORT_PRIVATE UChar32 characterStartingAt(unsigned);
- int toIntStrict(bool* ok = nullptr, int base = 10);
- unsigned toUIntStrict(bool* ok = nullptr, int base = 10);
- int64_t toInt64Strict(bool* ok = nullptr, int base = 10);
- uint64_t toUInt64Strict(bool* ok = nullptr, int base = 10);
- intptr_t toIntPtrStrict(bool* ok = nullptr, int base = 10);
-
- WTF_EXPORT_PRIVATE int toInt(bool* ok = nullptr); // ignores trailing garbage
- unsigned toUInt(bool* ok = nullptr); // ignores trailing garbage
- int64_t toInt64(bool* ok = nullptr); // ignores trailing garbage
- uint64_t toUInt64(bool* ok = nullptr); // ignores trailing garbage
- intptr_t toIntPtr(bool* ok = nullptr); // ignores trailing garbage
-
// FIXME: Like the strict functions above, these give false for "ok" when there is trailing garbage.
// Like the non-strict functions above, these return the value when there is trailing garbage.
// It would be better if these were more consistent with the above functions instead.
Modified: trunk/Source/WTF/wtf/text/StringToIntegerConversion.h (277354 => 277355)
--- trunk/Source/WTF/wtf/text/StringToIntegerConversion.h 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Source/WTF/wtf/text/StringToIntegerConversion.h 2021-05-12 04:23:30 UTC (rev 277355)
@@ -110,35 +110,7 @@
return parseInteger<IntegralType>(string.characters16(), string.length(), base, TrailingJunkPolicy::Allow);
}
-// FIXME: Deprecated. Remove toIntegralType entirely once we get move all callers to parseInteger.
-template<typename IntegralType, typename StringOrStringView> IntegralType toIntegralType(const StringOrStringView& stringView, bool* ok, int base = 10)
-{
- auto result = parseInteger<IntegralType>(stringView, base);
- if (ok)
- *ok = result.hasValue();
- return result.valueOr(0);
}
-// FIXME: Deprecated. Remove toIntegralType entirely once we get move all callers to parseInteger.
-template<typename IntegralType, typename CharacterType> IntegralType toIntegralType(const CharacterType* data, unsigned length, bool* ok, int base = 10)
-{
- return toIntegralType<IntegralType>(StringView { data, length }, ok, base);
-}
-
-// FIXME: Deprecated. Remove toIntegralType entirely once we get move all callers to parseInteger.
-template<typename IntegralType, typename StringOrStringView> Optional<IntegralType> toIntegralType(const StringOrStringView& stringView, int base = 10)
-{
- return parseInteger<IntegralType>(stringView, base);
-}
-
-// FIXME: Deprecated. Remove toIntegralType entirely once we get move all callers to parseInteger.
-template<typename IntegralType, typename CharacterType> Optional<IntegralType> toIntegralType(const CharacterType* data, unsigned length, int base = 10)
-{
- return parseInteger<IntegralType>(StringView { data, length }, base);
-}
-
-}
-
using WTF::parseInteger;
using WTF::parseIntegerAllowingTrailingJunk;
-using WTF::toIntegralType;
Modified: trunk/Source/WTF/wtf/text/StringView.cpp (277354 => 277355)
--- trunk/Source/WTF/wtf/text/StringView.cpp 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Source/WTF/wtf/text/StringView.cpp 2021-05-12 04:23:30 UTC (rev 277355)
@@ -311,17 +311,6 @@
return result.underlyingString;
}
-// FIXME: Should this be named parseNumber<uint16_t> instead?
-// FIXME: Should we replace the toInt family of functions with this style?
-Optional<uint16_t> parseUInt16(StringView string)
-{
- bool ok = false;
- auto number = toIntegralType<uint16_t>(string, &ok);
- if (!ok)
- return WTF::nullopt;
- return number;
-}
-
bool equalRespectingNullity(StringView a, StringView b)
{
if (a.m_characters == b.m_characters) {
Modified: trunk/Source/WTF/wtf/text/StringView.h (277354 => 277355)
--- trunk/Source/WTF/wtf/text/StringView.h 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Source/WTF/wtf/text/StringView.h 2021-05-12 04:23:30 UTC (rev 277355)
@@ -168,11 +168,6 @@
WTF_EXPORT_PRIVATE bool endsWith(const StringView&) const;
WTF_EXPORT_PRIVATE bool endsWithIgnoringASCIICase(const StringView&) const;
- int toInt() const;
- int toInt(bool& isValid) const;
- int toIntStrict(bool& isValid) const;
- Optional<uint64_t> toUInt64Strict() const;
- Optional<int64_t> toInt64Strict() const;
float toFloat(bool& isValid) const;
static void invalidate(const StringImpl&);
@@ -246,8 +241,6 @@
WTF_EXPORT_PRIVATE String normalizedNFC(const String&);
-WTF_EXPORT_PRIVATE Optional<uint16_t> parseUInt16(StringView);
-
}
#include <wtf/text/AtomString.h>
@@ -352,7 +345,7 @@
inline StringView::StringView(const char* characters)
{
- initialize(reinterpret_cast<const LChar*>(characters), strlen(characters));
+ initialize(reinterpret_cast<const LChar*>(characters), characters ? strlen(characters) : 0);
}
inline StringView::StringView(const char* characters, unsigned length)
@@ -588,40 +581,6 @@
return charactersToFloat(characters16(), m_length, &isValid);
}
-inline int StringView::toInt() const
-{
- bool isValid;
- return toInt(isValid);
-}
-
-inline int StringView::toInt(bool& isValid) const
-{
- if (is8Bit())
- return charactersToInt(characters8(), m_length, &isValid);
- return charactersToInt(characters16(), m_length, &isValid);
-}
-
-inline int StringView::toIntStrict(bool& isValid) const
-{
- if (is8Bit())
- return charactersToIntStrict(characters8(), m_length, &isValid);
- return charactersToIntStrict(characters16(), m_length, &isValid);
-}
-
-inline Optional<uint64_t> StringView::toUInt64Strict() const
-{
- bool isValid;
- uint64_t result = is8Bit() ? charactersToUInt64Strict(characters8(), m_length, &isValid) : charactersToUInt64Strict(characters16(), m_length, &isValid);
- return isValid ? makeOptional(result) : WTF::nullopt;
-}
-
-inline Optional<int64_t> StringView::toInt64Strict() const
-{
- bool isValid;
- int64_t result = is8Bit() ? charactersToInt64Strict(characters8(), m_length, &isValid) : charactersToInt64Strict(characters16(), m_length, &isValid);
- return isValid ? makeOptional(result) : WTF::nullopt;
-}
-
inline String StringView::toStringWithoutCopying() const
{
if (is8Bit())
Modified: trunk/Source/WTF/wtf/text/WTFString.cpp (277354 => 277355)
--- trunk/Source/WTF/wtf/text/WTFString.cpp 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Source/WTF/wtf/text/WTFString.cpp 2021-05-12 04:23:30 UTC (rev 277355)
@@ -492,106 +492,6 @@
return numberToFixedWidthString(number, decimalPlaces, buffer);
}
-int String::toIntStrict(bool* ok, int base) const
-{
- if (!m_impl) {
- if (ok)
- *ok = false;
- return 0;
- }
- return m_impl->toIntStrict(ok, base);
-}
-
-unsigned String::toUIntStrict(bool* ok, int base) const
-{
- if (!m_impl) {
- if (ok)
- *ok = false;
- return 0;
- }
- return m_impl->toUIntStrict(ok, base);
-}
-
-int64_t String::toInt64Strict(bool* ok, int base) const
-{
- if (!m_impl) {
- if (ok)
- *ok = false;
- return 0;
- }
- return m_impl->toInt64Strict(ok, base);
-}
-
-uint64_t String::toUInt64Strict(bool* ok, int base) const
-{
- if (!m_impl) {
- if (ok)
- *ok = false;
- return 0;
- }
- return m_impl->toUInt64Strict(ok, base);
-}
-
-intptr_t String::toIntPtrStrict(bool* ok, int base) const
-{
- if (!m_impl) {
- if (ok)
- *ok = false;
- return 0;
- }
- return m_impl->toIntPtrStrict(ok, base);
-}
-
-int String::toInt(bool* ok) const
-{
- if (!m_impl) {
- if (ok)
- *ok = false;
- return 0;
- }
- return m_impl->toInt(ok);
-}
-
-unsigned String::toUInt(bool* ok) const
-{
- if (!m_impl) {
- if (ok)
- *ok = false;
- return 0;
- }
- return m_impl->toUInt(ok);
-}
-
-int64_t String::toInt64(bool* ok) const
-{
- if (!m_impl) {
- if (ok)
- *ok = false;
- return 0;
- }
- return m_impl->toInt64(ok);
-}
-
-uint64_t String::toUInt64(bool* ok) const
-{
- if (!m_impl) {
- if (ok)
- *ok = false;
- return 0;
- }
- return m_impl->toUInt64(ok);
-}
-
-intptr_t String::toIntPtr(bool* ok) const
-{
- if (!m_impl) {
- if (ok)
- *ok = false;
- return 0;
- }
- return m_impl->toIntPtr(ok);
-}
-
double String::toDouble(bool* ok) const
{
if (!m_impl) {
@@ -892,130 +792,7 @@
}
// String Operations
-template<typename CharacterType>
-static unsigned lengthOfCharactersAsInteger(const CharacterType* data, size_t length)
-{
- size_t i = 0;
- // Allow leading spaces.
- for (; i != length; ++i) {
- if (!isSpaceOrNewline(data[i]))
- break;
- }
-
- // Allow sign.
- if (i != length && (data[i] == '+' || data[i] == '-'))
- ++i;
-
- // Allow digits.
- for (; i != length; ++i) {
- if (!isASCIIDigit(data[i]))
- break;
- }
-
- return i;
-}
-
-int charactersToIntStrict(const LChar* data, size_t length, bool* ok, int base)
-{
- return toIntegralType<int>(data, length, ok, base);
-}
-
-int charactersToIntStrict(const UChar* data, size_t length, bool* ok, int base)
-{
- return toIntegralType<int>(data, length, ok, base);
-}
-
-unsigned charactersToUIntStrict(const LChar* data, size_t length, bool* ok, int base)
-{
- return toIntegralType<unsigned>(data, length, ok, base);
-}
-
-unsigned charactersToUIntStrict(const UChar* data, size_t length, bool* ok, int base)
-{
- return toIntegralType<unsigned>(data, length, ok, base);
-}
-
-int64_t charactersToInt64Strict(const LChar* data, size_t length, bool* ok, int base)
-{
- return toIntegralType<int64_t>(data, length, ok, base);
-}
-
-int64_t charactersToInt64Strict(const UChar* data, size_t length, bool* ok, int base)
-{
- return toIntegralType<int64_t>(data, length, ok, base);
-}
-
-uint64_t charactersToUInt64Strict(const LChar* data, size_t length, bool* ok, int base)
-{
- return toIntegralType<uint64_t>(data, length, ok, base);
-}
-
-uint64_t charactersToUInt64Strict(const UChar* data, size_t length, bool* ok, int base)
-{
- return toIntegralType<uint64_t>(data, length, ok, base);
-}
-
-intptr_t charactersToIntPtrStrict(const LChar* data, size_t length, bool* ok, int base)
-{
- return toIntegralType<intptr_t>(data, length, ok, base);
-}
-
-intptr_t charactersToIntPtrStrict(const UChar* data, size_t length, bool* ok, int base)
-{
- return toIntegralType<intptr_t>(data, length, ok, base);
-}
-
-int charactersToInt(const LChar* data, size_t length, bool* ok)
-{
- return toIntegralType<int>(data, lengthOfCharactersAsInteger<LChar>(data, length), ok, 10);
-}
-
-int charactersToInt(const UChar* data, size_t length, bool* ok)
-{
- return toIntegralType<int>(data, lengthOfCharactersAsInteger(data, length), ok, 10);
-}
-
-unsigned charactersToUInt(const LChar* data, size_t length, bool* ok)
-{
- return toIntegralType<unsigned>(data, lengthOfCharactersAsInteger<LChar>(data, length), ok, 10);
-}
-
-unsigned charactersToUInt(const UChar* data, size_t length, bool* ok)
-{
- return toIntegralType<unsigned>(data, lengthOfCharactersAsInteger<UChar>(data, length), ok, 10);
-}
-
-int64_t charactersToInt64(const LChar* data, size_t length, bool* ok)
-{
- return toIntegralType<int64_t>(data, lengthOfCharactersAsInteger<LChar>(data, length), ok, 10);
-}
-
-int64_t charactersToInt64(const UChar* data, size_t length, bool* ok)
-{
- return toIntegralType<int64_t>(data, lengthOfCharactersAsInteger<UChar>(data, length), ok, 10);
-}
-
-uint64_t charactersToUInt64(const LChar* data, size_t length, bool* ok)
-{
- return toIntegralType<uint64_t>(data, lengthOfCharactersAsInteger<LChar>(data, length), ok, 10);
-}
-
-uint64_t charactersToUInt64(const UChar* data, size_t length, bool* ok)
-{
- return toIntegralType<uint64_t>(data, lengthOfCharactersAsInteger<UChar>(data, length), ok, 10);
-}
-
-intptr_t charactersToIntPtr(const LChar* data, size_t length, bool* ok)
-{
- return toIntegralType<intptr_t>(data, lengthOfCharactersAsInteger<LChar>(data, length), ok, 10);
-}
-
-intptr_t charactersToIntPtr(const UChar* data, size_t length, bool* ok)
-{
- return toIntegralType<intptr_t>(data, lengthOfCharactersAsInteger<UChar>(data, length), ok, 10);
-}
-
template<typename CharacterType, TrailingJunkPolicy policy>
static inline double toDoubleType(const CharacterType* data, size_t length, bool* ok, size_t& parsedLength)
{
Modified: trunk/Source/WTF/wtf/text/WTFString.h (277354 => 277355)
--- trunk/Source/WTF/wtf/text/WTFString.h 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Source/WTF/wtf/text/WTFString.h 2021-05-12 04:23:30 UTC (rev 277355)
@@ -42,31 +42,6 @@
// Declarations of string operations
-WTF_EXPORT_PRIVATE int charactersToIntStrict(const LChar*, size_t, bool* ok = nullptr, int base = 10);
-WTF_EXPORT_PRIVATE int charactersToIntStrict(const UChar*, size_t, bool* ok = nullptr, int base = 10);
-WTF_EXPORT_PRIVATE unsigned charactersToUIntStrict(const LChar*, size_t, bool* ok = nullptr, int base = 10);
-WTF_EXPORT_PRIVATE unsigned charactersToUIntStrict(const UChar*, size_t, bool* ok = nullptr, int base = 10);
-WTF_EXPORT_PRIVATE int64_t charactersToInt64Strict(const LChar*, size_t, bool* ok = nullptr, int base = 10);
-WTF_EXPORT_PRIVATE int64_t charactersToInt64Strict(const UChar*, size_t, bool* ok = nullptr, int base = 10);
-WTF_EXPORT_PRIVATE uint64_t charactersToUInt64Strict(const LChar*, size_t, bool* ok = nullptr, int base = 10);
-WTF_EXPORT_PRIVATE uint64_t charactersToUInt64Strict(const UChar*, size_t, bool* ok = nullptr, int base = 10);
-intptr_t charactersToIntPtrStrict(const LChar*, size_t, bool* ok = nullptr, int base = 10);
-intptr_t charactersToIntPtrStrict(const UChar*, size_t, bool* ok = nullptr, int base = 10);
-
-WTF_EXPORT_PRIVATE int charactersToInt(const LChar*, size_t, bool* ok = nullptr); // ignores trailing garbage
-WTF_EXPORT_PRIVATE int charactersToInt(const UChar*, size_t, bool* ok = nullptr); // ignores trailing garbage
-unsigned charactersToUInt(const LChar*, size_t, bool* ok = nullptr); // ignores trailing garbage
-unsigned charactersToUInt(const UChar*, size_t, bool* ok = nullptr); // ignores trailing garbage
-int64_t charactersToInt64(const LChar*, size_t, bool* ok = nullptr); // ignores trailing garbage
-int64_t charactersToInt64(const UChar*, size_t, bool* ok = nullptr); // ignores trailing garbage
-uint64_t charactersToUInt64(const LChar*, size_t, bool* ok = nullptr); // ignores trailing garbage
-WTF_EXPORT_PRIVATE uint64_t charactersToUInt64(const UChar*, size_t, bool* ok = nullptr); // ignores trailing garbage
-intptr_t charactersToIntPtr(const LChar*, size_t, bool* ok = nullptr); // ignores trailing garbage
-intptr_t charactersToIntPtr(const UChar*, size_t, bool* ok = nullptr); // ignores trailing garbage
-
-// FIXME: Like the strict functions above, these give false for "ok" when there is trailing garbage.
-// Like the non-strict functions above, these return the value when there is trailing garbage.
-// It would be better if these were more consistent with the above functions instead.
WTF_EXPORT_PRIVATE double charactersToDouble(const LChar*, size_t, bool* ok = nullptr);
WTF_EXPORT_PRIVATE double charactersToDouble(const UChar*, size_t, bool* ok = nullptr);
WTF_EXPORT_PRIVATE float charactersToFloat(const LChar*, size_t, bool* ok = nullptr);
@@ -281,21 +256,6 @@
WTF_EXPORT_PRIVATE Vector<String> splitAllowingEmptyEntries(UChar separator) const;
WTF_EXPORT_PRIVATE Vector<String> splitAllowingEmptyEntries(const String& separator) const;
- WTF_EXPORT_PRIVATE int toIntStrict(bool* ok = nullptr, int base = 10) const;
- WTF_EXPORT_PRIVATE unsigned toUIntStrict(bool* ok = nullptr, int base = 10) const;
- WTF_EXPORT_PRIVATE int64_t toInt64Strict(bool* ok = nullptr, int base = 10) const;
- WTF_EXPORT_PRIVATE uint64_t toUInt64Strict(bool* ok = nullptr, int base = 10) const;
- WTF_EXPORT_PRIVATE intptr_t toIntPtrStrict(bool* ok = nullptr, int base = 10) const;
-
- WTF_EXPORT_PRIVATE int toInt(bool* ok = nullptr) const;
- WTF_EXPORT_PRIVATE unsigned toUInt(bool* ok = nullptr) const;
- WTF_EXPORT_PRIVATE int64_t toInt64(bool* ok = nullptr) const;
- WTF_EXPORT_PRIVATE uint64_t toUInt64(bool* ok = nullptr) const;
- WTF_EXPORT_PRIVATE intptr_t toIntPtr(bool* ok = nullptr) const;
-
- // FIXME: Like the strict functions above, these give false for "ok" when there is trailing garbage.
- // Like the non-strict functions above, these return the value when there is trailing garbage.
- // It would be better if these were more consistent with the above functions instead.
WTF_EXPORT_PRIVATE double toDouble(bool* ok = nullptr) const;
WTF_EXPORT_PRIVATE float toFloat(bool* ok = nullptr) const;
@@ -680,16 +640,6 @@
using WTF::appendNumber;
using WTF::charactersToDouble;
using WTF::charactersToFloat;
-using WTF::charactersToInt64;
-using WTF::charactersToInt64Strict;
-using WTF::charactersToInt;
-using WTF::charactersToIntPtr;
-using WTF::charactersToIntPtrStrict;
-using WTF::charactersToIntStrict;
-using WTF::charactersToUInt64;
-using WTF::charactersToUInt64Strict;
-using WTF::charactersToUInt;
-using WTF::charactersToUIntStrict;
using WTF::emptyString;
using WTF::nullString;
using WTF::equal;
Modified: trunk/Source/WebCore/ChangeLog (277354 => 277355)
--- trunk/Source/WebCore/ChangeLog 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Source/WebCore/ChangeLog 2021-05-12 04:23:30 UTC (rev 277355)
@@ -1,3 +1,25 @@
+2021-05-11 Darin Adler <da...@apple.com>
+
+ Remove the String::toInt family of functions
+ https://bugs.webkit.org/show_bug.cgi?id=225599
+
+ Reviewed by Anders Carlsson.
+
+ * platform/graphics/GLContext.cpp:
+ (WebCore::GLContext::version): Use
+ parseIntegerAllowingTrailingJunk<unsigned> instead of String::toUInt.
+
+ * platform/graphics/GlyphBuffer.h:
+ (WebCore::GlyphBuffer::checkedStringOffsetAt const): Fix code that was
+ assuming GlyphBufferStringOffset was signed to compile without a warning
+ regardless of whether it's signed or unsigned. This was making GTK
+ builds have tons and tons of warnings, which was distracting while
+ working on the other fixes here.
+
+ * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
+ (CachedResourceStreamingClient::responseReceived): Use
+ parseIntegerAllowingTrailingJunk<uint64_t> instead of String::toUInt64.
+
2021-05-11 Commit Queue <commit-qu...@webkit.org>
Unreviewed, reverting r277341.
Modified: trunk/Source/WebCore/platform/graphics/GLContext.cpp (277354 => 277355)
--- trunk/Source/WebCore/platform/graphics/GLContext.cpp 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Source/WebCore/platform/graphics/GLContext.cpp 2021-05-12 04:23:30 UTC (rev 277355)
@@ -19,8 +19,11 @@
#include "config.h"
#if USE(OPENGL) || USE(OPENGL_ES)
+
#include "GLContext.h"
+
#include <wtf/ThreadSpecific.h>
+#include <wtf/text/StringToIntegerConversion.h>
#if USE(EGL)
#include "GLContextEGL.h"
@@ -183,7 +186,8 @@
versionDigits = versionStringComponents[0].split('.');
}
- m_version = versionDigits[0].toUInt() * 100 + versionDigits[1].toUInt() * 10;
+ m_version = parseIntegerAllowingTrailingJunk<unsigned>(versionDigits[0]).valueOr(0) * 100
+ + parseIntegerAllowingTrailingJunk<unsigned>(versionDigits[1]).valueOr(0) * 10;
}
return m_version;
}
Modified: trunk/Source/WebCore/platform/graphics/GlyphBuffer.h (277354 => 277355)
--- trunk/Source/WebCore/platform/graphics/GlyphBuffer.h 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Source/WebCore/platform/graphics/GlyphBuffer.h 2021-05-12 04:23:30 UTC (rev 277355)
@@ -78,7 +78,7 @@
Optional<GlyphBufferStringOffset> checkedStringOffsetAt(unsigned index, unsigned stringLength) const
{
auto result = uncheckedStringOffsetAt(index);
- if (result < 0 || static_cast<unsigned>(result) >= stringLength)
+ if (static_cast<std::make_unsigned_t<GlyphBufferStringOffset>>(result) >= stringLength)
return WTF::nullopt;
return result;
}
Modified: trunk/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp (277354 => 277355)
--- trunk/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp 2021-05-12 04:23:30 UTC (rev 277355)
@@ -1025,10 +1025,8 @@
// Pack response headers in the http-headers structure.
headers.reset(gst_structure_new_empty("response-headers"));
for (const auto& header : response.httpHeaderFields()) {
- bool ok = false;
- uint64_t convertedValue = header.value.toUInt64(&ok);
- if (ok)
- gst_structure_set(headers.get(), header.key.utf8().data(), G_TYPE_UINT64, convertedValue, nullptr);
+ if (auto convertedValue = parseIntegerAllowingTrailingJunk<uint64_t>(header.value))
+ gst_structure_set(headers.get(), header.key.utf8().data(), G_TYPE_UINT64, *convertedValue, nullptr);
else
gst_structure_set(headers.get(), header.key.utf8().data(), G_TYPE_STRING, header.value.utf8().data(), nullptr);
}
Modified: trunk/Source/WebKit/ChangeLog (277354 => 277355)
--- trunk/Source/WebKit/ChangeLog 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Source/WebKit/ChangeLog 2021-05-12 04:23:30 UTC (rev 277355)
@@ -1,3 +1,20 @@
+2021-05-11 Darin Adler <da...@apple.com>
+
+ Remove the String::toInt family of functions
+ https://bugs.webkit.org/show_bug.cgi?id=225599
+
+ Reviewed by Anders Carlsson.
+
+ * Shared/win/AuxiliaryProcessMainWin.cpp:
+ (WebKit::AuxiliaryProcessMainCommon::parseCommandLine): Use
+ parseIntegerAllowingTrailingJunk<uint64_t> instead of String::toUInt64.
+ * UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp:
+ (WebKit::ScriptMessageClient::didPostMessage): Ditto.
+ * UIProcess/win/WebProcessPoolWin.cpp:
+ (WebKit::initializeRemoteInspectorServer): Use
+ parseIntegerAllowingTrailingJunk<uint16_t> instead of StringView::toUInt64.
+ This is a 16-bit port number, so not valuable to parse larger integers.
+
2021-05-11 Devin Rousso <drou...@apple.com>
[macCatalyst] should have CSS `hover: hover` and `pointer: fine`
Modified: trunk/Source/WebKit/Shared/win/AuxiliaryProcessMainWin.cpp (277354 => 277355)
--- trunk/Source/WebKit/Shared/win/AuxiliaryProcessMainWin.cpp 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Source/WebKit/Shared/win/AuxiliaryProcessMainWin.cpp 2021-05-12 04:23:30 UTC (rev 277355)
@@ -28,7 +28,7 @@
#include <_javascript_Core/ExecutableAllocator.h>
#include <cstring>
-#include <wtf/text/WTFString.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebKit {
@@ -35,13 +35,11 @@
bool AuxiliaryProcessMainCommon::parseCommandLine(int argc, char** argv)
{
for (int i = 0; i < argc; i++) {
- if (!strcmp(argv[i], "-clientIdentifier") && i + 1 < argc) {
- String str(argv[++i]);
- m_parameters.connectionIdentifier = reinterpret_cast<HANDLE>(str.toUInt64());
- } else if (!strcmp(argv[i], "-processIdentifier") && i + 1 < argc) {
- String str(argv[++i]);
- m_parameters.processIdentifier = makeObjectIdentifier<WebCore::ProcessIdentifierType>(str.toUInt64());
- } else if (!strcmp(argv[i], "-configure-jsc-for-testing"))
+ if (!strcmp(argv[i], "-clientIdentifier") && i + 1 < argc)
+ m_parameters.connectionIdentifier = reinterpret_cast<HANDLE>(parseIntegerAllowingTrailingJunk<uint64_t>(argv[++i]).valueOr(0));
+ else if (!strcmp(argv[i], "-processIdentifier") && i + 1 < argc)
+ m_parameters.processIdentifier = makeObjectIdentifier<WebCore::ProcessIdentifierType>(parseIntegerAllowingTrailingJunk<uint64_t>(argv[++i]).valueOr(0));
+ else if (!strcmp(argv[i], "-configure-jsc-for-testing"))
JSC::Config::configureForTesting();
else if (!strcmp(argv[i], "-disable-jit"))
JSC::ExecutableAllocator::setJITEnabled(false);
Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp (277354 => 277355)
--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitRemoteInspectorProtocolHandler.cpp 2021-05-12 04:23:30 UTC (rev 277355)
@@ -30,6 +30,7 @@
#include "WebPageProxy.h"
#include "WebScriptMessageHandler.h"
#include <wtf/URL.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebKit {
using namespace WebCore;
@@ -50,7 +51,7 @@
return;
URL requestURL = URL({ }, page.pageLoadState().url());
- m_inspectorProtocolHandler.inspect(requestURL.hostAndPort(), tokens[0].toUInt64(), tokens[1].toUInt64(), tokens[2]);
+ m_inspectorProtocolHandler.inspect(requestURL.hostAndPort(), parseIntegerAllowingTrailingJunk<uint64_t>(tokens[0]).valueOr(0), parseIntegerAllowingTrailingJunk<uint64_t>(tokens[1]).valueOr(0), tokens[2]);
}
bool supportsAsyncReply() override
Modified: trunk/Source/WebKit/UIProcess/Inspector/socket/RemoteInspectorProtocolHandler.cpp (277354 => 277355)
--- trunk/Source/WebKit/UIProcess/Inspector/socket/RemoteInspectorProtocolHandler.cpp 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Source/WebKit/UIProcess/Inspector/socket/RemoteInspectorProtocolHandler.cpp 2021-05-12 04:23:30 UTC (rev 277355)
@@ -39,6 +39,7 @@
#include <WebCore/SerializedScriptValue.h>
#include <wtf/URL.h>
#include <wtf/text/StringBuilder.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebKit {
@@ -59,7 +60,7 @@
return;
URL requestURL { { }, page.pageLoadState().url() };
- m_inspectorProtocolHandler.inspect(requestURL.hostAndPort(), tokens[0].toUIntStrict(), tokens[1].toUIntStrict(), tokens[2]);
+ m_inspectorProtocolHandler.inspect(requestURL.hostAndPort(), parseInteger<int>(tokens[0]).valueOr(0), parseInteger<int>(tokens[1]).valueOr(0), tokens[2]);
}
bool supportsAsyncReply() override
Modified: trunk/Source/WebKit/UIProcess/win/WebProcessPoolWin.cpp (277354 => 277355)
--- trunk/Source/WebKit/UIProcess/win/WebProcessPoolWin.cpp 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Source/WebKit/UIProcess/win/WebProcessPoolWin.cpp 2021-05-12 04:23:30 UTC (rev 277355)
@@ -33,6 +33,7 @@
#if ENABLE(REMOTE_INSPECTOR)
#include <_javascript_Core/RemoteInspectorServer.h>
#include <WebCore/WebCoreBundleWin.h>
+#include <wtf/text/StringToIntegerConversion.h>
#endif
namespace WebKit {
@@ -61,7 +62,7 @@
return;
auto host = address.substring(0, pos);
- auto port = address.substring(pos + 1).toUInt64Strict();
+ auto port = parseInteger<uint16_t>(address.substring(pos + 1));
if (!port)
return;
Modified: trunk/Tools/ChangeLog (277354 => 277355)
--- trunk/Tools/ChangeLog 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Tools/ChangeLog 2021-05-12 04:23:30 UTC (rev 277355)
@@ -1,3 +1,26 @@
+2021-05-11 Darin Adler <da...@apple.com>
+
+ Remove the String::toInt family of functions
+ https://bugs.webkit.org/show_bug.cgi?id=225599
+
+ Reviewed by Anders Carlsson.
+
+ * TestWebKitAPI/CMakeLists.txt: Added StringToIntegerConversion.cpp.
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Ditto.
+
+ * TestWebKitAPI/Tests/WTF/StringToIntegerConversion.cpp: Added.
+ Contains tests moved and adapted from the files below so we don't
+ lose test coverage. We and and should add many more tests.
+
+ * TestWebKitAPI/Tests/WTF/StringView.cpp: Removed tests for parseUInt16
+ and StringView::toIntStrict.
+
+ * TestWebKitAPI/Tests/WTF/WTFString.cpp: Removed tests for String::toInt.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm: Use
+ parseInteger<uint64_t> instead of StringView::toUInt64Strict.
+ * TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm: Ditto.
+
2021-05-11 Devin Rousso <drou...@apple.com>
[macCatalyst] should have CSS `hover: hover` and `pointer: fine`
Modified: trunk/Tools/TestWebKitAPI/CMakeLists.txt (277354 => 277355)
--- trunk/Tools/TestWebKitAPI/CMakeLists.txt 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Tools/TestWebKitAPI/CMakeLists.txt 2021-05-12 04:23:30 UTC (rev 277355)
@@ -93,6 +93,7 @@
Tests/WTF/StringImpl.cpp
Tests/WTF/StringOperators.cpp
Tests/WTF/StringParsingBuffer.cpp
+ Tests/WTF/StringToIntegerConversion.cpp
Tests/WTF/StringView.cpp
Tests/WTF/SynchronizedFixedQueue.cpp
Tests/WTF/TextBreakIterator.cpp
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (277354 => 277355)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2021-05-12 04:23:30 UTC (rev 277355)
@@ -831,6 +831,7 @@
931C281E22BC579A001D98C4 /* opendatabase-always-exists.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 931C281B22BC5583001D98C4 /* opendatabase-always-exists.html */; };
9329AA291DE3F81E003ABD07 /* TextBreakIterator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9329AA281DE3F81E003ABD07 /* TextBreakIterator.cpp */; };
932AE53D1D371047005DFFAF /* focus-inputs.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 93575C551D30366E000D604D /* focus-inputs.html */; };
+ 9332EF942649BB68009F5D6D /* StringToIntegerConversion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9332EF932649BB68009F5D6D /* StringToIntegerConversion.cpp */; };
933D631D1FCB76200032ECD6 /* Hasher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 933D631B1FCB76180032ECD6 /* Hasher.cpp */; };
9342589C255B609B0059EEDD /* SpeechRecognition.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9342589B255B609A0059EEDD /* SpeechRecognition.mm */; };
9342589E255B6A120059EEDD /* speechrecognition-user-permission-persistence.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9342589D255B66A00059EEDD /* speechrecognition-user-permission-persistence.html */; };
@@ -2512,6 +2513,7 @@
931C281C22BC55A7001D98C4 /* WebSQLBasics.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebSQLBasics.mm; sourceTree = "<group>"; };
9329AA281DE3F81E003ABD07 /* TextBreakIterator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextBreakIterator.cpp; sourceTree = "<group>"; };
9331407B17B4419000F083B1 /* DidNotHandleKeyDown.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DidNotHandleKeyDown.cpp; sourceTree = "<group>"; };
+ 9332EF932649BB68009F5D6D /* StringToIntegerConversion.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringToIntegerConversion.cpp; sourceTree = "<group>"; };
933D631B1FCB76180032ECD6 /* Hasher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Hasher.cpp; sourceTree = "<group>"; };
9342589B255B609A0059EEDD /* SpeechRecognition.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SpeechRecognition.mm; sourceTree = "<group>"; };
9342589D255B66A00059EEDD /* speechrecognition-user-permission-persistence.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "speechrecognition-user-permission-persistence.html"; sourceTree = "<group>"; };
@@ -4464,6 +4466,7 @@
26F1B44315CA434F00D1E4BF /* StringImpl.cpp */,
C01363C713C3997300EF3964 /* StringOperators.cpp */,
7CD70C4E24A436EE00E61040 /* StringParsingBuffer.cpp */,
+ 9332EF932649BB68009F5D6D /* StringToIntegerConversion.cpp */,
7C74D42D188228F300E5ED57 /* StringView.cpp */,
5597F8341D9596C80066BC21 /* SynchronizedFixedQueue.cpp */,
9329AA281DE3F81E003ABD07 /* TextBreakIterator.cpp */,
@@ -5220,6 +5223,7 @@
7C83DF371D0A590C00FEBCF3 /* StringImpl.cpp in Sources */,
7C83DF381D0A590C00FEBCF3 /* StringOperators.cpp in Sources */,
7CD70C4F24A436EE00E61040 /* StringParsingBuffer.cpp in Sources */,
+ 9332EF942649BB68009F5D6D /* StringToIntegerConversion.cpp in Sources */,
7C83DF3A1D0A590C00FEBCF3 /* StringView.cpp in Sources */,
5597F8361D9596C80066BC21 /* SynchronizedFixedQueue.cpp in Sources */,
7C83DF401D0A590C00FEBCF3 /* TestsController.cpp in Sources */,
Added: trunk/Tools/TestWebKitAPI/Tests/WTF/StringToIntegerConversion.cpp (0 => 277355)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/StringToIntegerConversion.cpp (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/StringToIntegerConversion.cpp 2021-05-12 04:23:30 UTC (rev 277355)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include <wtf/text/StringToIntegerConversion.h>
+
+namespace TestWebKitAPI {
+
+TEST(WTF, ParseInteger)
+{
+ EXPECT_EQ(WTF::nullopt, parseInteger<int>(static_cast<const char*>(nullptr)));
+ EXPECT_EQ(WTF::nullopt, parseInteger<int>(""));
+ EXPECT_EQ(0, parseInteger<int>("0"));
+ EXPECT_EQ(1, parseInteger<int>("1"));
+ EXPECT_EQ(3, parseInteger<int>("3"));
+ EXPECT_EQ(-3, parseInteger<int>("-3"));
+ EXPECT_EQ(12345, parseInteger<int>("12345"));
+ EXPECT_EQ(-12345, parseInteger<int>("-12345"));
+ EXPECT_EQ(2147483647, parseInteger<int>("2147483647"));
+ EXPECT_EQ(WTF::nullopt, parseInteger<int>("2147483648"));
+ EXPECT_EQ(-2147483647 - 1, parseInteger<int>("-2147483648"));
+ EXPECT_EQ(WTF::nullopt, parseInteger<int>("-2147483649"));
+ EXPECT_EQ(WTF::nullopt, parseInteger<int>("x1"));
+ EXPECT_EQ(1, parseInteger<int>(" 1"));
+ EXPECT_EQ(WTF::nullopt, parseInteger<int>("1x"));
+
+ EXPECT_EQ(0U, 0U + *parseInteger<uint16_t>("0"));
+ EXPECT_EQ(3U, 0U + *parseInteger<uint16_t>("3"));
+ EXPECT_EQ(12345U, 0U + *parseInteger<uint16_t>("12345"));
+ EXPECT_EQ(65535U, 0U + *parseInteger<uint16_t>("65535"));
+ EXPECT_EQ(WTF::nullopt, parseInteger<uint16_t>("-1"));
+ EXPECT_EQ(WTF::nullopt, parseInteger<uint16_t>("-3"));
+ EXPECT_EQ(WTF::nullopt, parseInteger<uint16_t>("65536"));
+}
+
+TEST(WTF, ParseIntegerAllowingTrailingJunk)
+{
+ EXPECT_EQ(WTF::nullopt, parseIntegerAllowingTrailingJunk<int>(static_cast<const char*>(nullptr)));
+ EXPECT_EQ(WTF::nullopt, parseIntegerAllowingTrailingJunk<int>(""));
+ EXPECT_EQ(0, parseIntegerAllowingTrailingJunk<int>("0"));
+ EXPECT_EQ(1, parseIntegerAllowingTrailingJunk<int>("1"));
+ EXPECT_EQ(3, parseIntegerAllowingTrailingJunk<int>("3"));
+ EXPECT_EQ(-3, parseIntegerAllowingTrailingJunk<int>("-3"));
+ EXPECT_EQ(12345, parseIntegerAllowingTrailingJunk<int>("12345"));
+ EXPECT_EQ(-12345, parseIntegerAllowingTrailingJunk<int>("-12345"));
+ EXPECT_EQ(2147483647, parseIntegerAllowingTrailingJunk<int>("2147483647"));
+ EXPECT_EQ(WTF::nullopt, parseIntegerAllowingTrailingJunk<int>("2147483648"));
+ EXPECT_EQ(-2147483647 - 1, parseIntegerAllowingTrailingJunk<int>("-2147483648"));
+ EXPECT_EQ(WTF::nullopt, parseIntegerAllowingTrailingJunk<int>("-2147483649"));
+ EXPECT_EQ(WTF::nullopt, parseIntegerAllowingTrailingJunk<int>("x1"));
+ EXPECT_EQ(1, parseIntegerAllowingTrailingJunk<int>(" 1"));
+ EXPECT_EQ(1, parseIntegerAllowingTrailingJunk<int>("1x"));
+
+ EXPECT_EQ(0U, 0U + *parseIntegerAllowingTrailingJunk<uint16_t>("0"));
+ EXPECT_EQ(3U, 0U + *parseIntegerAllowingTrailingJunk<uint16_t>("3"));
+ EXPECT_EQ(12345U, 0U + *parseIntegerAllowingTrailingJunk<uint16_t>("12345"));
+ EXPECT_EQ(65535U, 0U + *parseIntegerAllowingTrailingJunk<uint16_t>("65535"));
+ EXPECT_EQ(WTF::nullopt, parseIntegerAllowingTrailingJunk<uint16_t>("-1"));
+ EXPECT_EQ(WTF::nullopt, parseIntegerAllowingTrailingJunk<uint16_t>("-3"));
+ EXPECT_EQ(WTF::nullopt, parseIntegerAllowingTrailingJunk<uint16_t>("65536"));
+}
+
+} // namespace TestWebKitAPI
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp (277354 => 277355)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp 2021-05-12 04:23:30 UTC (rev 277355)
@@ -990,37 +990,4 @@
EXPECT_TRUE(StringView(String(bitwise_cast<const UChar*>(u"Hello"))).isAllASCII());
}
-TEST(WTF, StringViewParseUInt16)
-{
- EXPECT_EQ(0U, *WTF::parseUInt16("0"));
- EXPECT_EQ(3U, *WTF::parseUInt16("3"));
- EXPECT_EQ(12345U, *WTF::parseUInt16("12345"));
- EXPECT_EQ(65535U, *WTF::parseUInt16("65535"));
- EXPECT_TRUE(!WTF::parseUInt16("-1"));
- EXPECT_TRUE(!WTF::parseUInt16("-3"));
- EXPECT_TRUE(!WTF::parseUInt16("65536"));
-}
-
-TEST(WTF, StringViewToIntStrict)
-{
- auto test = [](ASCIILiteral string) {
- bool isValid = false;
- int result = StringView(string).toIntStrict(isValid);
- return isValid ? makeOptional(result) : WTF::nullopt;
- };
- EXPECT_EQ(0, *test("0"_s));
- EXPECT_EQ(3, *test("3"_s));
- EXPECT_EQ(-3, *test("-3"_s));
- EXPECT_EQ(12345, *test("12345"_s));
- EXPECT_EQ(-12345, *test("-12345"_s));
- if (std::numeric_limits<int>::max() == 2147483647) {
- EXPECT_EQ(2147483647, *test("2147483647"_s));
- EXPECT_TRUE(!test("2147483648"_s));
- }
- if (std::numeric_limits<int>::min() == -2147483648) {
- EXPECT_EQ(-2147483648, *test("-2147483648"_s));
- EXPECT_TRUE(!test("-2147483649"_s));
- }
-}
-
} // namespace TestWebKitAPI
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp (277354 => 277355)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp 2021-05-12 04:23:30 UTC (rev 277355)
@@ -287,58 +287,6 @@
EXPECT_FALSE(original.impl() == copy.impl());
}
-TEST(WTF, StringToInt)
-{
- bool ok = false;
-
- EXPECT_EQ(0, String().toInt());
- EXPECT_EQ(0, String().toInt(&ok));
- EXPECT_FALSE(ok);
-
- EXPECT_EQ(0, emptyString().toInt());
- EXPECT_EQ(0, emptyString().toInt(&ok));
- EXPECT_FALSE(ok);
-
- EXPECT_EQ(0, String("0").toInt());
- EXPECT_EQ(0, String("0").toInt(&ok));
- EXPECT_TRUE(ok);
-
- EXPECT_EQ(1, String("1").toInt());
- EXPECT_EQ(1, String("1").toInt(&ok));
- EXPECT_TRUE(ok);
-
- EXPECT_EQ(2147483647, String("2147483647").toInt());
- EXPECT_EQ(2147483647, String("2147483647").toInt(&ok));
- EXPECT_TRUE(ok);
-
- EXPECT_EQ(0, String("2147483648").toInt());
- EXPECT_EQ(0, String("2147483648").toInt(&ok));
- EXPECT_FALSE(ok);
-
- EXPECT_EQ(-2147483648, String("-2147483648").toInt());
- EXPECT_EQ(-2147483648, String("-2147483648").toInt(&ok));
- EXPECT_TRUE(ok);
-
- EXPECT_EQ(0, String("-2147483649").toInt());
- EXPECT_EQ(0, String("-2147483649").toInt(&ok));
- EXPECT_FALSE(ok);
-
- // fail if we see leading junk
- EXPECT_EQ(0, String("x1").toInt());
- EXPECT_EQ(0, String("x1").toInt(&ok));
- EXPECT_FALSE(ok);
-
- // succeed if we see leading spaces
- EXPECT_EQ(1, String(" 1").toInt());
- EXPECT_EQ(1, String(" 1").toInt(&ok));
- EXPECT_TRUE(ok);
-
- // silently ignore trailing junk
- EXPECT_EQ(1, String("1x").toInt());
- EXPECT_EQ(1, String("1x").toInt(&ok));
- EXPECT_TRUE(ok);
-}
-
TEST(WTF, StringToDouble)
{
bool ok = false;
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm (277354 => 277355)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm 2021-05-12 04:23:30 UTC (rev 277355)
@@ -50,6 +50,7 @@
#import <wtf/WeakObjCPtr.h>
#import <wtf/text/StringConcatenateNumbers.h>
#import <wtf/text/StringHash.h>
+#import <wtf/text/StringToIntegerConversion.h>
#import <wtf/text/WTFString.h>
static bool done;
@@ -1601,8 +1602,8 @@
auto rangeBeginString = requestRangeString.substring(begin + rangeBytes.length(), dash - begin - rangeBytes.length());
auto rangeEndString = requestRangeString.substring(dash + 1, end - dash - 1);
- auto rangeBegin = rangeBeginString.toUInt64Strict();
- auto rangeEnd = rangeEndString == "*" ? [videoData length] : rangeEndString.toUInt64Strict();
+ auto rangeBegin = parseInteger<uint64_t>(rangeBeginString).valueOr(0);
+ auto rangeEnd = rangeEndString == "*" ? [videoData length] : parseInteger<uint64_t>(rangeEndString).valueOr(0);
auto response = adoptNS([[NSHTTPURLResponse alloc] initWithURL:[NSURL URLWithString:@"https://webkit.org/"] statusCode:206 HTTPVersion:@"HTTP/1.1" headerFields:@{
@"Content-Range" : [NSString stringWithFormat:@"bytes %llu-%llu/%lu", rangeBegin, rangeEnd, (unsigned long)[videoData length]],
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm (277354 => 277355)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm 2021-05-12 03:55:46 UTC (rev 277354)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm 2021-05-12 04:23:30 UTC (rev 277355)
@@ -47,6 +47,7 @@
#import <WebKit/_WKWebsiteDataStoreConfiguration.h>
#import <wtf/Deque.h>
#import <wtf/RetainPtr.h>
+#import <wtf/text/StringToIntegerConversion.h>
#import <wtf/text/WTFString.h>
static bool receivedScriptMessage;
@@ -770,8 +771,8 @@
auto end = request.find('\r', dash);
ASSERT(end != notFound);
- auto rangeBegin = *request.substring(begin + rangeBytes.length(), dash - begin - rangeBytes.length()).toUInt64Strict();
- auto rangeEnd = *request.substring(dash + 1, end - dash - 1).toUInt64Strict();
+ auto rangeBegin = parseInteger<uint64_t>(request.substring(begin + rangeBytes.length(), dash - begin - rangeBytes.length())).value();
+ auto rangeEnd = parseInteger<uint64_t>(request.substring(dash + 1, end - dash - 1)).value();
NSString *responseHeaderString = [NSString stringWithFormat:
@"HTTP/1.1 206 Partial Content\r\n"