summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend/mame/ui/selector.cpp
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2016-05-27 16:02:01 +1000
committer Vas Crabb <vas@vastheman.com>2016-05-27 16:03:03 +1000
commit73153c3387a8f0bc628b8f0ee3a63ba8bb6717e8 (patch)
treefd8c90af5704ce62c605f61075c16f88e541be4d /src/frontend/mame/ui/selector.cpp
parent14ad4244485b2f719e471522fa890e1bc17c0898 (diff)
ui refactoring [Vas Crabb]
* Make ARRAY_LENGTH cause a compile error if used with a pointer/vector * Clean up text input code, move common operations to inline templates * Fix numerous one-byte buffer overruns * Don't flat-out ignore input beyond the C1 hole * Fix decoding of SDL text input
Diffstat (limited to 'src/frontend/mame/ui/selector.cpp')
-rw-r--r--src/frontend/mame/ui/selector.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/frontend/mame/ui/selector.cpp b/src/frontend/mame/ui/selector.cpp
index a1c3ad0aa16..a60bb6ce070 100644
--- a/src/frontend/mame/ui/selector.cpp
+++ b/src/frontend/mame/ui/selector.cpp
@@ -100,21 +100,21 @@ void menu_selector::handle()
}
else if (menu_event->iptkey == IPT_SPECIAL)
{
- int buflen = strlen(m_search);
-
- // if it's a backspace and we can handle it, do so
- if ((menu_event->unichar == 8 || menu_event->unichar == 0x7f) && buflen > 0)
+ auto const buflen = strlen(m_search);
+ if ((menu_event->unichar == 8) || (menu_event->unichar == 0x7f))
{
- *(char *)utf8_previous_char(&m_search[buflen]) = 0;
- reset(reset_options::SELECT_FIRST);
+ // if it's a backspace and we can handle it, do so
+ if (0 < buflen)
+ {
+ *const_cast<char *>(utf8_previous_char(&m_search[buflen])) = 0;
+ reset(reset_options::SELECT_FIRST);
+ }
}
-
- // if it's any other key and we're not maxed out, update
- else if (menu_event->unichar >= ' ' && menu_event->unichar < 0x7f)
+ else if (menu_event->is_char_printable())
{
- buflen += utf8_from_uchar(&m_search[buflen], ARRAY_LENGTH(m_search) - buflen, menu_event->unichar);
- m_search[buflen] = 0;
- reset(reset_options::SELECT_FIRST);
+ // if it's any other key and we're not maxed out, update
+ if (menu_event->append_char(m_search, buflen))
+ reset(reset_options::SELECT_FIRST);
}
}