aboutsummaryrefslogtreecommitdiff
path: root/text.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-04-08 22:11:57 +0200
committerMarc André Tanner <mat@brain-dump.org>2017-04-09 11:28:06 +0200
commit4f15fee811d2645bf810a475d4272f83c30608d6 (patch)
treee61902723c42378b78b43e42bf55f37ec216d702 /text.c
parent6a6bc5bb4c1b5be36b342266d0f74ec4a2843b00 (diff)
downloadvis-4f15fee811d2645bf810a475d4272f83c30608d6.tar.gz
vis-4f15fee811d2645bf810a475d4272f83c30608d6.tar.xz
vis: remove handling of \r\n line endings
Use something like dos2unix(1) and unix2dos(1), if you need to edit such files.
Diffstat (limited to 'text.c')
-rw-r--r--text.c32
1 files changed, 1 insertions, 31 deletions
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,