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>
This commit is contained in:
Linus Torvalds 2012-07-11 02:21:36 -07:00
parent 4bccfab632
commit 0e9fc2be15
2 changed files with 21 additions and 2 deletions

21
line.c
View File

@ -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
*

2
main.c
View File

@ -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