diff options
| -rw-r--r-- | text.c | 11 | ||||
| -rw-r--r-- | text.h | 2 |
2 files changed, 13 insertions, 0 deletions
@@ -664,6 +664,17 @@ bool text_vprintf(Text *txt, size_t pos, const char *format, va_list ap) { return ret; } +bool text_insert_newline(Text *txt, size_t pos) { + switch (text_newline_type(txt)) { + case TEXT_NEWLINE_NL: + return text_insert(txt, pos, "\n", 1); + case TEXT_NEWLINE_CRNL: + return text_insert(txt, pos, "\r\n", 2); + default: + return false; + } +} + static size_t action_undo(Text *txt, Action *a) { size_t pos = EPOS; for (Change *c = a->change; c; c = c->next) { @@ -40,6 +40,8 @@ struct stat text_stat(Text*); bool text_appendf(Text*, const char *format, ...); bool text_printf(Text*, size_t pos, const char *format, ...); bool text_vprintf(Text*, size_t pos, const char *format, va_list ap); +/* inserts a line ending character (depending on file type) */ +bool text_insert_newline(Text*, size_t pos); /* insert `len' bytes starting from `data' at `pos' which has to be * in the interval [0, text_size(txt)] */ bool text_insert(Text*, size_t pos, const char *data, size_t len); |
