From e267bd9292909ae41a7dac1c8238717d1959ceeb Mon Sep 17 00:00:00 2001 From: Mike Lowis Date: Wed, 5 Oct 2016 09:53:54 -0400 Subject: [PATCH] Added some very basic support for utf-8. Combining characters don't display properly but they still read in properly --- buf.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/buf.c b/buf.c index cbe4751..466a031 100644 --- a/buf.c +++ b/buf.c @@ -1,13 +1,22 @@ #include #include "edit.h" +int fpeekc(FILE* fin) { + int c = fgetc(fin); + ungetc(c, fin); + return c; +} + void buf_load(Buf* buf, char* path) { unsigned i = 0; FILE* in = fopen(path, "rb"); - int c; - while (EOF != (c = fgetc(in))) - buf_ins(buf, i++, (Rune)c); + while (EOF != fpeekc(in)) { + size_t len = 0; + Rune r = 0; + while (!utf8decode(&r, &len, fgetc(in))); + buf_ins(buf, i++, r); + } fclose(in); } @@ -23,7 +32,6 @@ void buf_initsz(Buf* buf, size_t sz) static void syncgap(Buf* buf, unsigned off) { - //printf("assert: %u <= %u\n", off, buf_end(buf)); assert(off <= buf_end(buf)); /* If the buffer is full, resize it before syncing */ if (0 == (buf->gapend - buf->gapstart)) { -- 2.49.0