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/bookmarks.c | |
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/bookmarks.c')
-rw-r--r-- | src/bookmarks.c | 35 |
1 files changed, 17 insertions, 18 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 | } |