aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2020-10-10 10:41:51 +0200
committerMarc André Tanner <mat@brain-dump.org>2020-10-10 10:47:58 +0200
commit70a8f737d4335f7c76c248febc9ad66abc394044 (patch)
tree8d4e437e6990e9f16e7bb1dc1c62bbc36fbd3eb7
parentfc85c33601ccfc4acaa571148b4e974686783f86 (diff)
downloadvis-70a8f737d4335f7c76c248febc9ad66abc394044.tar.gz
vis-70a8f737d4335f7c76c248febc9ad66abc394044.tar.xz
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.
-rw-r--r--text.c8
-rw-r--r--text.h1
2 files changed, 7 insertions, 2 deletions
diff --git a/text.c b/text.c
index 38bec1a..6d93334 100644
--- 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
index 3bdb311..37e667b 100644
--- 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*);