Make expand function (that expand %...{} tokens) public

This commit is contained in:
Maxime Coste 2015-05-04 17:08:57 +01:00
parent 7f0588c02c
commit cfdf03ab31
2 changed files with 33 additions and 33 deletions

View File

@ -262,39 +262,6 @@ TokenList parse(StringView line)
return result;
}
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)
@ -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)

View File

@ -99,6 +99,10 @@ private:
const String& name) const;
};
String expand(StringView str, const Context& context,
ConstArrayView<String> shell_params,
const EnvVarMap& env_vars);
}
#endif // command_manager_hh_INCLUDED