diff --git a/Makefile.common b/Makefile.common index da0b2b5e89..2bc3bd4f65 100644 --- a/Makefile.common +++ b/Makefile.common @@ -220,8 +220,7 @@ OBJ += frontend/frontend.o \ record/drivers/record_null.o \ libretro-common/features/features_cpu.o \ performance_counters.o \ - verbosity.o \ - libretro-common/string/utf8_util.o + verbosity.o ifeq ($(HAVE_LANGEXTRA), 1) DEFINES += -DHAVE_LANGEXTRA diff --git a/gfx/drivers_font/gl_raster_font.c b/gfx/drivers_font/gl_raster_font.c index cec87cd72f..3c8bfd7ab0 100644 --- a/gfx/drivers_font/gl_raster_font.c +++ b/gfx/drivers_font/gl_raster_font.c @@ -17,7 +17,7 @@ #include "../common/gl_common.h" #include "../font_driver.h" #include "../video_shader_driver.h" -#include +#include /* TODO: Move viewport side effects to the caller: it's a source of bugs. */ @@ -36,14 +36,6 @@ #define MAX_MSG_LEN_CHUNK 64 -#ifdef HAVE_UTF8 -#define string_walk utf8_walk -#define string_len utf8_strlen -#else -#define string_walk utf8_walkbyte -#define string_len strlen -#endif - typedef struct { gl_t *gl; @@ -307,7 +299,7 @@ static void gl_raster_font_render_line( { int off_x, off_y, tex_x, tex_y, width, height; const struct font_glyph *glyph = - font->font_driver->get_glyph(font->font_data, string_walk(&msg)); + font->font_driver->get_glyph(font->font_data, utf8_walk(&msg)); if (!glyph) /* Do something smarter here ... */ glyph = font->font_driver->get_glyph(font->font_data, '?'); @@ -369,7 +361,7 @@ static void gl_raster_font_render_message( /* If the font height is not supported just draw as usual */ if (!font->font_driver->get_line_height) { - gl_raster_font_render_line(font, msg, string_len(msg), + gl_raster_font_render_line(font, msg, utf8len(msg), scale, color, pos_x, pos_y, text_align); return; } @@ -393,7 +385,7 @@ static void gl_raster_font_render_message( } else { - unsigned msg_len = string_len(msg); + unsigned msg_len = utf8len(msg); gl_raster_font_render_line(font, msg, msg_len, scale, color, pos_x, pos_y - (float)lines*line_height, text_align); break; diff --git a/libretro-common/encodings/encoding_utf.c b/libretro-common/encodings/encoding_utf.c index 93b2051607..ad52cff818 100644 --- a/libretro-common/encodings/encoding_utf.c +++ b/libretro-common/encodings/encoding_utf.c @@ -208,3 +208,31 @@ size_t utf8len(const char *string) return strlen(string); #endif } + +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; +} diff --git a/libretro-common/include/encodings/utf.h b/libretro-common/include/encodings/utf.h index 531ebe686a..85db439d82 100644 --- a/libretro-common/include/encodings/utf.h +++ b/libretro-common/include/encodings/utf.h @@ -40,4 +40,8 @@ size_t utf8cpy(char *d, size_t d_len, const char *s, size_t chars); const char *utf8skip(const char *str, size_t chars); +uint8_t utf8_walkbyte(const char **string); + +uint32_t utf8_walk(const char **string); + #endif diff --git a/libretro-common/include/string/utf8_util.h b/libretro-common/include/string/utf8_util.h deleted file mode 100644 index c70c95244f..0000000000 --- a/libretro-common/include/string/utf8_util.h +++ /dev/null @@ -1,32 +0,0 @@ -/* 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 deleted file mode 100644 index bc202d761b..0000000000 --- a/libretro-common/string/utf8_util.c +++ /dev/null @@ -1,39 +0,0 @@ -#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; -} diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index 9164dfef1a..9c94aa6355 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include "menu_generic.h" @@ -47,12 +47,6 @@ #include "../../file_path_special.h" -#ifdef HAVE_UTF8 -#define string_len utf8_strlen -#else -#define string_len strlen -#endif - enum { MUI_TEXTURE_POINTER = 0, @@ -407,7 +401,7 @@ static void mui_render_messagebox(mui_handle_t *mui, for (i = 0; i < list->size; i++) { const char *msg = list->elems[i].data; - int len = string_len(msg); + int len = utf8len(msg); if (len > longest) { longest = len; @@ -530,7 +524,7 @@ static void mui_render_label_value(mui_handle_t *mui, menu_animation_ctx_ticker_t ticker; char label_str[PATH_MAX_LENGTH] = {0}; char value_str[PATH_MAX_LENGTH] = {0}; - int value_len = string_len(value); + int value_len = utf8len(value); int ticker_limit = 0; uintptr_t texture_switch = 0; bool do_draw_text = false; @@ -1183,7 +1177,7 @@ static void mui_frame(void *data) snprintf(title_buf_msg, sizeof(title_buf), "%s (%s)", title_buf, title_msg); - value_len = string_len(title_buf); + value_len = utf8len(title_buf); ticker_limit = (usable_width / mui->glyph_width) - (value_len + 2); ticker.s = title_buf_msg_tmp; diff --git a/menu/drivers/rgui.c b/menu/drivers/rgui.c index e05627723b..be2f22a08c 100644 --- a/menu/drivers/rgui.c +++ b/menu/drivers/rgui.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include "menu_generic.h" @@ -46,14 +46,6 @@ #define RGUI_TERM_WIDTH(width) (((width - RGUI_TERM_START_X(width) - RGUI_TERM_START_X(width)) / (FONT_WIDTH_STRIDE))) #define RGUI_TERM_HEIGHT(width, height) (((height - RGUI_TERM_START_Y(height) - RGUI_TERM_START_X(width)) / (FONT_HEIGHT_STRIDE)) - 1) -#ifdef HAVE_UTF8 -#define string_walk utf8_walk -#define string_len utf8_strlen -#else -#define string_walk utf8_walkbyte -#define string_len strlen -#endif - typedef struct { bool force_redraw; @@ -185,7 +177,7 @@ static void blit_line(int x, int y, while (!string_is_empty(message)) { const uint8_t *font_fb = menu_display_get_font_framebuffer(); - uint32_t symbol = string_walk(&message); + uint32_t symbol = utf8_walk(&message); for (j = 0; j < FONT_HEIGHT; j++) { @@ -322,7 +314,7 @@ static void rgui_render_messagebox(const char *message) { unsigned line_width; char *msg = list->elems[i].data; - unsigned msglen = string_len(msg); + unsigned msglen = utf8len(msg); if (msglen > RGUI_TERM_WIDTH(fb_width)) { @@ -357,7 +349,7 @@ static void rgui_render_messagebox(const char *message) for (i = 0; i < list->size; i++) { const char *msg = list->elems[i].data; - int offset_x = FONT_WIDTH_STRIDE * (glyphs_width - string_len(msg)) / 2; + int offset_x = FONT_WIDTH_STRIDE * (glyphs_width - utf8len(msg)) / 2; int offset_y = FONT_HEIGHT_STRIDE * i; blit_line(x + 8 + offset_x, y + 8 + offset_y, msg, color); @@ -527,7 +519,7 @@ static void rgui_render(void *data) blit_line( RGUI_TERM_START_X(fb_width) + (RGUI_TERM_WIDTH(fb_width) - - string_len(title_buf)) * FONT_WIDTH_STRIDE / 2, + - utf8len(title_buf)) * FONT_WIDTH_STRIDE / 2, RGUI_TERM_START_X(fb_width), title_buf, TITLE_COLOR(settings)); @@ -602,8 +594,8 @@ static void rgui_render(void *data) snprintf(message, sizeof(message), "%c %-*.*s %-*s", entry_selected ? '>' : ' ', - (int)(RGUI_TERM_WIDTH(fb_width) - (entry_spacing + 1 + 2) - utf8len(entry_title_buf) + string_len(entry_title_buf)), - (int)(RGUI_TERM_WIDTH(fb_width) - (entry_spacing + 1 + 2) - utf8len(entry_title_buf) + string_len(entry_title_buf)), + (int)(RGUI_TERM_WIDTH(fb_width) - (entry_spacing + 1 + 2) - utf8len(entry_title_buf) + strlen(entry_title_buf)), + (int)(RGUI_TERM_WIDTH(fb_width) - (entry_spacing + 1 + 2) - utf8len(entry_title_buf) + strlen(entry_title_buf)), entry_title_buf, entry_spacing, type_str_buf); diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 8429cb1825..9caeb07b26 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include "menu_generic.h" @@ -57,12 +57,6 @@ #define XMB_DELAY 10 #endif -#ifdef HAVE_UTF8 -#define string_len utf8_strlen -#else -#define string_len strlen -#endif - typedef struct { float alpha; @@ -708,7 +702,7 @@ static void xmb_render_messagebox_internal( for (i = 0; i < list->size; i++) { const char *msg = list->elems[i].data; - int len = string_len(msg); + int len = utf8len(msg); if (len > longest) { longest = len;