From 53ef4487f58f706f363f7db37e5a894dd98e23e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 2 Aug 2014 14:16:18 +0200 Subject: Further improve iterator API - iterator_get now returns the correct piece - add utf8 aware methods to move by a character in either direction --- editor.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'editor.h') diff --git a/editor.h b/editor.h index 9a109b2..e8d5a44 100644 --- a/editor.h +++ b/editor.h @@ -4,10 +4,11 @@ typedef struct Editor Editor; typedef struct Piece Piece; typedef struct { - const char const *start; - const char const *end; - const char const *text; - const Piece const *piece; + const char const *start; /* begin of piece's data */ + const char const *end; /* pointer to the first byte after valid data i.e. [start, end) */ + const char const *text; /* current position within piece: start <= text < end */ + const Piece const *piece; /* internal state do not touch! */ + size_t pos; /* global position in bytes from start of file */ } Iterator; #define editor_iterate(ed, it, pos) \ @@ -26,14 +27,18 @@ bool editor_undo(Editor*); bool editor_redo(Editor*); size_t editor_bytes_get(Editor*, size_t pos, size_t len, char *buf); -bool editor_iterator_valid(const Iterator*); + Iterator editor_iterator_get(Editor*, size_t pos); +bool editor_iterator_valid(const Iterator*); bool editor_iterator_next(Iterator*); bool editor_iterator_prev(Iterator*); -Iterator editor_iterator_byte_get(Editor*, size_t pos, char *byte); + +bool editor_iterator_byte_get(Iterator *it, char *b); bool editor_iterator_byte_next(Iterator*, char *b); bool editor_iterator_byte_prev(Iterator*, char *b); -bool editor_iterator_byte_peek(Iterator *it, char *b); + +bool editor_iterator_char_next(Iterator *it, char *c); +bool editor_iterator_char_prev(Iterator *it, char *c); size_t editor_size(Editor*); bool editor_modified(Editor*); -- cgit v1.2.3