Commit 3f58f69c authored by Samuel Newbold's avatar Samuel Newbold

escaping empty strings when adding to elipsis variables

parent 099f13e8
......@@ -1575,6 +1575,14 @@ $a -x (fi rst) second
b: fi rst
c: second
0
$a -x () (fi rst) second
-*(-x () (fi rst)) -x(-x () (fi rst)) b((fi rst)) c(second)
-*: -xfi rst
-x: -xfi rst
b: fi rst
c: second
0
$a -x first (sec ond) third
-*(-x first (sec ond)) -x(-x first (sec ond)) b((sec ond)) c(third)
......@@ -1626,6 +1634,11 @@ $a (fi rst) (sec ond) third fourth
-*() x((fi rst) (sec ond)) y(third) z(fourth)
x: fi rstsec ond
0
$a () (sec ond) third fourth
-*() x(() (sec ond)) y(third) z(fourth)
x: sec ond
0
$a (fi rst) (sec ond) (thi rd) (fou rth) (fi fth)
-*() x((fi rst) (sec ond) (thi rd)) y(fou rth) z(fi fth)
......@@ -2793,7 +2806,7 @@ $w rwsh.mapped_argfunction {@a @$a @$1 @$* @$*2}
$w rwsh.mapped_argfunction {>dummy_file}
{>dummy_file}
0
$# jkl jkl
$# new tests here
0
$w rwsh.mapped_argfunction {{&&{&&x &&{e}} {&&&x &&&{e} {&&&&x &&&&{e}}}}}
......
......@@ -452,6 +452,7 @@ w a
a first
a -x first
a -x (fi rst) second
a -x () (fi rst) second
a -x first (sec ond) third
a -x (fi rst) (sec ond) third fourth
.function_some_flags a x [... y z] {
......@@ -464,6 +465,7 @@ a (fi rst)
a (fi rst) second
a first (sec ond) third
a (fi rst) (sec ond) third fourth
a () (sec ond) third fourth
a (fi rst) (sec ond) (thi rd) (fou rth) (fi fth)
.function_some_flags a [x] [... y] {
for &&{.list_locals}$ {.combine $1 \( $$1 \) \ }}
......
......@@ -52,8 +52,3 @@ recurse a b c d e f g h i j k l m n o p q r s t u v w x y z
# recurse ((((((((a b))) (c d)) (e f)) (g h)) (i j)) k l) m n (o (p (q (r (s (t (u (v (w (x (y z)))))))))))
recurse (a b) ((c d e) ((f g h) ((i j k) ((l m n) ((o p q) ((r s t) ((u v w) ((x y z)))))))))
.function_flag_ignorant echo text ... {.echo $text $nl}
.function e {.echo $*}
.echo ( ) () x
echo ( ) () x
e ( ) () x
......@@ -18,6 +18,14 @@
char** env;
namespace {
std::string word_from_value(const std::string& value) {
if (value == "") return std::string("()");
else if (value.find_first_of(" \t\n") != std::string::npos)
return "(" + value + ")";
else return value;}
} // close unnamed namespace
Variable_map::Variable_map(Variable_map* parent_i) : parent(parent_i) {
if (parent_i == NULL) {
local("?", "");
......@@ -26,28 +34,22 @@ Variable_map::Variable_map(Variable_map* parent_i) : parent(parent_i) {
void Variable_map::append_word_locally(const std::string& key,
const std::string& value) {
std::string word(value.find_first_of(" \t\n") == std::string::npos?
value: "(" + value + ")");
std::map<std::string, std::string>::iterator i = find(key);
if (i == end()) throw Signal_argm(Argm::Undefined_variable, key);
else i->second += " " + word;}
else i->second += " " + word_from_value(value);}
void Variable_map::append_word_if_exists(const std::string& key,
const std::string& value) {
std::string word(value.find_first_of(" \t\n") == std::string::npos?
value: "(" + value + ")");
std::map<std::string, std::string>::iterator i = find(key);
if (i == end()) return;
else if (i->second == "") i->second = word;
else i->second += " " + word;}
else if (i->second == "") i->second = word_from_value(value);
else i->second += " " + word_from_value(value);}
void Variable_map::local_or_append_word(const std::string& key,
const std::string& value) {
std::string word(value.find_first_of(" \t\n") == std::string::npos?
value: "(" + value + ")");
std::map<std::string, std::string>::iterator i = find(key);
if (i == end()) local(key, word);
else i->second += " " + word;}
if (i == end()) local(key, word_from_value(value));
else i->second += " " + word_from_value(value);}
bool Variable_map::exists(const std::string& key) const {
std::map<std::string, std::string>::const_iterator i = find(key);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment