aboutsummaryrefslogtreecommitdiff
path: root/vis-motions.c
diff options
context:
space:
mode:
authorChristian Hesse <mail@eworm.de>2025-12-09 17:22:20 +0100
committerChristian Hesse <mail@eworm.de>2025-12-09 17:26:52 +0100
commit560fa2bcaf2debdb5f12555efd5aa30c3b32467b (patch)
treeea12cc3f1e3b8fa5b5fffd3343319a6220cfd410 /vis-motions.c
parent48fbf21a6d6085d561757afb162d9f7b98792bf9 (diff)
downloadvis-560fa2bcaf2debdb5f12555efd5aa30c3b32467b.tar.gz
vis-560fa2bcaf2debdb5f12555efd5aa30c3b32467b.tar.xz
introduce search_common...
... and make search_{forward,backward} wrapper to that function.
Diffstat (limited to 'vis-motions.c')
-rw-r--r--vis-motions.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/vis-motions.c b/vis-motions.c
index 241bf37..5957c7b 100644
--- a/vis-motions.c
+++ b/vis-motions.c
@@ -45,20 +45,22 @@ static size_t search_word_backward(Vis *vis, Text *txt, size_t pos) {
return pos;
}
-static size_t search_forward(Vis *vis, Text *txt, size_t pos) {
+static size_t search_common(Vis *vis, Text *txt, size_t pos, bool backward) {
Regex *regex = vis_regex(vis, NULL);
if (regex)
- pos = text_search_forward(txt, pos, regex);
+ pos = backward ?
+ text_search_backward(txt, pos, regex) :
+ text_search_forward(txt, pos, regex);
text_regex_free(regex);
return pos;
}
+static size_t search_forward(Vis *vis, Text *txt, size_t pos) {
+ return search_common(vis, txt, pos, false);
+}
+
static size_t search_backward(Vis *vis, Text *txt, size_t pos) {
- Regex *regex = vis_regex(vis, NULL);
- if (regex)
- pos = text_search_backward(txt, pos, regex);
- text_regex_free(regex);
- return pos;
+ return search_common(vis, txt, pos, true);
}
static size_t common_word_next(Vis *vis, Text *txt, size_t pos,