diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2014-08-02 14:16:18 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2014-08-02 14:16:18 +0200 |
| commit | 53ef4487f58f706f363f7db37e5a894dd98e23e6 (patch) | |
| tree | fc8c6bd6d2140155fc717a5a38e64671f3c4ed21 /editor.h | |
| parent | 62ec1d8570f14aae1640c009dfe2ecfcc75ead11 (diff) | |
| download | vis-53ef4487f58f706f363f7db37e5a894dd98e23e6.tar.gz vis-53ef4487f58f706f363f7db37e5a894dd98e23e6.tar.xz | |
Further improve iterator API
- iterator_get now returns the correct piece
- add utf8 aware methods to move by a character in either direction
Diffstat (limited to 'editor.h')
| -rw-r--r-- | editor.h | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -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*); |
