diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-02-24 04:41:15 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-02-24 04:41:15 +0200 |
commit | 7284c9339449a5f022c4ba3adf40335447cb5007 (patch) | |
tree | 149ef634bb8827cd2b826de987b40587564ad54e /src | |
parent | 884149c9caceda88cf2182e381cf283d966e34d5 (diff) |
Bookmarks: Looking up site icons
Bookmark icons apply to site roots instead of domains. A root includes the user directory if one is found in the URL.
Diffstat (limited to 'src')
-rw-r--r-- | src/bookmarks.c | 35 | ||||
-rw-r--r-- | src/gmutil.c | 26 | ||||
-rw-r--r-- | src/gmutil.h | 1 |
3 files changed, 39 insertions, 23 deletions
diff --git a/src/bookmarks.c b/src/bookmarks.c index 60048d36..91280f3c 100644 --- a/src/bookmarks.c +++ b/src/bookmarks.c | |||
@@ -254,27 +254,26 @@ iChar siteIcon_Bookmarks(const iBookmarks *d, const iString *url) { | |||
254 | if (isEmpty_String(url)) { | 254 | if (isEmpty_String(url)) { |
255 | return 0; | 255 | return 0; |
256 | } | 256 | } |
257 | iChar icon = 0; | 257 | static iRegExp *tagPattern_; |
258 | iRangecc hostName = urlHost_String(url); | 258 | if (!tagPattern_) { |
259 | const size_t hostSize = size_Range(&hostName); | 259 | tagPattern_ = new_RegExp("\\busericon\\b", caseSensitive_RegExpOption); |
260 | size_t matchingSize = iInvalidSize; /* we'll pick the shortest matching */ | 260 | } |
261 | const iRangecc urlRoot = urlRoot_String(url); | ||
262 | size_t matchingSize = iInvalidSize; /* we'll pick the shortest matching */ | ||
263 | iChar icon = 0; | ||
261 | lock_Mutex(d->mtx); | 264 | lock_Mutex(d->mtx); |
262 | iConstForEach(Hash, i, &d->bookmarks) { | 265 | iConstForEach(Hash, i, &d->bookmarks) { |
263 | const iBookmark *bm = (const iBookmark *) i.value; | 266 | const iBookmark *bm = (const iBookmark *) i.value; |
264 | iUrl parts; | 267 | iRegExpMatch m; |
265 | init_Url(&parts, &bm->url); | 268 | init_RegExpMatch(&m); |
266 | if (!hasTag_Bookmark(bm, "usericon")) { /* TODO: Inefficient! RegExp rebuilt every time. */ | 269 | if (bm->icon && matchString_RegExp(tagPattern_, &bm->tags, &m)) { |
267 | continue; | 270 | const iRangecc bmRoot = urlRoot_String(&bm->url); |
268 | } | 271 | if (equalRangeCase_Rangecc(urlRoot, bmRoot)) { |
269 | if (size_Range(&hostName) == size_Range(&parts.host) && | 272 | const size_t n = size_String(&bm->url); |
270 | iCmpStrNCase(hostName.start, parts.host.start, hostSize) == 0) { | 273 | if (n < matchingSize) { |
271 | const size_t n = size_String(&bm->url); | 274 | matchingSize = n; |
272 | if (n > size_String(url)) { | 275 | icon = bm->icon; |
273 | continue; /* Bookmark must be higher up in the path tree. */ | 276 | } |
274 | } | ||
275 | if (n < matchingSize && bm->icon) { | ||
276 | matchingSize = n; | ||
277 | icon = bm->icon; | ||
278 | } | 277 | } |
279 | } | 278 | } |
280 | } | 279 | } |
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 | } |
diff --git a/src/gmutil.h b/src/gmutil.h index de8c1e65..b2cee61a 100644 --- a/src/gmutil.h +++ b/src/gmutil.h | |||
@@ -104,6 +104,7 @@ void init_Url (iUrl *, const iString *text); | |||
104 | iRangecc urlScheme_String (const iString *); | 104 | iRangecc urlScheme_String (const iString *); |
105 | iRangecc urlHost_String (const iString *); | 105 | iRangecc urlHost_String (const iString *); |
106 | iRangecc urlUser_String (const iString *); | 106 | iRangecc urlUser_String (const iString *); |
107 | iRangecc urlRoot_String (const iString *); | ||
107 | const iString * absoluteUrl_String (const iString *, const iString *urlMaybeRelative); | 108 | const iString * absoluteUrl_String (const iString *, const iString *urlMaybeRelative); |
108 | iBool isLikelyUrl_String (const iString *); | 109 | iBool isLikelyUrl_String (const iString *); |
109 | void punyEncodeUrlHost_String(iString *); | 110 | void punyEncodeUrlHost_String(iString *); |