mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-21 15:40:21 +00:00
Key control: correctly print UTF-8
This commit is contained in:
@@ -289,6 +289,29 @@ static int64_t convert_win_to_ansi_keycode(int c) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool is_utf8(int64_t ch) {
|
||||
#ifdef WIN32
|
||||
return false;
|
||||
#endif
|
||||
|
||||
unsigned char first_byte;
|
||||
while (ch != 0) {
|
||||
first_byte = ch & 0xff;
|
||||
ch >>= 8;
|
||||
}
|
||||
return first_byte & 0x80; /// @todo UTF-8 validity check would be nice
|
||||
}
|
||||
|
||||
static string get_utf8_representation(int64_t ch) {
|
||||
char str[9] = "";
|
||||
while (ch != 0) {
|
||||
memmove(str + 1, str, 8);
|
||||
str[0] = ch & 0xff;
|
||||
ch >>= 8;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
static string get_keycode_representation(int64_t ch) {
|
||||
switch (ch) {
|
||||
case K_UP: return "KEY_UP";
|
||||
@@ -303,6 +326,10 @@ static string get_keycode_representation(int64_t ch) {
|
||||
return string(1, ch);
|
||||
}
|
||||
|
||||
if (is_utf8(ch)) {
|
||||
return get_utf8_representation(ch);
|
||||
}
|
||||
|
||||
stringstream oss;
|
||||
oss << "0x" << hex << ch;
|
||||
return oss.str();
|
||||
|
||||
Reference in New Issue
Block a user