summaryrefslogtreecommitdiff
path: root/src/history.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-09-07 14:50:09 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-09-07 14:50:09 +0300
commitc7b55f3d2ead592e110a1a1fb219bcb5a9009b37 (patch)
tree21343a5c465fcb8b179dd8350c4452a443684a24 /src/history.c
parent7c9dfee6ecde3daf6ccf7fc26eb2b1438ac94157 (diff)
LookupWidget: Working on history content search
Diffstat (limited to 'src/history.c')
-rw-r--r--src/history.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/src/history.c b/src/history.c
index 63fa1104..57e556f7 100644
--- a/src/history.c
+++ b/src/history.c
@@ -67,8 +67,10 @@ void init_History(iHistory *d) {
67} 67}
68 68
69void deinit_History(iHistory *d) { 69void deinit_History(iHistory *d) {
70 clear_History(d); 70 iGuardMutex(d->mtx, {
71 deinit_Array(&d->recent); 71 clear_History(d);
72 deinit_Array(&d->recent);
73 });
72 delete_Mutex(d->mtx); 74 delete_Mutex(d->mtx);
73} 75}
74 76
@@ -249,3 +251,39 @@ void setCachedResponse_History(iHistory *d, const iGmResponse *response) {
249 } 251 }
250 unlock_Mutex(d->mtx); 252 unlock_Mutex(d->mtx);
251} 253}
254
255const iStringArray *searchContents_History(const iHistory *d, const iRegExp *pattern) {
256 iStringArray *urls = iClob(new_StringArray());
257 lock_Mutex(d->mtx);
258 iConstForEach(Array, i, &d->recent) {
259 const iRecentUrl *url = i.value;
260 const iGmResponse *resp = url->cachedResponse;
261 if (resp && category_GmStatusCode(resp->statusCode) == categorySuccess_GmStatusCode) {
262 if (indexOfCStrSc_String(&resp->meta, "text/", &iCaseInsensitive) == iInvalidPos) {
263 continue;
264 }
265 iRegExpMatch m;
266 init_RegExpMatch(&m);
267 if (matchRange_RegExp(pattern, range_Block(&resp->body), &m)) {
268 iString entry;
269 init_String(&entry);
270 iRangei cap = m.range;
271 cap.start = iMax(cap.start - 4, 0);
272 cap.end = iMin(cap.end + 10, (int) size_Block(&resp->body));
273 iString content;
274 initRange_String(&content, (iRangecc){ m.subject + cap.start, m.subject + cap.end });
275 /* This needs cleaning up; highlight the matched word. */ {
276
277 }
278 format_String(&entry, "match len:%zu str:%s", size_String(&content), cstr_String(&content));
279 deinit_String(&content);
280 //appendRange_String(&entry, );
281 appendFormat_String(&entry, " url:%s", cstr_String(&url->url));
282 pushBack_StringArray(urls, &entry);
283 deinit_String(&entry);
284 }
285 }
286 }
287 unlock_Mutex(d->mtx);
288 return urls;
289}