]> git.mdlowis.com Git - projs/tide.git/commitdiff
Added some very basic support for utf-8. Combining characters don't display properly...
authorMike Lowis <mike.lowis@gentex.com>
Wed, 5 Oct 2016 13:53:54 +0000 (09:53 -0400)
committerMike Lowis <mike.lowis@gentex.com>
Wed, 5 Oct 2016 13:53:54 +0000 (09:53 -0400)
buf.c

diff --git a/buf.c b/buf.c
index cbe4751e5b78722b3d43d2965ccb09ac8edc9f0b..466a03136a9454e61aa3e064daed4a96f0b1831d 100644 (file)
--- a/buf.c
+++ b/buf.c
@@ -1,13 +1,22 @@
 #include <assert.h>
 #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)) {