diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2015-05-04 17:08:57 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2015-05-04 17:08:57 +0100 |
| commit | cfdf03ab312c7fbd31603ac18c36a4cd8714080a (patch) | |
| tree | db00ee658a3506b380a52eff30d3d4fddaced294 /src/command_manager.cc | |
| parent | 7f0588c02cac7373490643aebec8083354995a53 (diff) | |
Make expand function (that expand %...{} tokens) public
Diffstat (limited to 'src/command_manager.cc')
| -rw-r--r-- | src/command_manager.cc | 62 |
1 files changed, 29 insertions, 33 deletions
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 @@ -264,39 +264,6 @@ TokenList parse(StringView line) String expand_token(const Token& token, const Context& context, ConstArrayView<String> shell_params, - const EnvVarMap& env_vars); - -String expand(StringView str, const Context& context, - ConstArrayView<String> 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<true>(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<String> shell_params, const EnvVarMap& env_vars) { auto& content = token.content(); @@ -327,6 +294,35 @@ String expand_token(const Token& token, const Context& context, } +String expand(StringView str, const Context& context, + ConstArrayView<String> 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<true>(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) |
