aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-04-05 12:40:43 +0200
committerMarc André Tanner <mat@brain-dump.org>2017-04-08 22:54:36 +0200
commit391720cb430ad74d01dacb1cd53c06d6283aba4e (patch)
treed7057d702f5196d153fa7f57dfe7a8bf440674f0
parent03ffb2b812022082c681f478da10b095f44dfb97 (diff)
downloadvis-391720cb430ad74d01dacb1cd53c06d6283aba4e.tar.gz
vis-391720cb430ad74d01dacb1cd53c06d6283aba4e.tar.xz
text: introduce text_char_get which converts \r\n to \n
-rw-r--r--text.c5
-rw-r--r--text.h3
2 files changed, 8 insertions, 0 deletions
diff --git a/text.c b/text.c
index 390be98..b994bc4 100644
--- a/text.c
+++ b/text.c
@@ -1548,6 +1548,11 @@ bool text_byte_get(Text *txt, size_t pos, char *buf) {
return text_bytes_get(txt, pos, 1, buf);
}
+bool text_char_get(Text *txt, size_t pos, char *buf) {
+ Iterator it = text_iterator_get(txt, pos);
+ return text_iterator_char_get(&it, buf);
+}
+
size_t text_bytes_get(Text *txt, size_t pos, size_t len, char *buf) {
if (!buf)
return 0;
diff --git a/text.h b/text.h
index 8559b36..0e372c1 100644
--- a/text.h
+++ b/text.h
@@ -70,6 +70,9 @@ size_t text_lineno_by_pos(Text*, size_t pos);
/* set `buf' to the byte found at `pos' and return true, if `pos' is invalid
* false is returned and `buf' is left unmodified */
bool text_byte_get(Text*, size_t pos, char *buf);
+/* same as byte get, but if a sequence of '\r\n' is read at `pos',
+ * `buf` is set to \n instead of \r. */
+bool text_char_get(Text*, size_t pos, char *buf);
/* store at most `len' bytes starting from `pos' into `buf', the return value
* indicates how many bytes were copied into `buf'. WARNING buf will not be
* NUL terminated. */