From 4f15fee811d2645bf810a475d4272f83c30608d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 8 Apr 2017 22:11:57 +0200 Subject: vis: remove handling of \r\n line endings Use something like dos2unix(1) and unix2dos(1), if you need to edit such files. --- text.c | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) (limited to 'text.c') diff --git a/text.c b/text.c index c4d354e..7b197ca 100644 --- a/text.c +++ b/text.c @@ -124,7 +124,6 @@ struct Text { size_t size; /* current file content size in bytes */ struct stat info; /* stat as probed at load time */ LineCache lines; /* mapping between absolute pos in bytes and logical line breaks */ - enum TextNewLine newlines; /* which type of new lines does the file use */ }; struct TextSave { /* used to hold context between text_save_{begin,commit} calls */ @@ -669,9 +668,7 @@ bool text_printf(Text *txt, size_t pos, const char *format, ...) { } size_t text_insert_newline(Text *txt, size_t pos) { - const char *data = text_newline_char(txt); - size_t len = strlen(data); - return text_insert(txt, pos, data, len) ? len : 0; + return text_insert(txt, pos, "\n", 1) ? 1 : 0; } static size_t revision_undo(Text *txt, Revision *rev) { @@ -1321,33 +1318,6 @@ bool text_sigbus(Text *txt, const char *addr) { return false; } -enum TextNewLine text_newline_type(Text *txt){ - if (!txt->newlines) { - txt->newlines = TEXT_NEWLINE_LF; /* default to UNIX style \n new lines */ - const char *start = txt->block ? txt->block->data : NULL; - if (start) { - const char *nl = memchr(start, '\n', txt->block->len); - if (nl > start && nl[-1] == '\r') - txt->newlines = TEXT_NEWLINE_CRLF; - } else { - char c; - size_t nl = lines_skip_forward(txt, 0, 1, NULL); - if (nl > 1 && text_byte_get(txt, nl-2, &c) && c == '\r') - txt->newlines = TEXT_NEWLINE_CRLF; - } - } - - return txt->newlines; -} - -const char *text_newline_char(Text *txt) { - static const char *types[] = { - [TEXT_NEWLINE_LF] = "\n", - [TEXT_NEWLINE_CRLF] = "\r\n", - }; - return types[text_newline_type(txt)]; -} - static bool text_iterator_init(Iterator *it, size_t pos, Piece *p, size_t off) { Iterator iter = (Iterator){ .pos = pos, -- cgit v1.2.3