tweaks: make two conditions more direct, and thus elide two functions

Using straightforward comparisons is clearer and faster and shorter.

Again, note that this does not filter out 0x7F (DEL).  But that is
okay, as that code will never be returned from get_kbinput().
master
Benno Schulenberg 2020-02-12 11:34:23 +01:00
parent 6747142cd7
commit 0a31a9aa38
4 changed files with 2 additions and 17 deletions

View File

@ -56,12 +56,6 @@ char *addstrings(char* str1, size_t len1, char* str2, size_t len2)
return str1;
}
/* Return TRUE if the value of c is in byte range, and FALSE otherwise. */
bool is_byte(int c)
{
return ((unsigned int)c == (unsigned char)c);
}
/* This function is equivalent to isalpha() for multibyte characters. */
bool is_alpha_mbchar(const char *c)
{
@ -110,13 +104,6 @@ bool is_blank_mbchar(const char *c)
return isblank((unsigned char)*c);
}
/* This function is equivalent to iscntrl(), except in that it only
* handles non-high-bit control characters. */
bool is_ascii_cntrl_char(int c)
{
return (0 <= c && c < 32);
}
/* This function is equivalent to iscntrl() for multibyte characters,
* except in that it also handles multibyte control characters with
* their high bits set. */

View File

@ -1531,7 +1531,7 @@ void do_input(void)
/* If we got a non-high-bit control key, a meta key sequence, or a
* function key, and it's not a shortcut or toggle, throw it out. */
if (shortcut == NULL) {
if (is_ascii_cntrl_char(input) || meta_key || !is_byte(input)) {
if (input < 0x20 || input > 0xFF || meta_key) {
unbound_key(input);
input = ERR;
}

View File

@ -90,7 +90,7 @@ int do_statusbar_input(bool *finished)
/* If we got a non-high-bit control key, a meta key sequence, or a
* function key, and it's not a shortcut or toggle, throw it out. */
if (shortcut == NULL) {
if (is_ascii_cntrl_char(input) || meta_key || !is_byte(input)) {
if (input < 0x20 || input > 0xFF || meta_key) {
beep();
input = ERR;
}

View File

@ -204,10 +204,8 @@ void utf8_init(void);
bool using_utf8(void);
#endif
char *addstrings(char* str1, size_t len1, char* str2, size_t len2);
bool is_byte(int c);
bool is_alpha_mbchar(const char *c);
bool is_blank_mbchar(const char *c);
bool is_ascii_cntrl_char(int c);
bool is_cntrl_mbchar(const char *c);
bool is_word_mbchar(const char *c, bool allow_punct);
char control_mbrep(const char *c, bool isdata);