diff options
Diffstat (limited to 'text.c')
| -rw-r--r-- | text.c | 32 |
1 files changed, 1 insertions, 31 deletions
@@ -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, |
