diff src/digraph.c @ 14083:8a9a00357676 v8.1.0059

patch 8.1.0059: displayed digraph for "ga" wrong with 'encoding' "cp1251" commit https://github.com/vim/vim/commit/bc5020aa4d7ef4aea88395eff858f74fc881eab9 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jun 16 17:25:22 2018 +0200 patch 8.1.0059: displayed digraph for "ga" wrong with 'encoding' "cp1251" Problem: Displayed digraph for "ga" wrong with 'encoding' "cp1251". Solution: Convert from 'encoding' to "utf-8" if needed. (closes https://github.com/vim/vim/issues/3015)
author Christian Brabandt <cb@256bit.org>
date Sat, 16 Jun 2018 17:30:06 +0200
parents 81c348d40312
children 27b9a84395b5
line wrap: on
line diff
--- a/src/digraph.c
+++ b/src/digraph.c
@@ -1979,14 +1979,37 @@ do_digraph(int c)
  * If not found return NULL.
  */
     char_u *
-get_digraph_for_char(val)
-    int val;
+get_digraph_for_char(int val_arg)
 {
+    int		val = val_arg;
     int		i;
     int		use_defaults;
     digr_T	*dp;
     static      char_u      r[3];
 
+#if defined(FEAT_MBYTE) && defined(USE_UNICODE_DIGRAPHS)
+    if (!enc_utf8)
+    {
+	char_u	    buf[6], *to;
+	vimconv_T   vc;
+
+	// convert the character from 'encoding' to Unicode
+	i = mb_char2bytes(val, buf);
+	vc.vc_type = CONV_NONE;
+	if (convert_setup(&vc, p_enc, (char_u *)"utf-8") == OK)
+	{
+	    vc.vc_fail = TRUE;
+	    to = string_convert(&vc, buf, &i);
+	    if (to != NULL)
+	    {
+		val = utf_ptr2char(to);
+		vim_free(to);
+	    }
+	    (void)convert_setup(&vc, NULL, NULL);
+	}
+    }
+#endif
+
     for (use_defaults = 0; use_defaults <= 1; use_defaults++)
     {
 	if (use_defaults == 0)