aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/mbyte.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-04-26 00:23:11 +0800
committerGitHub <noreply@github.com>2023-04-26 00:23:11 +0800
commit907018e547c9b989781667d2cf951e1abf99ab9d (patch)
tree23f7f371bc8a4fb7e2968efc01dd9ab9aa08a7b9 /src/nvim/mbyte.c
parent7e0d66801297677ecbb6b35d0c9139e672920be4 (diff)
downloadrneovim-907018e547c9b989781667d2cf951e1abf99ab9d.tar.gz
rneovim-907018e547c9b989781667d2cf951e1abf99ab9d.tar.bz2
rneovim-907018e547c9b989781667d2cf951e1abf99ab9d.zip
vim-patch:8.2.3139: functions for string manipulation are spread out (#23316)
Problem: Functions for string manipulation are spread out. Solution: Move string related functions to a new source file. (Yegappan Lakshmanan, closes vim/vim#8470) https://github.com/vim/vim/commit/a2438132a675be4dde3acbdf03ba1fdb2f09427c Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src/nvim/mbyte.c')
-rw-r--r--src/nvim/mbyte.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index ab787524a9..78204b22a8 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -2361,6 +2361,34 @@ static char *iconv_string(const vimconv_T *const vcp, const char *str, size_t sl
return result;
}
+/// iconv() function
+void f_iconv(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
+{
+ vimconv_T vimconv;
+
+ rettv->v_type = VAR_STRING;
+ rettv->vval.v_string = NULL;
+
+ const char *const str = tv_get_string(&argvars[0]);
+ char buf1[NUMBUFLEN];
+ char *const from = enc_canonize(enc_skip((char *)tv_get_string_buf(&argvars[1], buf1)));
+ char buf2[NUMBUFLEN];
+ char *const to = enc_canonize(enc_skip((char *)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 = xstrdup(str);
+ } else {
+ rettv->vval.v_string = string_convert(&vimconv, (char *)str, NULL);
+ }
+
+ convert_setup(&vimconv, NULL, NULL);
+ xfree(from);
+ xfree(to);
+}
+
/// Setup "vcp" for conversion from "from" to "to".
/// The names must have been made canonical with enc_canonize().
/// vcp->vc_type must have been initialized to CONV_NONE.