aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2018-04-09 01:12:52 +0300
committerZyX <kp-pav@yandex.ru>2018-04-09 10:29:29 +0300
commit93be2ba5422cf08369269fe12567dea04254aa20 (patch)
treed8e3551a711906fb5231e2703753326e9c3ba8e9 /src
parent58a5699a4400d1d706056e456ca641b3e4b0a5e9 (diff)
downloadrneovim-93be2ba5422cf08369269fe12567dea04254aa20.tar.gz
rneovim-93be2ba5422cf08369269fe12567dea04254aa20.tar.bz2
rneovim-93be2ba5422cf08369269fe12567dea04254aa20.zip
charset: Fix transchar() with multibyte characters
It appears that transchar() was working under assumption that `transchar_nonprint()` may be used for multibyte characters while its documentation stated exact opposite. It was not actually untrue though, except that longer buffer would be needed then the one stated in documentation. But it is false now with assert().
Diffstat (limited to 'src')
-rw-r--r--src/nvim/charset.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index d8d080ee8a..aecde29ce2 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -517,14 +517,16 @@ char_u* str_foldcase(char_u *str, int orglen, char_u *buf, int buflen)
// Does NOT work for multi-byte characters, c must be <= 255.
// Also doesn't work for the first byte of a multi-byte, "c" must be a
// character!
-static char_u transchar_buf[7];
+static char_u transchar_buf[11];
-/// Translates a character
+/// Translate a character into a printable one, leaving printable ASCII intact
///
-/// @param c
+/// All unicode characters are considered non-printable in this function.
+///
+/// @param[in] c Character to translate.
///
-/// @return translated character.
-char_u* transchar(int c)
+/// @return translated character into a static buffer.
+char_u *transchar(int c)
{
int i = 0;
if (IS_SPECIAL(c)) {
@@ -537,12 +539,14 @@ char_u* transchar(int c)
if ((!chartab_initialized && (((c >= ' ') && (c <= '~'))
|| (p_altkeymap && F_ischar(c))))
- || ((c < 256) && vim_isprintc_strict(c))) {
+ || ((c <= 0xFF) && vim_isprintc_strict(c))) {
// printable character
transchar_buf[i] = (char_u)c;
transchar_buf[i + 1] = NUL;
- } else {
+ } else if (c <= 0xFF){
transchar_nonprint(transchar_buf + i, c);
+ } else {
+ transchar_hex((char *)transchar_buf + i, c);
}
return transchar_buf;
}