Title: [277249] trunk/Source/WebCore
Revision
277249
Author
[email protected]
Date
2021-05-09 11:54:10 -0700 (Sun, 09 May 2021)

Log Message

Remove uses of the String::toInt family of functions from the WebCore/platform directory
https://bugs.webkit.org/show_bug.cgi?id=225575

Second half.

Reviewed by Sam Weinig.

* platform/mediastream/mac/ScreenDisplayCapturerMac.mm:
(WebCore::ScreenDisplayCapturerMac::create): Use parseInteger<uint32_t>
instead of String::toUIntStrict.
(WebCore::ScreenDisplayCapturerMac::screenCaptureDeviceWithPersistentID): Ditto.
* platform/mediastream/mac/WindowDisplayCapturerMac.mm:
(WebCore::WindowDisplayCapturerMac::create): Ditto.
(WebCore::WindowDisplayCapturerMac::windowCaptureDeviceWithPersistentID): Ditto.

* platform/network/HTTPParsers.cpp:
(WebCore::parseRange): Use parseInteger<long long> instead of
String::toInt64Strict. Also use StringView so we don't allocate substrings on
the heap just to parse integers within an existing string. And removed unneeded
call to stripWhiteSpace in one place since parseInteger already allows leading
and trailing spaces, and in another case where we need to strip because of an
empty string check, used stripLeadingAndTrailingHTTPSpaces instead.

* platform/network/ParsedContentRange.cpp:
(WebCore::parseContentRange): Use parseInteger<int64_t> instead of
StringView::toInt64Strict.

* platform/network/ParsedRequestRange.cpp:
(WebCore::ParsedRequestRange::parse): Use parseInteger<uint64_t> instead of
StringView::toUInt64Strict.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (277248 => 277249)


--- trunk/Source/WebCore/ChangeLog	2021-05-09 18:39:24 UTC (rev 277248)
+++ trunk/Source/WebCore/ChangeLog	2021-05-09 18:54:10 UTC (rev 277249)
@@ -1,5 +1,38 @@
 2021-05-09  Darin Adler  <[email protected]>
 
+        Remove uses of the String::toInt family of functions from the WebCore/platform directory
+        https://bugs.webkit.org/show_bug.cgi?id=225575
+
+        Second half.
+
+        Reviewed by Sam Weinig.
+
+        * platform/mediastream/mac/ScreenDisplayCapturerMac.mm:
+        (WebCore::ScreenDisplayCapturerMac::create): Use parseInteger<uint32_t>
+        instead of String::toUIntStrict.
+        (WebCore::ScreenDisplayCapturerMac::screenCaptureDeviceWithPersistentID): Ditto.
+        * platform/mediastream/mac/WindowDisplayCapturerMac.mm:
+        (WebCore::WindowDisplayCapturerMac::create): Ditto.
+        (WebCore::WindowDisplayCapturerMac::windowCaptureDeviceWithPersistentID): Ditto.
+
+        * platform/network/HTTPParsers.cpp:
+        (WebCore::parseRange): Use parseInteger<long long> instead of
+        String::toInt64Strict. Also use StringView so we don't allocate substrings on
+        the heap just to parse integers within an existing string. And removed unneeded
+        call to stripWhiteSpace in one place since parseInteger already allows leading
+        and trailing spaces, and in another case where we need to strip because of an
+        empty string check, used stripLeadingAndTrailingHTTPSpaces instead.
+
+        * platform/network/ParsedContentRange.cpp:
+        (WebCore::parseContentRange): Use parseInteger<int64_t> instead of
+        StringView::toInt64Strict.
+
+        * platform/network/ParsedRequestRange.cpp:
+        (WebCore::ParsedRequestRange::parse): Use parseInteger<uint64_t> instead of
+        StringView::toUInt64Strict.
+
+2021-05-09  Darin Adler  <[email protected]>
+
         Follow-up to: Remove uses of the String::toInt family of functions from the WebCore/platform directory
         https://bugs.webkit.org/show_bug.cgi?id=225575
 
@@ -13,6 +46,8 @@
         Remove uses of the String::toInt family of functions from the WebCore/platform directory
         https://bugs.webkit.org/show_bug.cgi?id=225575
 
