Mercurial > vim
diff src/typval.c @ 28718:723c7d940cba
patch 8.2.4883: string interpolation only works in heredoc
Commit: https://github.com/vim/vim/commit/2eaef106e4a7fc9dc74a7e672b5f550ec1f9786e
Author: LemonBoy <thatlemon@gmail.com>
Date: Fri May 6 13:14:50 2022 +0100
patch 8.2.4883: string interpolation only works in heredoc
Problem: String interpolation only works in heredoc.
Solution: Support interpolated strings. Use syntax for heredoc consistent
with strings, similar to C#. (closes #10327)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 06 May 2022 14:15:03 +0200 |
parents | 38f7a132bba3 |
children | d0241e74bfdb |
line wrap: on
line diff
--- a/src/typval.c +++ b/src/typval.c @@ -2266,6 +2266,32 @@ eval_lit_string(char_u **arg, typval_T * return OK; } + int +eval_interp_string(char_u **arg, typval_T *rettv, int evaluate) +{ + typval_T tv; + int ret; + + // *arg is on the '$' character. + (*arg)++; + + rettv->v_type = VAR_STRING; + + if (**arg == '"') + ret = eval_string(arg, &tv, evaluate); + else + ret = eval_lit_string(arg, &tv, evaluate); + + if (ret == FAIL || !evaluate) + return ret; + + rettv->vval.v_string = eval_all_expr_in_str(tv.vval.v_string); + + clear_tv(&tv); + + return rettv->vval.v_string != NULL ? OK : FAIL; +} + /* * Return a string with the string representation of a variable. * If the memory is allocated "tofree" is set to it, otherwise NULL.