From 80d4626908fffe10ac313e0ccf8913e4a5c7cdd4 Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Tue, 23 Aug 2016 19:02:26 -0400 Subject: [PATCH] forgot to add extra utf8 files --- libretro-common/include/string/utf8_util.h | 32 ++++++++++++++++++ libretro-common/string/utf8_util.c | 39 ++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 libretro-common/include/string/utf8_util.h create mode 100644 libretro-common/string/utf8_util.c diff --git a/libretro-common/include/string/utf8_util.h b/libretro-common/include/string/utf8_util.h new file mode 100644 index 0000000000..c70c95244f --- /dev/null +++ b/libretro-common/include/string/utf8_util.h @@ -0,0 +1,32 @@ +/* Copyright (C) 2010-2016 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (utf8_util.h). + * --------------------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, + * to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef __LIBRETRO_SDK_UTF8_UTIL_H__ +#define __LIBRETRO_SDK_UTF8_UTIL_H__ + +#include + +unsigned utf8_strlen(const char *string); +uint8_t utf8_walkbyte(const char **string); +uint32_t utf8_walk(const char **string); + +#endif diff --git a/libretro-common/string/utf8_util.c b/libretro-common/string/utf8_util.c new file mode 100644 index 0000000000..bc202d761b --- /dev/null +++ b/libretro-common/string/utf8_util.c @@ -0,0 +1,39 @@ +#include + +uint32_t utf8_strlen(const char *s) +{ + int i = 0, j = 0; + while (s[i]) { + if ((s[i] & 0xc0) != 0x80) j++; + i++; + } + return j; +} + +uint8_t utf8_walkbyte(const char **string) +{ + return *((*string)++); +} + +/* Does not validate the input, returns garbage if it's not UTF-8. */ +uint32_t utf8_walk(const char **string) +{ + uint8_t first = utf8_walkbyte(string); + uint32_t ret; + + if (first<128) + return first; + + ret = 0; + ret = (ret<<6) | (utf8_walkbyte(string) & 0x3F); + if (first >= 0xE0) + ret = (ret<<6) | (utf8_walkbyte(string) & 0x3F); + if (first >= 0xF0) + ret = (ret<<6) | (utf8_walkbyte(string) & 0x3F); + + if (first >= 0xF0) + return ret | (first&31)<<18; + if (first >= 0xE0) + return ret | (first&15)<<12; + return ret | (first&7)<<6; +}