From 5e016233a9fe77258edd85a2dc746d20e6db46a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sun, 26 Jul 2015 11:21:47 +0200 Subject: text-object: add new functions to search for words --- text-objects.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'text-objects.c') diff --git a/text-objects.c b/text-objects.c index 815e36a..b06d680 100644 --- a/text-objects.c +++ b/text-objects.c @@ -13,6 +13,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #include #include "text-motions.h" #include "text-objects.h" @@ -165,6 +166,36 @@ Filerange text_object_word_outer(Text *txt, size_t pos) { return r; } +Filerange text_object_word_find_next(Text *txt, size_t pos, const char *word) { + size_t len = strlen(word); + for (;;) { + size_t match_pos = text_find_next(txt, pos, word); + if (match_pos != pos) { + Filerange match_word = text_object_word(txt, match_pos); + if (text_range_size(&match_word) == len) + return match_word; + pos = match_pos; + } else { + return text_range_empty(); + } + } +} + +Filerange text_object_word_find_prev(Text *txt, size_t pos, const char *word) { + size_t len = strlen(word); + for (;;) { + size_t match_pos = text_find_prev(txt, pos, word); + if (match_pos != pos) { + Filerange match_word = text_object_word(txt, match_pos); + if (text_range_size(&match_word) == len) + return match_word; + pos = match_pos; + } else { + return text_range_empty(); + } + } +} + Filerange text_object_line(Text *txt, size_t pos) { Filerange r; r.start = text_line_begin(txt, pos); -- cgit v1.2.3