From c7b55f3d2ead592e110a1a1fb219bcb5a9009b37 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Mon, 7 Sep 2020 14:50:09 +0300 Subject: LookupWidget: Working on history content search --- src/history.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'src/history.c') 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) { } void deinit_History(iHistory *d) { - clear_History(d); - deinit_Array(&d->recent); + iGuardMutex(d->mtx, { + clear_History(d); + deinit_Array(&d->recent); + }); delete_Mutex(d->mtx); } @@ -249,3 +251,39 @@ void setCachedResponse_History(iHistory *d, const iGmResponse *response) { } unlock_Mutex(d->mtx); } + +const iStringArray *searchContents_History(const iHistory *d, const iRegExp *pattern) { + iStringArray *urls = iClob(new_StringArray()); + lock_Mutex(d->mtx); + iConstForEach(Array, i, &d->recent) { + const iRecentUrl *url = i.value; + const iGmResponse *resp = url->cachedResponse; + if (resp && category_GmStatusCode(resp->statusCode) == categorySuccess_GmStatusCode) { + if (indexOfCStrSc_String(&resp->meta, "text/", &iCaseInsensitive) == iInvalidPos) { + continue; + } + iRegExpMatch m; + init_RegExpMatch(&m); + if (matchRange_RegExp(pattern, range_Block(&resp->body), &m)) { + iString entry; + init_String(&entry); + iRangei cap = m.range; + cap.start = iMax(cap.start - 4, 0); + cap.end = iMin(cap.end + 10, (int) size_Block(&resp->body)); + iString content; + initRange_String(&content, (iRangecc){ m.subject + cap.start, m.subject + cap.end }); + /* This needs cleaning up; highlight the matched word. */ { + + } + format_String(&entry, "match len:%zu str:%s", size_String(&content), cstr_String(&content)); + deinit_String(&content); + //appendRange_String(&entry, ); + appendFormat_String(&entry, " url:%s", cstr_String(&url->url)); + pushBack_StringArray(urls, &entry); + deinit_String(&entry); + } + } + } + unlock_Mutex(d->mtx); + return urls; +} -- cgit v1.2.3