Title: [130695] trunk/Source/WTF
Revision
130695
Author
[email protected]
Date
2012-10-08 15:31:45 -0700 (Mon, 08 Oct 2012)

Log Message

Generalize moving URLComponent's begin position
https://bugs.webkit.org/show_bug.cgi?id=98626

Reviewed by Adam Barth.

The patch r130609 introduced moving URLComponents's position.
It turns out this concept is really useful in the parser so
this patch generalize the idea.

* wtf/url/api/ParsedURL.cpp:
(WTF::ParsedURL::removePort):
* wtf/url/src/URLCanonEtc.cpp:
* wtf/url/src/URLComponent.h:
(WTF::URLComponent::moveBy):
Rename URLComponent::move() to URLComponent::moveBy() for consistency
with some of WebCore types.

* wtf/url/src/URLParse.cpp:
* wtf/url/src/URLParseFile.cpp:

* wtf/url/src/URLSegments.cpp:
(WTF::URLSegments::moveFromComponentBy):
Change the semantic to everything from a certain component. This is
useful to move everything, including the scheme.

* wtf/url/src/URLSegments.h:
(URLSegments):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (130694 => 130695)


--- trunk/Source/WTF/ChangeLog	2012-10-08 22:30:22 UTC (rev 130694)
+++ trunk/Source/WTF/ChangeLog	2012-10-08 22:31:45 UTC (rev 130695)
@@ -1,3 +1,33 @@
+2012-10-08  Benjamin Poulain  <[email protected]>
+
+        Generalize moving URLComponent's begin position
+        https://bugs.webkit.org/show_bug.cgi?id=98626
+
+        Reviewed by Adam Barth.
+
+        The patch r130609 introduced moving URLComponents's position.
+        It turns out this concept is really useful in the parser so
+        this patch generalize the idea.
+
+        * wtf/url/api/ParsedURL.cpp:
+        (WTF::ParsedURL::removePort):
+        * wtf/url/src/URLCanonEtc.cpp:
+        * wtf/url/src/URLComponent.h:
+        (WTF::URLComponent::moveBy):
+        Rename URLComponent::move() to URLComponent::moveBy() for consistency
+        with some of WebCore types.
+
+        * wtf/url/src/URLParse.cpp:
+        * wtf/url/src/URLParseFile.cpp:
+
+        * wtf/url/src/URLSegments.cpp:
+        (WTF::URLSegments::moveFromComponentBy):
+        Change the semantic to everything from a certain component. This is
+        useful to move everything, including the scheme.
+
+        * wtf/url/src/URLSegments.h:
+        (URLSegments):
+
 2012-10-08  Andreas Kling  <[email protected]>
 
         Lower minimum table size of WTF::HashTable to reduce memory usage.

Modified: trunk/Source/WTF/wtf/url/api/ParsedURL.cpp (130694 => 130695)


--- trunk/Source/WTF/wtf/url/api/ParsedURL.cpp	2012-10-08 22:30:22 UTC (rev 130694)
+++ trunk/Source/WTF/wtf/url/api/ParsedURL.cpp	2012-10-08 22:31:45 UTC (rev 130695)
@@ -187,7 +187,7 @@
 
     // 2) Update the components positions.
     m_segments.port.reset();
-    m_segments.moveComponentsAfter(URLSegments::Port, -length);
+    m_segments.moveFromComponentBy(URLSegments::Path, -length);
 }
 
 String ParsedURL::path() const

Modified: trunk/Source/WTF/wtf/url/src/URLCanonEtc.cpp (130694 => 130695)


--- trunk/Source/WTF/wtf/url/src/URLCanonEtc.cpp	2012-10-08 22:30:22 UTC (rev 130694)
+++ trunk/Source/WTF/wtf/url/src/URLCanonEtc.cpp	2012-10-08 22:31:45 UTC (rev 130695)
@@ -124,7 +124,7 @@
     }
 
     // The output scheme starts from the current position.
-    outputScheme.setBegin(outputScheme.begin() + output.length());
+    outputScheme.moveBy(output.length());
 
     // Danger: it's important that this code does not strip any characters: it
     // only emits the canonical version (be it valid or escaped) of each of

Modified: trunk/Source/WTF/wtf/url/src/URLComponent.h (130694 => 130695)


--- trunk/Source/WTF/wtf/url/src/URLComponent.h	2012-10-08 22:30:22 UTC (rev 130694)
+++ trunk/Source/WTF/wtf/url/src/URLComponent.h	2012-10-08 22:31:45 UTC (rev 130695)
@@ -65,7 +65,7 @@
 
     int begin() const { return m_begin; }
     void setBegin(int begin) { m_begin = begin; }
-    void move(int offset) { m_begin += offset; }
+    void moveBy(int offset) { m_begin += offset; }
 
     int length() const { return m_length; }
     void setLength(int length) { m_length = length; }

Modified: trunk/Source/WTF/wtf/url/src/URLParse.cpp (130694 => 130695)


