From 23686632d48fe9d31fb4538593e995df766743a2 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 13 Jan 2003 10:06:26 +0000 Subject: [PATCH] fix some bugs where looked up wrong offsets for characters in the utf8_skip table, move the table into the .cc --- otk/ustring.cc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/otk/ustring.cc b/otk/ustring.cc index b721089e..8c48cb4d 100644 --- a/otk/ustring.cc +++ b/otk/ustring.cc @@ -14,6 +14,18 @@ namespace otk { // helper functions +// The number of bytes to skip to find the next character in the string +static const char utf8_skip[256] = { + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1 +}; + // takes a pointer into a utf8 string and returns a unicode character for the // first character at the pointer unichar utf8_get_char (const char *p) @@ -41,7 +53,7 @@ static ustring::size_type utf8_ptr_to_offset(const char *str, const char *pos) ustring::size_type offset = 0; while (str < pos) { - str += utf8_skip[*str]; + str += utf8_skip[static_cast(*str)]; offset++; } @@ -52,7 +64,7 @@ static ustring::size_type utf8_ptr_to_offset(const char *str, const char *pos) const char *utf8_offset_to_ptr(const char *str, ustring::size_type offset) { while (offset--) - str += utf8_skip[*str]; + str += utf8_skip[static_cast(*str)]; return str; } @@ -69,7 +81,7 @@ ustring::size_type utf8_byte_offset(const char* str, ustring::size_type offset) if(*p == '\0') return ustring::npos; - p += utf8_skip[*p]; + p += utf8_skip[static_cast(*p)]; } return (p - str); @@ -90,7 +102,7 @@ ustring::size_type utf8_byte_offset(const char* str, ustring::size_type offset, if(p >= pend) return ustring::npos; - p += utf8_skip[*p]; + p += utf8_skip[static_cast(*p)]; } return (p - str); -- 2.39.2