Make expand function (that expand %...{} tokens) public
This commit is contained in:
parent
7f0588c02c
commit
cfdf03ab31
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user