--- trunk/Source/WTF/wtf/url/src/URLParse.cpp	2012-10-08 22:30:22 UTC (rev 130694)
+++ trunk/Source/WTF/wtf/url/src/URLParse.cpp	2012-10-08 22:31:45 UTC (rev 130695)
@@ -350,7 +350,7 @@
     // Extract the scheme. We also handle the case where there is no scheme.
     if (doExtractScheme(&spec[begin], specLength - begin, parsed.scheme)) {
         // Offset the results since we gave ExtractScheme a substring.
-        parsed.scheme.setBegin(parsed.scheme.begin() + begin);
+        parsed.scheme.moveBy(begin);
 
         if (parsed.scheme.end() == specLength - 1)
             return;
@@ -368,7 +368,7 @@
 
     if (doExtractScheme(innerSpec, innerSpecLength, innerScheme)) {
         // Offset the results since we gave ExtractScheme a substring.
-        innerScheme.setBegin(innerScheme.begin() + innerStart);
+        innerScheme.moveBy(innerStart);
 
         if (innerScheme.end() == specLength - 1)
             return;
@@ -395,14 +395,7 @@
     // If we had any scheme that supported nesting more than one level deep,
     // we'd have to recurse into the innerParsed's innerParsed when
     // adjusting by innerStart.
-    innerParsed.scheme.setBegin(innerParsed.scheme.begin() + innerStart);
-    innerParsed.username.setBegin(innerParsed.username.begin() + innerStart);
-    innerParsed.password.setBegin(innerParsed.password.begin() + innerStart);
-    innerParsed.host.setBegin(innerParsed.host.begin() + innerStart);
-    innerParsed.port.setBegin(innerParsed.port.begin() + innerStart);
-    innerParsed.query.setBegin(innerParsed.query.begin() + innerStart);
-    innerParsed.fragment.setBegin(innerParsed.fragment.begin() + innerStart);
-    innerParsed.path.setBegin(innerParsed.path.begin() + innerStart);
+    innerParsed.moveFromComponentBy(URLSegments::Scheme, innerStart);
 
     // Query and ref move from innerParsed to parsed.
     parsed.query = innerParsed.query;
@@ -461,7 +454,7 @@
     // handle the case where there is no scheme.
     if (ExtractScheme(&spec[begin], specLength - begin, &parsed.scheme)) {
         // Offset the results since we gave ExtractScheme a substring.
-        parsed.scheme.setBegin(parsed.scheme.begin() + begin);
+        parsed.scheme.moveBy(begin);
 
         // For compatability with the standard URL parser, we treat no path as
         // -1, rather than having a length of 0 (we normally wouldn't care so
@@ -509,7 +502,7 @@
     // handle the case where there is no scheme.
     if (ExtractScheme(&spec[begin], specLength - begin, &parsed.scheme)) {
         // Offset the results since we gave ExtractScheme a substring.
-        parsed.scheme.setBegin(parsed.scheme.begin() + begin);
+        parsed.scheme.moveBy(begin);
 
         if (parsed.scheme.end() != specLength - 1) {
             pathBegin = parsed.scheme.end() + 1;

Modified: trunk/Source/WTF/wtf/url/src/URLParseFile.cpp (130694 => 130695)


--- trunk/Source/WTF/wtf/url/src/URLParseFile.cpp	2012-10-08 22:30:22 UTC (rev 130694)
+++ trunk/Source/WTF/wtf/url/src/URLParseFile.cpp	2012-10-08 22:31:45 UTC (rev 130695)
@@ -183,7 +183,7 @@
     {
         if (ExtractScheme(&spec[begin], specLength - begin, &parsed.scheme)) {
             // Offset the results since we gave ExtractScheme a substring.
-            parsed.scheme.setBegin(parsed.scheme.begin() + begin);
+            parsed.scheme.moveBy(begin);
             afterScheme = parsed.scheme.end() + 1;
         } else {
             // No scheme found, remember that.

Modified: trunk/Source/WTF/wtf/url/src/URLSegments.cpp (130694 => 130695)


--- trunk/Source/WTF/wtf/url/src/URLSegments.cpp	2012-10-08 22:30:22 UTC (rev 130694)
+++ trunk/Source/WTF/wtf/url/src/URLSegments.cpp	2012-10-08 22:31:45 UTC (rev 130695)
@@ -110,26 +110,26 @@
     return current;
 }
 
-void URLSegments::moveComponentsAfter(ComponentType type, int offset)
+void URLSegments::moveFromComponentBy(ComponentType type, int offset)
 {
     switch (type) {
     // Fall through.
     case Scheme:
-        username.move(offset);
+        scheme.moveBy(offset);
     case Username:
-        password.move(offset);
+        username.moveBy(offset);
     case Password:
-        host.move(offset);
+        password.moveBy(offset);
     case Host:
-        port.move(offset);
+        host.moveBy(offset);
     case Port:
-        path.move(offset);
+        port.moveBy(offset);
     case Path:
-        query.move(offset);
+        path.moveBy(offset);
     case Query:
-        fragment.move(offset);
+        query.moveBy(offset);
     case Fragment:
-        break;
+        fragment.moveBy(offset);
     }
 }
 

Modified: trunk/Source/WTF/wtf/url/src/URLSegments.h (130694 => 130695)


--- trunk/Source/WTF/wtf/url/src/URLSegments.h	2012-10-08 22:30:22 UTC (rev 130694)
+++ trunk/Source/WTF/wtf/url/src/URLSegments.h	2012-10-08 22:31:45 UTC (rev 130695)
@@ -121,8 +121,8 @@
     //
     int charactersBefore(ComponentType, DelimiterInclusion) const;
 
-    // Shift all the components after ComponentType by 'offset'.
-    void moveComponentsAfter(ComponentType, int offset);
+    // Shift all the components from 'firstComponent' to the last component by 'offset'.
+    void moveFromComponentBy(ComponentType firstComponent, int offset);
 
     // Each component excludes the related delimiters and has a length of -1
     // if that component is absent but 0 if the component exists but is empty.
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to