aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-23 17:23:24 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-23 17:23:24 +0100
commit8ea8866114c450dec08322c57f8002b29eee19d3 (patch)
treeb6a8a41f7cc4d1bfdf363278cec16b3cfaef9feb
parentee56c417f8f8b486f0de2aa3b09a1bf32a377764 (diff)
downloadpaludis-8ea8866114c450dec08322c57f8002b29eee19d3.tar.gz
paludis-8ea8866114c450dec08322c57f8002b29eee19d3.tar.xz
Parse -X0 as -X 0 rather than -X -0
-rw-r--r--paludis/args/args_handler.cc18
-rw-r--r--paludis/args/args_visitor.cc25
-rw-r--r--paludis/args/args_visitor.hh4
3 files changed, 28 insertions, 19 deletions
diff --git a/paludis/args/args_handler.cc b/paludis/args/args_handler.cc
index 2793719..7e0b15b 100644
--- a/paludis/args/args_handler.cc
+++ b/paludis/args/args_handler.cc
@@ -228,14 +228,14 @@ ArgsHandler::run(
if (it == _imp->longopts.end())
throw BadArgument("--no-" + arg);
- char second_char_or_zero('\0');
- ArgsVisitor visitor(&argit, arge, env_prefix, second_char_or_zero, true);
+ std::string remaining_chars;
+ ArgsVisitor visitor(&argit, arge, env_prefix, remaining_chars, true);
it->second->accept(visitor);
}
else
{
- char second_char_or_zero('\0');
- ArgsVisitor visitor(&argit, arge, env_prefix, second_char_or_zero, false);
+ std::string remaining_chars;
+ ArgsVisitor visitor(&argit, arge, env_prefix, remaining_chars, false);
it->second->accept(visitor);
}
}
@@ -245,11 +245,11 @@ ArgsHandler::run(
for (std::string::iterator c = arg.begin(); c != arg.end(); ++c)
{
bool maybe_second_char_used(false);
- char second_char_or_zero('\0');
- if (2 == arg.length() && c == arg.begin())
+ std::string remaining_chars;
+ if (arg.length() >= 2 && c == arg.begin())
{
maybe_second_char_used = true;
- second_char_or_zero = arg[1];
+ remaining_chars = arg.substr(1);
}
std::map<char, ArgsOption *>::iterator it = _imp->shortopts.find(*c);
@@ -258,10 +258,10 @@ ArgsHandler::run(
throw BadArgument(std::string("-") + *c);
}
- ArgsVisitor visitor(&argit, arge, env_prefix, second_char_or_zero, false);
+ ArgsVisitor visitor(&argit, arge, env_prefix, remaining_chars, false);
it->second->accept(visitor);
- if (maybe_second_char_used && '\0' == second_char_or_zero)
+ if (maybe_second_char_used && remaining_chars.empty())
break;
}
}
diff --git a/paludis/args/args_visitor.cc b/paludis/args/args_visitor.cc
index aa0e863..e55497d 100644
--- a/paludis/args/args_visitor.cc
+++ b/paludis/args/args_visitor.cc
@@ -43,19 +43,19 @@ namespace paludis
ArgsHandler::ArgsIterator * args_index;
ArgsHandler::ArgsIterator args_end;
std::string env_prefix;
- char & second_char_or_zero;
+ std::string & remaining_chars;
bool no;
Imp(
ArgsHandler::ArgsIterator * i,
ArgsHandler::ArgsIterator e,
std::string p,
- char & s,
+ std::string & s,
bool n) :
args_index(i),
args_end(e),
env_prefix(p),
- second_char_or_zero(s),
+ remaining_chars(s),
no(n)
{
}
@@ -63,7 +63,7 @@ namespace paludis
}
ArgsVisitor::ArgsVisitor(ArgsHandler::ArgsIterator * ai, ArgsHandler::ArgsIterator ae,
- const std::string & env_prefix, char & s, bool n) :
+ const std::string & env_prefix, std::string & s, bool n) :
Pimp<ArgsVisitor>(ai, ae, env_prefix, s, n)
{
}
@@ -123,7 +123,16 @@ void ArgsVisitor::visit(IntegerArg & arg)
if (! _imp->no)
{
arg.set_specified(true);
- std::string param = get_param(arg);
+ std::string param;
+
+ if ((! _imp->remaining_chars.empty()) && (std::string::npos == _imp->remaining_chars.find_first_not_of("0123456789")))
+ {
+ param = _imp->remaining_chars;
+ _imp->remaining_chars.clear();
+ }
+ else
+ param = get_param(arg);
+
try
{
int a(destringify<int>(param));
@@ -148,10 +157,10 @@ void ArgsVisitor::visit(EnumArg & arg)
arg.set_specified(true);
std::string p;
- if ('\0' != _imp->second_char_or_zero)
+ if (_imp->remaining_chars.length() == 1)
{
- p = std::string(1, _imp->second_char_or_zero);
- _imp->second_char_or_zero = '\0';
+ p = _imp->remaining_chars;
+ _imp->remaining_chars.clear();
}
else
p = get_param(arg);
diff --git a/paludis/args/args_visitor.hh b/paludis/args/args_visitor.hh
index 523ec20..b0d04e1 100644
--- a/paludis/args/args_visitor.hh
+++ b/paludis/args/args_visitor.hh
@@ -68,13 +68,13 @@ namespace paludis
/**
* Constructor
*
- * \since 0.47
+ * \since 0.49
*/
ArgsVisitor(
ArgsHandler::ArgsIterator *,
ArgsHandler::ArgsIterator,
const std::string &,
- char & second_char_or_zero,
+ std::string & remaining_chars,
bool no);
~ArgsVisitor();