summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gmutil.c50
1 files changed, 19 insertions, 31 deletions
diff --git a/src/gmutil.c b/src/gmutil.c
index 369aaaf1..79268dd4 100644
--- a/src/gmutil.c
+++ b/src/gmutil.c
@@ -35,41 +35,29 @@ void init_Url(iUrl *d, const iString *text) {
35 d->path = (iRangecc){ cstr + 7, constEnd_String(text) }; 35 d->path = (iRangecc){ cstr + 7, constEnd_String(text) };
36 return; 36 return;
37 } 37 }
38 static iRegExp *absoluteUrlPattern_; 38 static iRegExp *urlPattern_;
39 static iRegExp *relativeUrlPattern_; 39 static iRegExp *authPattern_;
40 if (!absoluteUrlPattern_) { 40 if (!urlPattern_) {
41 absoluteUrlPattern_ = new_RegExp("([a-z]+:)?(//[^/:?]*)(:[0-9]+)?([^?]*)(\\?.*)?", 41 urlPattern_ = new_RegExp("^(([^:/?#]+):)?(//([^/?#]*))?"
42 caseInsensitive_RegExpOption); 42 "([^?#]*)(\\?([^#]*))?(#(.*))?",
43 caseInsensitive_RegExpOption);
44 authPattern_ = new_RegExp("([^:]+)(:([0-9]+))?", caseInsensitive_RegExpOption);
43 } 45 }
46 iZap(*d);
44 iRegExpMatch m; 47 iRegExpMatch m;
45 init_RegExpMatch(&m); 48 init_RegExpMatch(&m);
46 if (matchString_RegExp(absoluteUrlPattern_, text, &m)) { 49 if (matchString_RegExp(urlPattern_, text, &m)) {
47 d->scheme = capturedRange_RegExpMatch(&m, 1); 50 d->scheme = capturedRange_RegExpMatch(&m, 2);
48 d->host = capturedRange_RegExpMatch(&m, 2); 51 d->host = capturedRange_RegExpMatch(&m, 4);
49 if (!isEmpty_Range(&d->host)) { 52 d->port = (iRangecc){ d->host.end, d->host.end };
50 d->host.start += 2; /* skip the double slash */ 53 d->path = capturedRange_RegExpMatch(&m, 5);
54 d->query = capturedRange_RegExpMatch(&m, 6);
55 /* Check if the authority contains a port. */
56 init_RegExpMatch(&m);
57 if (matchRange_RegExp(authPattern_, d->host, &m)) {
58 d->host = capturedRange_RegExpMatch(&m, 1);
59 d->port = capturedRange_RegExpMatch(&m, 3);
51 } 60 }
52 d->port = capturedRange_RegExpMatch(&m, 3);
53 if (!isEmpty_Range(&d->port)) {
54 d->port.start++; /* omit the colon */
55 }
56 d->path = capturedRange_RegExpMatch(&m, 4);
57 d->query = capturedRange_RegExpMatch(&m, 5);
58 }
59 else {
60 /* Must be a relative path. */
61 iZap(*d);
62 if (!relativeUrlPattern_) {
63 relativeUrlPattern_ = new_RegExp("([a-z]+:)?([^?]*)(\\?.*)?", 0);
64 }
65 if (matchString_RegExp(relativeUrlPattern_, text, &m)) {
66 d->scheme = capturedRange_RegExpMatch(&m, 1);
67 d->path = capturedRange_RegExpMatch(&m, 2);
68 d->query = capturedRange_RegExpMatch(&m, 3);
69 }
70 }
71 if (!isEmpty_Range(&d->scheme)) {
72 d->scheme.end--; /* omit the colon */
73 } 61 }
74} 62}
75 63