aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--text.c11
-rw-r--r--text.h2
2 files changed, 13 insertions, 0 deletions
diff --git a/text.c b/text.c
index da14209..7f94247 100644
--- a/text.c
+++ b/text.c
@@ -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) {
diff --git a/text.h b/text.h
index 685079e..b2783b3 100644
--- a/text.h
+++ b/text.h
@@ -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);