tweaks: elide a small function that is used just once

This commit is contained in:
Benno Schulenberg 2021-04-07 17:08:05 +02:00
parent b6a32fbd5f
commit c75a3839da
3 changed files with 5 additions and 20 deletions

View File

@ -251,21 +251,6 @@ bool is_zerowidth(const char *ch)
{ {
return (use_utf8 && mbwidth(ch) == 0); return (use_utf8 && mbwidth(ch) == 0);
} }
/* Convert the given Unicode value to a multibyte character, if possible.
* If the conversion succeeds, return the (dynamically allocated) multibyte
* character and its length. Otherwise, return a length of zero. */
char *make_mbchar(long code, int *length)
{
char *mb_char = nmalloc(MAXCHARLEN);
*length = wctomb(mb_char, (wchar_t)code);
if (*length < 0)
*length = 0;
return mb_char;
}
#endif /* ENABLE_UTF8 */ #endif /* ENABLE_UTF8 */
/* Return the number of bytes in the character that starts at *pointer. */ /* Return the number of bytes in the character that starts at *pointer. */

View File

@ -207,7 +207,6 @@ char control_mbrep(const char *c, bool isdata);
int mbtowide(wchar_t *wc, const char *c); int mbtowide(wchar_t *wc, const char *c);
int mbwidth(const char *c); int mbwidth(const char *c);
bool is_zerowidth(const char *ch); bool is_zerowidth(const char *ch);
char *make_mbchar(long code, int *length);
#endif #endif
int char_length(const char *pointer); int char_length(const char *pointer);
size_t mbstrlen(const char *pointer); size_t mbstrlen(const char *pointer);

View File

@ -1381,7 +1381,7 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *count)
* commence Unicode input. Otherwise, put the code back. */ * commence Unicode input. Otherwise, put the code back. */
if (using_utf8() && (keycode == '0' || keycode == '1')) { if (using_utf8() && (keycode == '0' || keycode == '1')) {
long unicode = assemble_unicode(keycode); long unicode = assemble_unicode(keycode);
char *multibyte; char multibyte[MB_CUR_MAX];
reveal_cursor = FALSE; reveal_cursor = FALSE;
@ -1411,14 +1411,15 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *count)
} }
/* Convert the Unicode value to a multibyte sequence. */ /* Convert the Unicode value to a multibyte sequence. */
multibyte = make_mbchar(unicode, (int *)count); *count = wctomb(multibyte, unicode);
if (*count > MAXCHARLEN)
*count = 0;
/* Change the multibyte character into a series of integers. */ /* Change the multibyte character into a series of integers. */
for (size_t i = 0; i < *count; i++) for (size_t i = 0; i < *count; i++)
yield[i] = (int)multibyte[i]; yield[i] = (int)multibyte[i];
free(multibyte);
return yield; return yield;
} }
#endif /* ENABLE_UTF8 */ #endif /* ENABLE_UTF8 */