unicode.h: Updates

- Remove from emu.h (except for UTF8_xxx macros, which have been transplanted to emucore.h since a lot of drivers use them) and osdepend.h
- Add std::string_view overrides for uchar_from_utf8 and normalize_unicode
This commit is contained in:
AJR 2020-12-15 13:36:55 -05:00
parent 35bec8d273
commit 2ca5f3a386
20 changed files with 82 additions and 53 deletions

View File

@ -30,6 +30,7 @@
#include "debugger.h"
#include "r4000.h"
#include "mips3dsm.h"
#include "unicode.h"
#include "softfloat3/source/include/softfloat.h"

View File

@ -11,6 +11,7 @@
#include "emu.h"
#include "drivenum.h"
#include "softlist_dev.h"
#include "unicode.h"
#include <algorithm>

View File

@ -38,7 +38,6 @@
// commonly-referenced utilities imported from lib/util
#include "palette.h"
#include "unicode.h"
#include "strformat.h"
#include "vecstream.h"

View File

@ -188,6 +188,47 @@ constexpr int ROT180 = ORIENTATION_FLIP_X | ORIENTATION_FLIP_Y;
constexpr int ROT270 = ORIENTATION_SWAP_XY | ORIENTATION_FLIP_Y; // rotate counter-clockwise 90 degrees
// these are UTF-8 encoded strings for common characters
#define UTF8_NBSP "\xc2\xa0" /* non-breaking space */
#define UTF8_MULTIPLY "\xc3\x97" /* multiplication sign */
#define UTF8_DIVIDE "\xc3\xb7" /* division sign */
#define UTF8_SQUAREROOT "\xe2\x88\x9a" /* square root symbol */
#define UTF8_PLUSMINUS "\xc2\xb1" /* plusminus symbol */
#define UTF8_POW_2 "\xc2\xb2" /* superscript 2 */
#define UTF8_POW_X "\xcb\xa3" /* superscript x */
#define UTF8_POW_Y "\xca\xb8" /* superscript y */
#define UTF8_PRIME "\xca\xb9" /* prime symbol */
#define UTF8_DEGREES "\xc2\xb0" /* degrees symbol */
#define UTF8_SMALL_PI "\xcf\x80" /* Greek small letter pi */
#define UTF8_CAPITAL_SIGMA "\xce\xa3" /* Greek capital letter sigma */
#define UTF8_CAPITAL_DELTA "\xce\x94" /* Greek capital letter delta */
#define UTF8_MACRON "\xc2\xaf" /* macron symbol */
#define UTF8_NONSPACE_MACRON "\xcc\x84" /* nonspace macron, use after another char */
#define a_RING "\xc3\xa5" /* small a with a ring */
#define a_UMLAUT "\xc3\xa4" /* small a with an umlaut */
#define o_UMLAUT "\xc3\xb6" /* small o with an umlaut */
#define u_UMLAUT "\xc3\xbc" /* small u with an umlaut */
#define e_ACUTE "\xc3\xa9" /* small e with an acute */
#define n_TILDE "\xc3\xb1" /* small n with a tilde */
#define A_RING "\xc3\x85" /* capital A with a ring */
#define A_UMLAUT "\xc3\x84" /* capital A with an umlaut */
#define O_UMLAUT "\xc3\x96" /* capital O with an umlaut */
#define U_UMLAUT "\xc3\x9c" /* capital U with an umlaut */
#define E_ACUTE "\xc3\x89" /* capital E with an acute */
#define N_TILDE "\xc3\x91" /* capital N with a tilde */
#define UTF8_LEFT "\xe2\x86\x90" /* cursor left */
#define UTF8_RIGHT "\xe2\x86\x92" /* cursor right */
#define UTF8_UP "\xe2\x86\x91" /* cursor up */
#define UTF8_DOWN "\xe2\x86\x93" /* cursor down */
//**************************************************************************
// COMMON MACROS

View File

@ -100,6 +100,7 @@
#include "natkeyboard.h"
#include "osdepend.h"
#include "unicode.h"
#include <cctype>
#include <ctime>

View File

@ -11,6 +11,7 @@
#include "emu.h"
#include "natkeyboard.h"
#include "emuopts.h"
#include "unicode.h"
#include <algorithm>
#include <cstring>

View File

