From e7b6ac1574ba4dad280e6a45beb52dac4e3ea2e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Mon, 8 Sep 2014 17:27:25 +0200 Subject: Hook up search as a movement --- text-motions.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'text-motions.c') diff --git a/text-motions.c b/text-motions.c index fc87950..7696ff0 100644 --- a/text-motions.c +++ b/text-motions.c @@ -296,3 +296,33 @@ size_t text_bracket_match(Text *txt, size_t pos) { return pos; /* no match found */ } + +size_t text_search_forward(Text *txt, size_t pos, Regex *regex) { + int start = pos + 1; + int end = text_size(txt); + RegexMatch match[1]; + bool found = !text_search_range_forward(txt, start, end - start, regex, 1, match, 0); + + if (!found) { + start = 0; + end = pos; + found = !text_search_range_forward(txt, start, end, regex, 1, match, 0); + } + + return found ? match[0].start : pos; +} + +size_t text_search_backward(Text *txt, size_t pos, Regex *regex) { + int start = 0; + int end = pos; + RegexMatch match[1]; + bool found = !text_search_range_backward(txt, start, end, regex, 1, match, 0); + + if (!found) { + start = pos + 1; + end = text_size(txt); + found = !text_search_range_backward(txt, start, end - start, regex, 1, match, 0); + } + + return found ? match[0].start : pos; +} -- cgit v1.2.3