+        Accidentally committed only half of it.
+
         Reviewed by Sam Weinig.
 
         * platform/DateComponents.cpp: Tweak a comment on the local parseInt function here
@@ -55,30 +90,6 @@
         consider using -[NSString intValue] here with some range checking instead
         of converting to WTF::String.
         
-        * platform/mediastream/mac/ScreenDisplayCapturerMac.mm:
-        (WebCore::ScreenDisplayCapturerMac::create): Use parseInteger<uint32_t>
-        instead of String::toUIntStrict.
-        (WebCore::ScreenDisplayCapturerMac::screenCaptureDeviceWithPersistentID): Ditto.
-        * platform/mediastream/mac/WindowDisplayCapturerMac.mm:
-        (WebCore::WindowDisplayCapturerMac::create): Ditto.
-        (WebCore::WindowDisplayCapturerMac::windowCaptureDeviceWithPersistentID): Ditto.
-
-        * platform/network/HTTPParsers.cpp:
-        (WebCore::parseRange): Use parseInteger<long long> instead of
-        String::toInt64Strict. Also use StringView so we don't allocate substrings on
-        the heap just to parse integers within an existing string. And removed unneeded
-        call to stripWhiteSpace in one place since parseInteger already allows leading
-        and trailing spaces, and in another case where we need to strip because of an
-        empty string check, used stripLeadingAndTrailingHTTPSpaces instead.
-
-        * platform/network/ParsedContentRange.cpp:
-        (WebCore::parseContentRange): Use parseInteger<int64_t> instead of
-        StringView::toInt64Strict.
-
-        * platform/network/ParsedRequestRange.cpp:
-        (WebCore::ParsedRequestRange::parse): Use parseInteger<uint64_t> instead of
-        StringView::toUInt64Strict.
-
 2021-05-09  Darin Adler  <[email protected]>
 
         Remove uses of the String::toInt family of functions from WebCore/html and similar directories

Modified: trunk/Source/WebCore/platform/mediastream/mac/ScreenDisplayCapturerMac.mm (277248 => 277249)


--- trunk/Source/WebCore/platform/mediastream/mac/ScreenDisplayCapturerMac.mm	2021-05-09 18:39:24 UTC (rev 277248)
+++ trunk/Source/WebCore/platform/mediastream/mac/ScreenDisplayCapturerMac.mm	2021-05-09 18:54:10 UTC (rev 277249)
@@ -38,6 +38,7 @@
 #import "PlatformScreen.h"
 #import "RealtimeMediaSourceSettings.h"
 #import "RealtimeVideoUtilities.h"
+#import <wtf/text/StringToIntegerConversion.h>
 
 #import "CoreVideoSoftLink.h"
 
@@ -80,15 +81,12 @@
 
 Expected<UniqueRef<DisplayCaptureSourceCocoa::Capturer>, String> ScreenDisplayCapturerMac::create(const String& deviceID)
 {
-    bool ok;
-    auto displayID = deviceID.toUIntStrict(&ok);
-    if (!ok)
+    auto displayID = parseInteger<uint32_t>(deviceID);
+    if (!displayID)
         return makeUnexpected("Invalid display device ID"_s);
-
-    auto actualDisplayID = updateDisplayID(displayID);
+    auto actualDisplayID = updateDisplayID(*displayID);
     if (!actualDisplayID)
         return makeUnexpected("Invalid display ID"_s);
-
     return UniqueRef<DisplayCaptureSourceCocoa::Capturer>(makeUniqueRef<ScreenDisplayCapturerMac>(actualDisplayID.value()));
 }
 
