@@ -262,6 +262,7 @@ static void f_libcallnr(typval_T *argvars, typval_T *rettv);
262262static void f_line (typval_T * argvars , typval_T * rettv );
263263static void f_line2byte (typval_T * argvars , typval_T * rettv );
264264static void f_lispindent (typval_T * argvars , typval_T * rettv );
265+ static void f_list2str (typval_T * argvars , typval_T * rettv );
265266static void f_localtime (typval_T * argvars , typval_T * rettv );
266267#ifdef FEAT_FLOAT
267268static void f_log (typval_T * argvars , typval_T * rettv );
@@ -401,6 +402,7 @@ static void f_split(typval_T *argvars, typval_T *rettv);
401402static void f_sqrt (typval_T * argvars , typval_T * rettv );
402403static void f_str2float (typval_T * argvars , typval_T * rettv );
403404#endif
405+ static void f_str2list (typval_T * argvars , typval_T * rettv );
404406static void f_str2nr (typval_T * argvars , typval_T * rettv );
405407static void f_strchars (typval_T * argvars , typval_T * rettv );
406408#ifdef HAVE_STRFTIME
@@ -752,6 +754,7 @@ static struct fst
752754 {"line" , 1 , 1 , f_line },
753755 {"line2byte" , 1 , 1 , f_line2byte },
754756 {"lispindent" , 1 , 1 , f_lispindent },
757+ {"list2str" , 1 , 2 , f_list2str },
755758 {"localtime" , 0 , 0 , f_localtime },
756759#ifdef FEAT_FLOAT
757760 {"log" , 1 , 1 , f_log },
@@ -902,6 +905,7 @@ static struct fst
902905 {"sqrt" , 1 , 1 , f_sqrt },
903906 {"str2float" , 1 , 1 , f_str2float },
904907#endif
908+ {"str2list" , 1 , 2 , f_str2list },
905909 {"str2nr" , 1 , 2 , f_str2nr },
906910 {"strcharpart" , 2 , 3 , f_strcharpart },
907911 {"strchars" , 1 , 2 , f_strchars },
@@ -7849,6 +7853,61 @@ f_lispindent(typval_T *argvars UNUSED, typval_T *rettv)
78497853 rettv -> vval .v_number = -1 ;
78507854}
78517855
7856+ /*
7857+ * "list2str()" function
7858+ */
7859+ static void
7860+ f_list2str (typval_T * argvars , typval_T * rettv )
7861+ {
7862+ list_T * l ;
7863+ listitem_T * li ;
7864+ garray_T ga ;
7865+ int utf8 = FALSE;
7866+
7867+ rettv -> v_type = VAR_STRING ;
7868+ rettv -> vval .v_string = NULL ;
7869+ if (argvars [0 ].v_type != VAR_LIST )
7870+ {
7871+ emsg (_ (e_invarg ));
7872+ return ;
7873+ }
7874+
7875+ l = argvars [0 ].vval .v_list ;
7876+ if (l == NULL )
7877+ return ; // empty list results in empty string
7878+
7879+ if (argvars [1 ].v_type != VAR_UNKNOWN )
7880+ utf8 = (int )tv_get_number_chk (& argvars [1 ], NULL );
7881+
7882+ ga_init2 (& ga , 1 , 80 );
7883+ if (has_mbyte || utf8 )
7884+ {
7885+ char_u buf [MB_MAXBYTES + 1 ];
7886+ int (* char2bytes )(int , char_u * );
7887+
7888+ if (utf8 || enc_utf8 )
7889+ char2bytes = utf_char2bytes ;
7890+ else
7891+ char2bytes = mb_char2bytes ;
7892+
7893+ for (li = l -> lv_first ; li != NULL ; li = li -> li_next )
7894+ {
7895+ buf [(* char2bytes )(tv_get_number (& li -> li_tv ), buf )] = NUL ;
7896+ ga_concat (& ga , buf );
7897+ }
7898+ ga_append (& ga , NUL );
7899+ }
7900+ else if (ga_grow (& ga , list_len (l ) + 1 ) == OK )
7901+ {
7902+ for (li = l -> lv_first ; li != NULL ; li = li -> li_next )
7903+ ga_append (& ga , tv_get_number (& li -> li_tv ));
7904+ ga_append (& ga , NUL );
7905+ }
7906+
7907+ rettv -> v_type = VAR_STRING ;
7908+ rettv -> vval .v_string = ga .ga_data ;
7909+ }
7910+
78527911/*
78537912 * "localtime()" function
78547913 */
@@ -12900,6 +12959,47 @@ f_str2float(typval_T *argvars, typval_T *rettv)
1290012959}
1290112960#endif
1290212961
12962+ /*
12963+ * "str2list()" function
12964+ */
12965+ static void
12966+ f_str2list (typval_T * argvars , typval_T * rettv )
12967+ {
12968+ char_u * p ;
12969+ int utf8 = FALSE;
12970+
12971+ if (rettv_list_alloc (rettv ) == FAIL )
12972+ return ;
12973+
12974+ if (argvars [1 ].v_type != VAR_UNKNOWN )
12975+ utf8 = (int )tv_get_number_chk (& argvars [1 ], NULL );
12976+
12977+ p = tv_get_string (& argvars [0 ]);
12978+
12979+ if (has_mbyte || utf8 )
12980+ {
12981+ int (* ptr2len )(char_u * );
12982+ int (* ptr2char )(char_u * );
12983+
12984+ if (utf8 || enc_utf8 )
12985+ {
12986+ ptr2len = utf_ptr2len ;
12987+ ptr2char = utf_ptr2char ;
12988+ }
12989+ else
12990+ {
12991+ ptr2len = mb_ptr2len ;
12992+ ptr2char = mb_ptr2char ;
12993+ }
12994+
12995+ for ( ; * p != NUL ; p += (* ptr2len )(p ))
12996+ list_append_number (rettv -> vval .v_list , (* ptr2char )(p ));
12997+ }
12998+ else
12999+ for ( ; * p != NUL ; ++ p )
13000+ list_append_number (rettv -> vval .v_list , * p );
13001+ }
13002+
1290313003/*
1290413004 * "str2nr()" function
1290513005 */
0 commit comments