diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-07-11 02:21:36 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-07-11 02:21:36 -0700 |
commit | 0e9fc2be15b0926dfee08846c906cd3b2668878a (patch) | |
tree | 7a44b1e123a1f8ec710a1e7067dc0aead6413a70 | |
parent | 4bccfab6324c8c8bc8106e65c4aec076f5d121be (diff) | |
download | uemacs-0e9fc2be15b0926dfee08846c906cd3b2668878a.tar.gz |
Start actually inserting full utf8 sequences
This makes it possible to cut-and-paste the UTF8 testfile into a new
buffer, and the end result looks correct.
NOTE! We still do various things wrong while editing. For example,
while the cursor movements were fixed, simple things like deleting a
character still work on single bytes, rather than utf8 characters.
So while this is getting much closer to actually editing UTF-8 data,
it's not there yet.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | line.c | 21 | ||||
-rw-r--r-- | main.c | 2 |
2 files changed, 21 insertions, 2 deletions
@@ -20,6 +20,7 @@ #include "estruct.h" #include "edef.h" #include "efunc.h" +#include "utf8.h" #define BLOCK_SIZE 16 /* Line block chunk size. */ @@ -161,7 +162,7 @@ int linstr(char *instr) * well, and FALSE on errors. */ -int linsert(int n, int c) +static int linsert_byte(int n, int c) { char *cp1; char *cp2; @@ -239,6 +240,24 @@ int linsert(int n, int c) return TRUE; } +int linsert(int n, int c) +{ + char utf8[6]; + int bytes = unicode_to_utf8(c, utf8), i; + + if (bytes == 1) + return linsert_byte(n, (unsigned char) utf8[0]); + for (i = 0; i < n; i++) { + int j; + for (j = 0; j < bytes; j++) { + unsigned char c = utf8[j]; + if (!linsert_byte(1, c)) + return FALSE; + } + } + return TRUE; +} + /* * Overwrite a character into the current line at the current position * @@ -500,7 +500,7 @@ int execute(int c, int f, int n) || (c >= 0x80 && c <= 0xFE)) { #else #if VMS || BSD || USG /* 8BIT P.K. */ - || (c >= 0xA0 && c <= 0xFE)) { + || (c >= 0xA0 && c <= 0xFFFF)) { #else ) { #endif |