diff options
author | 2020-12-08 21:19:17 -0500 | |
---|---|---|
committer | 2020-12-08 21:24:46 -0500 | |
commit | c22cb17f326b4939d8ff4219410909e32e70ab86 (patch) | |
tree | 8db68c201fa9673eeb6acab37a5d221c7a338ea6 /src/frontend/mame/ui/text.cpp | |
parent | 6172111b187c1dd66329adb2b9bba2a82a0ce116 (diff) |
C++17 string handling updates (without charconv so as not to break GCC 7)
- render.cpp, rendlay.cpp, ui/ui.cpp, ui/menu.cpp: Change argument types for text processing functions from const char * to std::string_view
- ui/menu.cpp: Add overloads of item_append omitting the frequently empty subtext argument
- cheat.cpp: Remove some c_str() calls that became unnecessary a while ago
Diffstat (limited to 'src/frontend/mame/ui/text.cpp')
-rw-r--r-- | src/frontend/mame/ui/text.cpp | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/frontend/mame/ui/text.cpp b/src/frontend/mame/ui/text.cpp index 0e61b1710db..54bd327cacc 100644 --- a/src/frontend/mame/ui/text.cpp +++ b/src/frontend/mame/ui/text.cpp @@ -121,12 +121,9 @@ text_layout::~text_layout() // add_text //------------------------------------------------- -void text_layout::add_text(const char *text, const char_style &style) +void text_layout::add_text(std::string_view text, const char_style &style) { - std::size_t position = 0; - std::size_t const text_length = std::strlen(text); - - while (position < text_length) + while (!text.empty()) { // adding a character - we might change the width invalidate_calculated_actual_width(); @@ -136,7 +133,7 @@ void text_layout::add_text(const char *text, const char_style &style) { // get the current character char32_t schar; - int const scharcount = uchar_from_utf8(&schar, &text[position], text_length - position); + int const scharcount = uchar_from_utf8(&schar, &text[0], text.length()); if (scharcount < 0) break; @@ -144,7 +141,7 @@ void text_layout::add_text(const char *text, const char_style &style) text_justify line_justify = justify(); if (schar == '\t') { - position += unsigned(scharcount); + text.remove_prefix(scharcount); line_justify = text_layout::CENTER; } @@ -154,10 +151,10 @@ void text_layout::add_text(const char *text, const char_style &style) // get the current character char32_t ch; - int const scharcount = uchar_from_utf8(&ch, &text[position], text_length - position); + int const scharcount = uchar_from_utf8(&ch, &text[0], text.length()); if (scharcount < 0) break; - position += unsigned(scharcount); + text.remove_prefix(scharcount); // set up source information source_info source = { 0, }; |