From 0e9fc2be15b0926dfee08846c906cd3b2668878a Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 11 Jul 2012 02:21:36 -0700 Subject: [PATCH] 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 --- line.c | 21 ++++++++++++++++++++- main.c | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/line.c b/line.c index f1aa084..6e46ffc 100644 --- a/line.c +++ b/line.c @@ -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 * diff --git a/main.c b/main.c index 9331b38..a6dabf6 100644 --- a/main.c +++ b/main.c @@ -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