diff src/screen.c @ 25978:40b17deb294f v8.2.3522

patch 8.2.3522: cannot use x and u when setting 'listchars' Commit: https://github.com/vim/vim/commit/93ff6720fe4427341bc426b6d46e6324f226c270 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 16 17:51:40 2021 +0100 patch 8.2.3522: cannot use \x and \u when setting 'listchars' Problem: Cannot use \x and \u when setting 'listchars'. Solution: Support hex and unicode in hex form. (closes https://github.com/vim/vim/issues/9006)
author Bram Moolenaar <Bram@vim.org>
date Sat, 16 Oct 2021 19:00:03 +0200
parents bf09d07f098e
children 7b07f361b1d4
line wrap: on
line diff
--- a/src/screen.c
+++ b/src/screen.c
@@ -4777,6 +4777,35 @@ screen_screenrow(void)
 #endif
 
 /*
+ * Calls mb_ptr2char_adv(p) and returns the character.
+ * If "p" starts with "\x", "\u" or "\U" the hex or unicode value is used.
+ */
+    static int
+get_encoded_char_adv(char_u **p)
+{
+    char_u *s = *p;
+
+    if (s[0] == '\\' && (s[1] == 'x' || s[1] == 'u' || s[1] == 'U'))
+    {
+	varnumber_T num = 0;
+	int	    bytes;
+	int	    n;
+
+	for (bytes = s[1] == 'x' ? 1 : s[1] == 'u' ? 2 : 4; bytes > 0; --bytes)
+	{
+	    *p += 2;
+	    n = hexhex2nr(*p);
+	    if (n < 0)
+		return 0;
+	    num = num * 256 + n;
+	}
+	*p += 2;
+	return num;
+    }
+    return mb_ptr2char_adv(p);
+}
+
+/*
  * Handle setting 'listchars' or 'fillchars'.
  * Assume monocell characters.
  * Returns error message, NULL if it's OK.
@@ -4884,19 +4913,19 @@ set_chars_option(win_T *wp, char_u **var
 		{
 		    c2 = c3 = 0;
 		    s = p + len + 1;
-		    c1 = mb_ptr2char_adv(&s);
+		    c1 = get_encoded_char_adv(&s);
 		    if (mb_char2cells(c1) > 1)
 			return e_invarg;
 		    if (tab[i].cp == &lcs_chars.tab2)
 		    {
 			if (*s == NUL)
 			    return e_invarg;
-			c2 = mb_ptr2char_adv(&s);
+			c2 = get_encoded_char_adv(&s);
 			if (mb_char2cells(c2) > 1)
 			    return e_invarg;
 			if (!(*s == ',' || *s == NUL))
 			{
-			    c3 = mb_ptr2char_adv(&s);
+			    c3 = get_encoded_char_adv(&s);
 			    if (mb_char2cells(c3) > 1)
 				return e_invarg;
 			}
@@ -4938,7 +4967,7 @@ set_chars_option(win_T *wp, char_u **var
 			multispace_len = 0;
 			while (*s != NUL && *s != ',')
 			{
-			    c1 = mb_ptr2char_adv(&s);
+			    c1 = get_encoded_char_adv(&s);
 			    if (mb_char2cells(c1) > 1)
 				return e_invarg;
 			    ++multispace_len;
@@ -4954,7 +4983,7 @@ set_chars_option(win_T *wp, char_u **var
 
 			while (*s != NUL && *s != ',')
 			{
-			    c1 = mb_ptr2char_adv(&s);
+			    c1 = get_encoded_char_adv(&s);
 			    if (p == last_multispace)
 				lcs_chars.multispace[multispace_pos++] = c1;
 			}