diff options
Diffstat (limited to 'src/gmutil.c')
-rw-r--r-- | src/gmutil.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/gmutil.c b/src/gmutil.c index 1edc41ae..2b40367d 100644 --- a/src/gmutil.c +++ b/src/gmutil.c | |||
@@ -153,20 +153,36 @@ iRangecc urlHost_String(const iString *d) { | |||
153 | } | 153 | } |
154 | 154 | ||
155 | iRangecc urlUser_String(const iString *d) { | 155 | iRangecc urlUser_String(const iString *d) { |
156 | iRegExp *userPats[2] = { new_RegExp("~([^/?]+)", 0), | 156 | static iRegExp *userPats_[2]; |
157 | new_RegExp("/users/([^/?]+)", caseInsensitive_RegExpOption) }; | 157 | if (!userPats_[0]) { |
158 | userPats_[0] = new_RegExp("~([^/?]+)", 0); | ||
159 | userPats_[1] = new_RegExp("/users/([^/?]+)", caseInsensitive_RegExpOption); | ||
160 | } | ||
158 | iRegExpMatch m; | 161 | iRegExpMatch m; |
159 | init_RegExpMatch(&m); | 162 | init_RegExpMatch(&m); |
160 | iRangecc found = iNullRange; | 163 | iRangecc found = iNullRange; |
161 | iForIndices(i, userPats) { | 164 | iForIndices(i, userPats_) { |
162 | if (matchString_RegExp(userPats[i], d, &m)) { | 165 | if (matchString_RegExp(userPats_[i], d, &m)) { |
163 | found = capturedRange_RegExpMatch(&m, 1); | 166 | found = capturedRange_RegExpMatch(&m, 1); |
164 | } | 167 | } |
165 | iRelease(userPats[i]); | ||
166 | } | 168 | } |
167 | return found; | 169 | return found; |
168 | } | 170 | } |
169 | 171 | ||
172 | iRangecc urlRoot_String(const iString *d) { | ||
173 | const char *rootEnd; | ||
174 | const iRangecc user = urlUser_String(d); | ||
175 | if (!isEmpty_Range(&user)) { | ||
176 | rootEnd = user.end; | ||
177 | } | ||
178 | else { | ||
179 | iUrl parts; | ||
180 | init_Url(&parts, d); | ||
181 | rootEnd = parts.path.start; | ||
182 | } | ||
183 | return (iRangecc){ constBegin_String(d), rootEnd }; | ||
184 | } | ||
185 | |||
170 | static iBool isAbsolutePath_(iRangecc path) { | 186 | static iBool isAbsolutePath_(iRangecc path) { |
171 | return isAbsolute_Path(collect_String(urlDecode_String(collect_String(newRange_String(path))))); | 187 | return isAbsolute_Path(collect_String(urlDecode_String(collect_String(newRange_String(path))))); |
172 | } | 188 | } |