From 0d9bbb74c6de959ab7c6b93b7a97f9f2e643e8e8 Mon Sep 17 00:00:00 2001 From: Randy Palamar Date: Fri, 5 Dec 2025 22:36:10 -0700 Subject: replace oversized libutf with smaller version this is taken from one of my other projects. there was no reason for there to be 2x the code tests checking for surrogate characters and non characters were removed. I see no reason why the user shouldn't be allowed to insert those characters in text (they exist in the standard). Also, in the case of non-characters only the first two were being checked and not the other 64. --- libutf.c | 54 ------------------------------------------------------ 1 file changed, 54 deletions(-) delete mode 100644 libutf.c (limited to 'libutf.c') diff --git a/libutf.c b/libutf.c deleted file mode 100644 index 108595e..0000000 --- a/libutf.c +++ /dev/null @@ -1,54 +0,0 @@ -/* libutf8 © 2012-2015 Connor Lane Smith */ -#include "util.h" - -#include "libutf.h" - -int -runelen(Rune r) -{ - if(r <= 0x7F) - return 1; - else if(r <= 0x07FF) - return 2; - else if(r <= 0xD7FF) - return 3; - else if(r <= 0xDFFF) - return 0; /* surrogate character */ - else if(r <= 0xFFFD) - return 3; - else if(r <= 0xFFFF) - return 0; /* illegal character */ - else if(r <= Runemax) - return 4; - else - return 0; /* rune too large */ -} - -int -runetochar(char *s, const Rune *p) -{ - Rune r = *p; - - switch(runelen(r)) { - case 1: /* 0aaaaaaa */ - s[0] = r; - return 1; - case 2: /* 00000aaa aabbbbbb */ - s[0] = 0xC0 | ((r & 0x0007C0) >> 6); /* 110aaaaa */ - s[1] = 0x80 | (r & 0x00003F); /* 10bbbbbb */ - return 2; - case 3: /* aaaabbbb bbcccccc */ - s[0] = 0xE0 | ((r & 0x00F000) >> 12); /* 1110aaaa */ - s[1] = 0x80 | ((r & 0x000FC0) >> 6); /* 10bbbbbb */ - s[2] = 0x80 | (r & 0x00003F); /* 10cccccc */ - return 3; - case 4: /* 000aaabb bbbbcccc ccdddddd */ - s[0] = 0xF0 | ((r & 0x1C0000) >> 18); /* 11110aaa */ - s[1] = 0x80 | ((r & 0x03F000) >> 12); /* 10bbbbbb */ - s[2] = 0x80 | ((r & 0x000FC0) >> 6); /* 10cccccc */ - s[3] = 0x80 | (r & 0x00003F); /* 10dddddd */ - return 4; - default: - return 0; /* error */ - } -} -- cgit v1.2.3