@ -15,6 +15,7 @@
#include "osdepend.h"
#include "uismall.fh"
#include "unicode.h"
#include "ui/uicmd14.fh"
#include "ui/cmddata.h"
@ -380,7 +381,7 @@ std::string convert_command_glyph(std::string_view str)
{
// decode UTF-8
char32_t uchar;
int const codelen(uchar_from_utf8(&uchar, &str[0], str.length()));
int const codelen(uchar_from_utf8(&uchar, str));
if (0 >= codelen)
break;
str.remove_prefix(codelen);
@ -861,7 +862,7 @@ float render_font::string_width(float height, float aspect, std::string_view str
// loop over characters
while (!string.empty())
{
int scharcount = uchar_from_utf8(&schar, &string[0], string.length());
int scharcount = uchar_from_utf8(&schar, string);
totwidth += get_char(schar).width;
string.remove_prefix(scharcount);
}
@ -884,7 +885,7 @@ float render_font::utf8string_width(float height, float aspect, std::string_view
while (!utf8string.empty())
{
char32_t uchar;
int count = uchar_from_utf8(&uchar, &utf8string[0], utf8string.length());
int count = uchar_from_utf8(&uchar, utf8string);
if (count < 0)
break;

View File

@ -18,6 +18,7 @@
#include "video/rgbutil.h"
#include "nanosvg.h"
#include "unicode.h"
#include "vecstream.h"
#include "xmlfile.h"
@ -3156,7 +3157,7 @@ protected:
while (!s.empty())
{
char32_t schar;
int scharcount = uchar_from_utf8(&schar, &s[0], s.length());
int scharcount = uchar_from_utf8(&schar, s);
if (scharcount == -1)
break;
@ -3307,7 +3308,7 @@ private:
while (!s.empty())
{
char32_t schar;
int scharcount = uchar_from_utf8(&schar, &s[0], s.length());
int scharcount = uchar_from_utf8(&schar, s);
if (scharcount == -1)
break;
@ -3693,7 +3694,7 @@ void layout_element::component::draw_text(
while (!str.empty())
{
char32_t schar;
int scharcount = uchar_from_utf8(&schar, &str[0], str.length());
int scharcount = uchar_from_utf8(&schar, str);
if (scharcount == -1)
break;

View File

@ -16,6 +16,8 @@
#include "romload.h"
#include "validity.h"
#include "unicode.h"
#include <cctype>

View File

@ -14,6 +14,7 @@
#include "emuopts.h"
#include "romload.h"
#include "video/rgbutil.h"
#include "unicode.h"
#include <cctype>
#include <type_traits>

View File

@ -13,6 +13,7 @@
#include "ui/ui.h"
#include "ui/utils.h"
#include "unicode.h"
namespace ui {

View File

@ -31,6 +31,7 @@
#include "romload.h"
#include "softlist_dev.h"
#include "uiinput.h"
#include "unicode.h"
#include <atomic>
#include <condition_variable>

View File

@ -24,6 +24,7 @@
#include "softlist_dev.h"
#include "uiinput.h"
#include "luaengine.h"
#include "unicode.h"
#include <algorithm>
#include <iterator>

View File

@ -12,6 +12,7 @@
#include "text.h"
#include "rendfont.h"
#include "render.h"
#include "unicode.h"
#include <cstddef>
#include <cstring>
@ -133,7 +134,7 @@ void text_layout::add_text(std::string_view text, const char_style &style)
{
// get the current character
char32_t schar;
int const scharcount = uchar_from_utf8(&schar, &text[0], text.length());
int const scharcount = uchar_from_utf8(&schar, text);
if (scharcount < 0)
break;
@ -151,7 +152,7 @@ void text_layout::add_text(std::string_view text, const char_style &style)
// get the current character
char32_t ch;
int const scharcount = uchar_from_utf8(&ch, &text[0], text.length());
int const scharcount = uchar_from_utf8(&ch, text);
if (scharcount < 0)
break;
text.remove_prefix(scharcount);

View File

@ -19,6 +19,8 @@
#include <unordered_map>
#include <vector>
#include "unicode.h"
class mame_ui_manager;
class render_container;

View File

@ -120,6 +120,17 @@ bool uchar_is_digit(char32_t uchar)
}
//-------------------------------------------------
// uchar_from_utf8 - convert a UTF-8 sequence
// into a unicode character
//-----------------------------------------------
int uchar_from_utf8(char32_t *uchar, std::string_view utf8str)
{
return uchar_from_utf8(uchar, utf8str.data(), utf8str.length());
}
//-------------------------------------------------
// uchar_from_utf8 - convert a UTF-8 sequence
// into a unicode character
@ -494,9 +505,9 @@ std::string normalize_unicode(const char *s, unicode_normalization_form normaliz
// unicode
//-------------------------------------------------
std::string normalize_unicode(const char *s, size_t length, unicode_normalization_form normalization_form, bool fold_case)
std::string normalize_unicode(std::string_view s, unicode_normalization_form normalization_form, bool fold_case)
{
return internal_normalize_unicode(s, length, normalization_form, fold_case, false);
return internal_normalize_unicode(s.data(), s.length(), normalization_form, fold_case, false);
}

View File

@ -22,6 +22,7 @@
#include "osdcore.h"
#include <string>
#include <string_view>
#include <cstdlib>
@ -36,46 +37,6 @@
#define UTF8_CHAR_MAX 6
#define UTF16_CHAR_MAX 2
// these are UTF-8 encoded strings for common characters
#define UTF8_NBSP "\xc2\xa0" /* non-breaking space */
#define UTF8_MULTIPLY "\xc3\x97" /* multiplication sign */
#define UTF8_DIVIDE "\xc3\xb7" /* division sign */
#define UTF8_SQUAREROOT "\xe2\x88\x9a" /* square root symbol */
#define UTF8_PLUSMINUS "\xc2\xb1" /* plusminus symbol */
#define UTF8_POW_2 "\xc2\xb2" /* superscript 2 */
#define UTF8_POW_X "\xcb\xa3" /* superscript x */
#define UTF8_POW_Y "\xca\xb8" /* superscript y */
#define UTF8_PRIME "\xca\xb9" /* prime symbol */
#define UTF8_DEGREES "\xc2\xb0" /* degrees symbol */
#define UTF8_SMALL_PI "\xcf\x80" /* Greek small letter pi */
#define UTF8_CAPITAL_SIGMA "\xce\xa3" /* Greek capital letter sigma */
#define UTF8_CAPITAL_DELTA "\xce\x94" /* Greek capital letter delta */
#define UTF8_MACRON "\xc2\xaf" /* macron symbol */
#define UTF8_NONSPACE_MACRON "\xcc\x84" /* nonspace macron, use after another char */
#define a_RING "\xc3\xa5" /* small a with a ring */
#define a_UMLAUT "\xc3\xa4" /* small a with an umlaut */
#define o_UMLAUT "\xc3\xb6" /* small o with an umlaut */
#define u_UMLAUT "\xc3\xbc" /* small u with an umlaut */
#define e_ACUTE "\xc3\xa9" /* small e with an acute */
#define n_TILDE "\xc3\xb1" /* small n with a tilde */
#define A_RING "\xc3\x85" /* capital A with a ring */
#define A_UMLAUT "\xc3\x84" /* capital A with an umlaut */
#define O_UMLAUT "\xc3\x96" /* capital O with an umlaut */
#define U_UMLAUT "\xc3\x9c" /* capital U with an umlaut */
#define E_ACUTE "\xc3\x89" /* capital E with an acute */
#define N_TILDE "\xc3\x91" /* capital N with a tilde */
#define UTF8_LEFT "\xe2\x86\x90" /* cursor left */
#define UTF8_RIGHT "\xe2\x86\x92" /* cursor right */
#define UTF8_UP "\xe2\x86\x91" /* cursor up */
#define UTF8_DOWN "\xe2\x86\x93" /* cursor down */
enum class unicode_normalization_form { C, D, KC, KD };
@ -95,6 +56,7 @@ bool uchar_is_digit(char32_t uchar);
// converting strings to 32-bit Unicode chars
int uchar_from_utf8(char32_t *uchar, const char *utf8char, size_t count);
int uchar_from_utf8(char32_t *uchar, std::string_view utf8str);
int uchar_from_utf16(char32_t *uchar, const char16_t *utf16char, size_t count);
int uchar_from_utf16f(char32_t *uchar, const char16_t *utf16char, size_t count);
std::u32string ustr_from_utf8(const std::string &utf8str);
@ -112,7 +74,7 @@ std::string utf8_from_wstring(const std::wstring &string);
// unicode normalization
std::string normalize_unicode(const std::string &s, unicode_normalization_form normalization_form, bool fold_case = false);
std::string normalize_unicode(const char *s, unicode_normalization_form normalization_form, bool fold_case = false);
std::string normalize_unicode(const char *s, size_t length, unicode_normalization_form normalization_form, bool fold_case = false);
std::string normalize_unicode(std::string_view s, unicode_normalization_form normalization_form, bool fold_case = false);
// upper and lower case
char32_t uchar_toupper(char32_t ch);

View File

@ -31,6 +31,7 @@
#include "emu.h"
#include "uiinput.h"
#include "strconv.h"
#include "unicode.h"
// MAMEOS headers
#include "input_common.h"

View File

@ -17,6 +17,7 @@
#include "osdnet.h"
#include "modules/osdmodule.h"
#include "netdev_module.h"
#include "unicode.h"
#ifdef __linux__
#define IFF_TAP 0x0002

View File

@ -15,7 +15,6 @@
#include "emucore.h"
#include "osdcore.h"
#include "unicode.h"
#include "../frontend/mame/ui/menuitem.h"
#include <memory>