diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2021-07-10 21:29:18 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-07-10 21:29:18 +0200 |
commit | a2438132a675be4dde3acbdf03ba1fdb2f09427c (patch) | |
tree | 973f677bea21a7f41bbb9d49ad0038550e6e665b /src/mbyte.c | |
parent | 31e21766d6fb0a386e15ccc8c2192f6a3a210f53 (diff) | |
download | vim-git-a2438132a675be4dde3acbdf03ba1fdb2f09427c.tar.gz |
patch 8.2.3139: functions for string manipulation are spread outv8.2.3139
Problem: Functions for string manipulation are spread out.
Solution: Move string related functions to a new source file. (Yegappan
Lakshmanan, closes #8470)
Diffstat (limited to 'src/mbyte.c')
-rw-r--r-- | src/mbyte.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/mbyte.c b/src/mbyte.c index b2519ecba..6fb046d34 100644 --- a/src/mbyte.c +++ b/src/mbyte.c @@ -4961,6 +4961,37 @@ f_getimstatus(typval_T *argvars UNUSED, typval_T *rettv) rettv->vval.v_number = im_get_status(); # endif } + +/* + * iconv() function + */ + void +f_iconv(typval_T *argvars UNUSED, typval_T *rettv) +{ + char_u buf1[NUMBUFLEN]; + char_u buf2[NUMBUFLEN]; + char_u *from, *to, *str; + vimconv_T vimconv; + + rettv->v_type = VAR_STRING; + rettv->vval.v_string = NULL; + + str = tv_get_string(&argvars[0]); + from = enc_canonize(enc_skip(tv_get_string_buf(&argvars[1], buf1))); + to = enc_canonize(enc_skip(tv_get_string_buf(&argvars[2], buf2))); + vimconv.vc_type = CONV_NONE; + convert_setup(&vimconv, from, to); + + // If the encodings are equal, no conversion needed. + if (vimconv.vc_type == CONV_NONE) + rettv->vval.v_string = vim_strsave(str); + else + rettv->vval.v_string = string_convert(&vimconv, str, NULL); + + convert_setup(&vimconv, NULL, NULL); + vim_free(from); + vim_free(to); +} #endif /* |