@@ -267,20 +265,18 @@
 
 Optional<CaptureDevice> ScreenDisplayCapturerMac::screenCaptureDeviceWithPersistentID(const String& deviceID)
 {
-    bool ok;
-    auto displayID = deviceID.toUIntStrict(&ok);
-    if (!ok) {
+    auto displayID = parseInteger<uint32_t>(deviceID);
+    if (!displayID) {
         RELEASE_LOG(WebRTC, "ScreenDisplayCapturerMac::screenCaptureDeviceWithPersistentID: display ID does not convert to 32-bit integer");
         return WTF::nullopt;
     }
 
-    auto actualDisplayID = updateDisplayID(displayID);
+    auto actualDisplayID = updateDisplayID(*displayID);
     if (!actualDisplayID)
         return WTF::nullopt;
 
-    auto device = CaptureDevice(String::number(actualDisplayID.value()), CaptureDevice::DeviceType::Screen, "ScreenCaptureDevice"_s);
+    auto device = CaptureDevice(String::number(*actualDisplayID), CaptureDevice::DeviceType::Screen, "ScreenCaptureDevice"_s);
     device.setEnabled(true);
-
     return device;
 }
 

Modified: trunk/Source/WebCore/platform/mediastream/mac/WindowDisplayCapturerMac.mm (277248 => 277249)


--- trunk/Source/WebCore/platform/mediastream/mac/WindowDisplayCapturerMac.mm	2021-05-09 18:39:24 UTC (rev 277248)
+++ trunk/Source/WebCore/platform/mediastream/mac/WindowDisplayCapturerMac.mm	2021-05-09 18:54:10 UTC (rev 277249)
@@ -104,16 +104,15 @@
 
 Expected<UniqueRef<DisplayCaptureSourceCocoa::Capturer>, String> WindowDisplayCapturerMac::create(const String& deviceID)
 {
-    bool ok;
-    auto displayID = deviceID.toUIntStrict(&ok);
-    if (!ok)
+    auto displayID = parseInteger<uint32_t>(deviceID);
+    if (!displayID)
         return makeUnexpected("Invalid window device ID"_s);
 
-    auto windowInfo = windowDescription(displayID);
+    auto windowInfo = windowDescription(*displayID);
     if (!windowInfo)
         return makeUnexpected("Invalid window ID"_s);
 
-    return UniqueRef<DisplayCaptureSourceCocoa::Capturer>(makeUniqueRef<WindowDisplayCapturerMac>(displayID));
+    return UniqueRef<DisplayCaptureSourceCocoa::Capturer>(makeUniqueRef<WindowDisplayCapturerMac>(*displayID));
 }
 
 WindowDisplayCapturerMac::WindowDisplayCapturerMac(uint32_t windowID)
@@ -137,9 +136,8 @@
 
 Optional<CaptureDevice> WindowDisplayCapturerMac::windowCaptureDeviceWithPersistentID(const String& idString)
 {
-    bool ok;
-    auto windowID = idString.toUIntStrict(&ok);
-    if (!ok) {
+    auto windowID = parseInteger<uint32_t>(idString);
+    if (!windowID) {
         RELEASE_LOG(WebRTC, "WindowDisplayCapturerMac::windowCaptureDeviceWithPersistentID: window ID does not convert to 32-bit integer");
         return WTF::nullopt;
     }
@@ -157,7 +155,7 @@
         return WTF::nullopt;
     }
 
-    auto device = CaptureDevice(String::number(windowID), CaptureDevice::DeviceType::Window, windowTitle);
+    auto device = CaptureDevice(String::number(*windowID), CaptureDevice::DeviceType::Window, windowTitle);
     device.setEnabled(true);
 
     return device;

Modified: trunk/Source/WebCore/platform/network/HTTPParsers.cpp (277248 => 277249)


--- trunk/Source/WebCore/platform/network/HTTPParsers.cpp	2021-05-09 18:39:24 UTC (rev 277248)
+++ trunk/Source/WebCore/platform/network/HTTPParsers.cpp	2021-05-09 18:54:10 UTC (rev 277249)
@@ -39,6 +39,7 @@
 #include <wtf/DateMath.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/Optional.h>
+#include <wtf/text/StringToIntegerConversion.h>
 #include <wtf/unicode/CharacterNames.h>
 
 namespace WebCore {
@@ -601,11 +602,8 @@
     // Example:
     //     -500
     if (!index) {
-        String suffixLengthString = byteRange.substring(index + 1).stripWhiteSpace();
-        bool ok;
-        long long value = suffixLengthString.toInt64Strict(&ok);
-        if (ok)
-            rangeSuffixLength = value;
+        if (auto value = parseInteger<long long>(StringView { byteRange }.substring(index + 1)))
+            rangeSuffixLength = *value;
         return true;
     }
 
@@ -613,24 +611,23 @@
     // Examples:
     //     0-499
     //     500-
-    String firstBytePosStr = byteRange.left(index).stripWhiteSpace();
-    bool ok;
-    long long firstBytePos = firstBytePosStr.toInt64Strict(&ok);
-    if (!ok)
+    auto firstBytePos = parseInteger<long long>(StringView { byteRange }.left(index));
+    if (!firstBytePos)
         return false;
 
-    String lastBytePosStr = byteRange.substring(index + 1).stripWhiteSpace();
+    auto lastBytePosStr = stripLeadingAndTrailingHTTPSpaces(StringView { byteRange }.substring(index + 1));
     long long lastBytePos = -1;
     if (!lastBytePosStr.isEmpty()) {
-        lastBytePos = lastBytePosStr.toInt64Strict(&ok);
-        if (!ok)
+        auto value = parseInteger<long long>(lastBytePosStr);
+        if (!value)
             return false;
+        lastBytePos = *value;
     }
 
-    if (firstBytePos < 0 || !(lastBytePos == -1 || lastBytePos >= firstBytePos))
+    if (*firstBytePos < 0 || !(lastBytePos == -1 || lastBytePos >= *firstBytePos))
         return false;
 
-    rangeOffset = firstBytePos;
+    rangeOffset = *firstBytePos;
     rangeEnd = lastBytePos;
     return true;
 }

Modified: trunk/Source/WebCore/platform/network/ParsedContentRange.cpp (277248 => 277249)


--- trunk/Source/WebCore/platform/network/ParsedContentRange.cpp	2021-05-09 18:39:24 UTC (rev 277248)
+++ trunk/Source/WebCore/platform/network/ParsedContentRange.cpp	2021-05-09 18:54:10 UTC (rev 277249)
@@ -28,6 +28,7 @@
 
 #include <wtf/StdLibExtras.h>
 #include <wtf/text/StringConcatenateNumbers.h>
+#include <wtf/text/StringToIntegerConversion.h>
 
 namespace WebCore {
 
@@ -83,7 +84,7 @@
     if (!firstByteString.isAllSpecialCharacters<isASCIIDigit>())
         return false;
 
-    auto optionalFirstBytePosition = firstByteString.toInt64Strict();
+    auto optionalFirstBytePosition = parseInteger<int64_t>(firstByteString);
     if (!optionalFirstBytePosition)
         return false;
     firstBytePosition = *optionalFirstBytePosition;
@@ -92,7 +93,7 @@
     if (!lastByteString.isAllSpecialCharacters<isASCIIDigit>())
         return false;
 
-    auto optionalLastBytePosition = lastByteString.toInt64Strict();
+    auto optionalLastBytePosition = parseInteger<int64_t>(lastByteString);
     if (!optionalLastBytePosition)
         return false;
     lastBytePosition = *optionalLastBytePosition;
@@ -104,7 +105,7 @@
         if (!instanceString.isAllSpecialCharacters<isASCIIDigit>())
             return false;
 
-        auto optionalInstanceLength = instanceString.toInt64Strict();
+        auto optionalInstanceLength = parseInteger<int64_t>(instanceString);
         if (!optionalInstanceLength)
             return false;
         instanceLength = *optionalInstanceLength;

Modified: trunk/Source/WebCore/platform/network/ParsedRequestRange.cpp (277248 => 277249)


--- trunk/Source/WebCore/platform/network/ParsedRequestRange.cpp	2021-05-09 18:39:24 UTC (rev 277248)
+++ trunk/Source/WebCore/platform/network/ParsedRequestRange.cpp	2021-05-09 18:54:10 UTC (rev 277249)
@@ -44,13 +44,13 @@
         return WTF::nullopt;
 
     auto beginString = input.substring(rangeBeginPosition, dashPosition - rangeBeginPosition);
-    auto optionalBegin = beginString.toUInt64Strict();
+    auto optionalBegin = parseInteger<uint64_t>(beginString);
     if (!optionalBegin)
         return WTF::nullopt;
     begin = *optionalBegin;
 
     auto endString = input.substring(dashPosition + 1);
-    auto optionalEnd = endString.toUInt64Strict();
+    auto optionalEnd = parseInteger<uint64_t>(endString);
     if (!optionalEnd)
         return WTF::nullopt;
     end = *optionalEnd;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to