Skip to content

Commit

Permalink
patch 8.1.0059: displayed digraph for "ga" wrong with 'encoding' "cp1…
Browse files Browse the repository at this point in the history
…251"

Problem:    Displayed digraph for "ga" wrong with 'encoding' "cp1251".
Solution:   Convert from 'encoding' to "utf-8" if needed. (closes #3015)
  • Loading branch information
brammool committed Jun 16, 2018
1 parent bfa4246 commit bc5020a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/digraph.c
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions src/testdir/test_digraph.vim
Expand Up @@ -465,4 +465,16 @@ func Test_show_digraph()
bwipe!
endfunc

func Test_show_digraph_cp1251()
if !has('multi_byte')
return
endif
new
set encoding=cp1251
call Put_Dig("='")
call assert_equal("\n<\xfa> <|z> <M-z> 250, Hex fa, Oct 372, Digr ='", execute('ascii'))
set encoding=utf-8
bwipe!
endfunc

" vim: shiftwidth=2 sts=2 expandtab
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -761,6 +761,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
59,
/**/
58,
/**/
Expand Down

0 comments on commit bc5020a

Please sign in to comment.