Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/url.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-10-03 21:56:42 +0400
committerJunio C Hamano <gitster@pobox.com>2011-10-03 21:56:42 +0400
commitb33a1b9fe794df53b449ffdbba0b39ef9e1772bf (patch)
tree04e58667e769f3539ab05ab9e26d6a615bf7ba6a /url.c
parent7ed863a85a6ce2c4ac4476848310b8f917ab41f9 (diff)
url.c: simplify is_url()
The function was implemented in an overly complicated way. Rewrite it to check from left to right in a single pass. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'url.c')
-rw-r--r--url.c32
1 files changed, 6 insertions, 26 deletions
diff --git a/url.c b/url.c
index 6a5495960f..8d64d902ec 100644
--- a/url.c
+++ b/url.c
@@ -17,35 +17,15 @@ int is_urlschemechar(int first_flag, int ch)
int is_url(const char *url)
{
- const char *url2, *first_slash;
-
- if (!url)
- return 0;
- url2 = url;
- first_slash = strchr(url, '/');
-
- /* Input with no slash at all or slash first can't be URL. */
- if (!first_slash || first_slash == url)
- return 0;
- /* Character before must be : and next must be /. */
- if (first_slash[-1] != ':' || first_slash[1] != '/')
+ /* Is "scheme" part reasonable? */
+ if (!url || !is_urlschemechar(1, *url++))
return 0;
- /* There must be something before the :// */
- if (first_slash == url + 1)
- return 0;
- /*
- * Check all characters up to first slash - 1. Only alphanum
- * is allowed.
- */
- url2 = url;
- while (url2 < first_slash - 1) {
- if (!is_urlschemechar(url2 == url, (unsigned char)*url2))
+ while (*url && *url != ':') {
+ if (!is_urlschemechar(0, *url++))
return 0;
- url2++;
}
-
- /* Valid enough. */
- return 1;
+ /* We've seen "scheme"; we want colon-slash-slash */
+ return (url[0] == ':' && url[1] == '/' && url[2] == '/');
}
static int url_decode_char(const char *q)