diff --git a/src/command_manager.cc b/src/command_manager.cc index d37966f8..074b736b 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -262,39 +262,6 @@ TokenList parse(StringView line) return result; } -String expand_token(const Token& token, const Context& context, - ConstArrayView shell_params, - const EnvVarMap& env_vars); - -String expand(StringView str, const Context& context, - ConstArrayView shell_params, - const EnvVarMap& env_vars) -{ - String res; - auto pos = 0_byte; - auto length = str.length(); - while (pos < length) - { - if (str[pos] == '\\') - { - char c = str[++pos]; - if (c != '%' and c != '\\') - res += '\\'; - res += c; - ++pos; - } - else if (str[pos] == '%') - { - Token token = parse_percent_token(str, pos); - res += expand_token(token, context, shell_params, env_vars); - ++pos; - } - else - res += str[pos++]; - } - return res; -} - String expand_token(const Token& token, const Context& context, ConstArrayView shell_params, const EnvVarMap& env_vars) @@ -327,6 +294,35 @@ String expand_token(const Token& token, const Context& context, } +String expand(StringView str, const Context& context, + ConstArrayView shell_params, + const EnvVarMap& env_vars) +{ + String res; + auto pos = 0_byte; + auto length = str.length(); + while (pos < length) + { + if (str[pos] == '\\') + { + char c = str[++pos]; + if (c != '%' and c != '\\') + res += '\\'; + res += c; + ++pos; + } + else if (str[pos] == '%') + { + Token token = parse_percent_token(str, pos); + res += expand_token(token, context, shell_params, env_vars); + ++pos; + } + else + res += str[pos++]; + } + return res; +} + struct command_not_found : runtime_error { command_not_found(StringView command) diff --git a/src/command_manager.hh b/src/command_manager.hh index 46afac26..152b7253 100644 --- a/src/command_manager.hh +++ b/src/command_manager.hh @@ -99,6 +99,10 @@ private: const String& name) const; }; +String expand(StringView str, const Context& context, + ConstArrayView shell_params, + const EnvVarMap& env_vars); + } #endif // command_manager_hh_INCLUDED