From 902ccb3d65db97ad4f8d17279806b0290d7ca332 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Tue, 16 Feb 2021 08:50:37 +0200 Subject: Search engine queries via the navbar Any text that doesn't look like a URL is passed onto the configured search URL as a query string. IssueID #157 --- src/gmutil.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/gmutil.c') diff --git a/src/gmutil.c b/src/gmutil.c index 0e0cccc5..32bf356f 100644 --- a/src/gmutil.c +++ b/src/gmutil.c @@ -272,6 +272,21 @@ const iString *absoluteUrl_String(const iString *d, const iString *urlMaybeRelat return absolute; } +iBool isLikelyUrl_String(const iString *d) { + /* Guess whether a human intends the string to be an URL. This is supposed to be fuzzy; + not completely per-spec: a) begins with a scheme; b) has something that looks like a + hostname */ + iRegExp *pattern = new_RegExp("^([a-z]+:)?//.*|" + "^(//)?([^/?#: ]+)([/?#:].*)$|" + "^(\\w+(\\.\\w+)+|localhost)$", + caseInsensitive_RegExpOption); + iRegExpMatch m; + init_RegExpMatch(&m); + const iBool likelyUrl = matchString_RegExp(pattern, d, &m); + iRelease(pattern); + return likelyUrl; +} + static iBool equalPuny_(const iString *d, iRangecc orig) { if (!endsWith_String(d, "-")) { return iFalse; /* This is a sufficient condition? */ -- cgit v1.2.3