From: Mike Lowis Date: Wed, 5 Oct 2016 13:53:54 +0000 (-0400) Subject: Added some very basic support for utf-8. Combining characters don't display properly... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=e267bd9292909ae41a7dac1c8238717d1959ceeb;p=projs%2Ftide.git Added some very basic support for utf-8. Combining characters don't display properly but they still read in properly --- 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)) {