tweaks: avoid using toupper() and tolower() where easily possible

Those functions can misbehave for some characters in certain locales.
This commit is contained in:
Benno Schulenberg 2025-05-06 15:57:42 +02:00
parent 8e104117a4
commit d50e8feed9
2 changed files with 9 additions and 8 deletions

View File

@ -756,10 +756,11 @@ void parse_binding(char *ptr, bool dobind)
keycopy = copy_of(keyptr);
/* Uppercase either the second or the first character of the key name. */
if (keycopy[0] == '^')
keycopy[1] = toupper((unsigned char)keycopy[1]);
else
keycopy[0] = toupper((unsigned char)keycopy[0]);
if (keycopy[0] == '^') {
if ('a' <= keycopy[1] && keycopy[1] <= 'z')
keycopy[1] &= 0x5F;
} else if ('a' <= keycopy[0] && keycopy[0] <= 'z')
keycopy[0] &= 0x5F;
/* Verify that the key name is not too short. */
if (keycopy[1] == '\0' || (keycopy[0] == 'M' && keycopy[2] == '\0')) {

View File

@ -1046,8 +1046,8 @@ int parse_kbinput(WINDOW *frame)
meta_key = TRUE;
} else if (waiting_codes == 0 || nextcodes[0] == ESC_CODE ||
(keycode != 'O' && keycode != '[')) {
if (!shifted_metas)
keycode = tolower(keycode);
if ('A' <= keycode && keycode <= 'Z' && !shifted_metas)
keycode |= 0x20;
meta_key = TRUE;
} else
keycode = parse_escape_sequence(keycode);
@ -1105,8 +1105,8 @@ int parse_kbinput(WINDOW *frame)
/* If the first escape arrived alone but not the second, then it
* is a Meta keystroke; otherwise, it is an "Esc Esc control". */
if (first_escape_was_alone && !last_escape_was_alone) {
if (!shifted_metas)
keycode = tolower(keycode);
if ('A' <= keycode && keycode <= 'Z' && !shifted_metas)
keycode |= 0x20;
meta_key = TRUE;
} else
keycode = convert_to_control(keycode);