vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 92dabbb4e74f6c149df7380805194f41d924fd03
parent ad308ec4f0070768b1f5ac184b078f979619ff0e
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sat, 10 Oct 2020 10:41:51 +0200

text: provide public text_iterator_init

It can be used to initialize a (stack allocated) Iterator structure,
avoiding the copying of the return value as done by text_iterator_get
which depending on the implementation might be problematic.

Diffstat:
Mtext.c | 8++++++--
Mtext.h | 1+
2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/text.c b/text.c @@ -1403,10 +1403,14 @@ static bool iterator_init(Iterator *it, size_t pos, Piece *p, size_t off) { return text_iterator_valid(it); } +bool text_iterator_init(const Text *txt, Iterator *it, size_t pos) { + Location loc = piece_get_extern(txt, pos); + return iterator_init(it, pos, loc.piece, loc.off); +} + Iterator text_iterator_get(const Text *txt, size_t pos) { Iterator it; - Location loc = piece_get_extern(txt, pos); - iterator_init(&it, pos, loc.piece, loc.off); + text_iterator_init(txt, &it, pos); return it; } diff --git a/text.h b/text.h @@ -250,6 +250,7 @@ char *text_bytes_alloc0(const Text*, size_t pos, size_t len); * @{ */ Iterator text_iterator_get(const Text*, size_t pos); +bool text_iterator_init(const Text*, Iterator*, size_t pos); const Text *text_iterator_text(const Iterator*); bool text_iterator_valid(const Iterator*); bool text_iterator_has_next(const Iterator*);