From c818fb021632cbb68229ba265f01b060e6b6d0f4 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Fri, 3 Feb 2012 20:21:17 +0000 Subject: Split off UTF-8 code into separate file and add extra functions. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 2489 --- textscreen/txt_gui.c | 57 +++------------------------------------------------- 1 file changed, 3 insertions(+), 54 deletions(-) (limited to 'textscreen/txt_gui.c') diff --git a/textscreen/txt_gui.c b/textscreen/txt_gui.c index 1bcc2e9e..bc869255 100644 --- a/textscreen/txt_gui.c +++ b/textscreen/txt_gui.c @@ -25,6 +25,7 @@ #include "txt_gui.h" #include "txt_io.h" #include "txt_main.h" +#include "txt_utf8.h" typedef struct txt_cliparea_s txt_cliparea_t; @@ -296,58 +297,6 @@ void TXT_DrawString(const char *s) TXT_GotoXY(x + strlen(s), y); } -// Decode UTF-8 character, incrementing *ptr over the decoded bytes. - -static unsigned int DecodeUTF8(const char **ptr) -{ - const char *p = *ptr; - unsigned int c; - - // UTF-8 decode. - - if ((*p & 0x80) == 0) // 1 character (ASCII): - { - c = *p; - *ptr += 1; - } - else if ((p[0] & 0xe0) == 0xc0 // 2 character: - && (p[1] & 0xc0) == 0x80) - { - c = ((p[0] & 0x1f) << 6) - | (p[1] & 0x3f); - *ptr += 2; - } - else if ((p[0] & 0xf0) == 0xe0 // 3 character: - && (p[1] & 0xc0) == 0x80 - && (p[2] & 0xc0) == 0x80) - { - c = ((p[0] & 0x0f) << 12) - | ((p[1] & 0x3f) << 6) - | (p[2] & 0x3f); - *ptr += 3; - } - else if ((p[0] & 0xf8) == 0xf0 // 4 character: - && (p[1] & 0xc0) == 0x80 - && (p[2] & 0xc0) == 0x80 - && (p[3] & 0xc0) == 0x80) - { - c = ((p[0] & 0x07) << 18) - | ((p[1] & 0x3f) << 12) - | ((p[2] & 0x3f) << 6) - | (p[3] & 0x3f); - *ptr += 4; - } - else - { - // Decode failure. - // Don't bother with 5/6 byte sequences. - - c = 0; - } - - return c; -} - static void PutUnicodeChar(unsigned int c) { unsigned int i; @@ -389,7 +338,7 @@ void TXT_DrawUTF8String(const char *s) for (p = s; *p != '\0'; ) { - c = DecodeUTF8(&p); + c = TXT_DecodeUTF8(&p); if (c == 0) { @@ -406,7 +355,7 @@ void TXT_DrawUTF8String(const char *s) } } - TXT_GotoXY(x + strlen(s), y); + TXT_GotoXY(x + TXT_UTF8_Strlen(s), y); } void TXT_DrawHorizScrollbar(int x, int y, int w, int cursor, int range) -- cgit v1.2.3