" checkup Florgel, dargel and durgel\n"
" default: (double) 2.1\n"
" text \n"
- " default: (empty)\n"
+ " default: \"\"\n"
"\n"
"Ops fortunate, ops me ut orgia vociferatio contumax per, rudo re loco emitto\n"
"intolerabiliter ita iugo. Subcribo gravo. Devenio luna fonticulus Castanea\n"
typename type::const_iterator const i_end (value.end());
if (i != i_end)
for (;;) {
- senf::console::format(*i, os);
+ os << senf::console::str(*i);
if (++i == i_end)
break;
else
typename type::const_iterator const i_end (value.end());
if (i != i_end)
for (;;) {
- senf::console::format(i->first, os);
- os << "=";
- senf::console::format(i->second, os);
+ os << senf::console::str(i->first)
+ << "="
+ << senf::console::str(i->second);
if (++i == i_end)
break;
else
prefix_ void senf::console::ReturnValueTraits< std::pair<T1,T2> >::format(type const & value,
std::ostream & os)
{
- os << "(";
- senf::console::format(value.first, os);
- os << " ";
- senf::console::format(value.second, os);
- os << ")";
+ os << "(" << senf::console::str(value.first)
+ << " " << senf::console::str(value.second) << ")";
}
#endif
senf::console::root().add("test", dir);
std::map<std::string, int> defv (
- boost::assign::map_list_of("foo",7)("bar",2).to_container(defv));
+ boost::assign::map_list_of("foo bar",7)("bar",2).to_container(defv));
dir.add("test", &mapTest)
.arg("data", "test data", senf::console::kw::default_value = defv);
std::stringstream ss;
parser.parse("test/test; test/test (); "
"test/test (vier=4 fuenf = 5 acht=8 )",
boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
- BOOST_CHECK_EQUAL( ss.str(), "(barfoo 9)\n" "( 0)\n" "(achtfuenfvier 17)\n" );
+ BOOST_CHECK_EQUAL( ss.str(), "(\"barfoo bar\" 9)\n" "(\"\" 0)\n" "(achtfuenfvier 17)\n" ); //
ss.str("");
SENF_CHECK_NO_THROW(
"\n"
"With:\n"
" data test data\n"
- " default: (bar=2 foo=7)\n" );
+ " default: (bar=2 \"foo bar\"=7)\n" );
}
///////////////////////////////cc.e////////////////////////////////////////
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
+prefix_ std::string senf::console::ArgumentTraits<std::string>::str(std::string const & value)
+{
+ if (! value.empty() && boost::algorithm::all(value, CommandParser::isWordChar))
+ return value;
+ else {
+ std::string rv (value);
+ for (std::string::size_type i (0); i < rv.size(); ++i)
+ if (rv[i] == '"' || rv[i] == '\\')
+ rv.insert(i++,"\\");
+ rv.insert(0,"\"");
+ rv.push_back('"');
+ return rv;
+ }
+}
+
prefix_ long senf::console::detail::parseEnum(EnumTable const & table,
ParseCommandInfo::TokensRange const & tokens)
{
}
///////////////////////////////////////////////////////////////////////////
+// senf::console::ArgumentTraits<std::string>
+
+prefix_ void senf::console::ArgumentTraits<std::string>::
+parse(ParseCommandInfo::TokensRange const & tokens, std::string & out)
+{
+ senf_console_parse_argument(tokens,out);
+}
+
+prefix_ std::string senf::console::ArgumentTraits<std::string>::description()
+{
+ return "string";
+}
+
+///////////////////////////////////////////////////////////////////////////
// senf::console::ReturnValueTraits<bool>
prefix_ void senf::console::ReturnValueTraits<bool>::format(bool value, std::ostream & os)
}
template <class Type>
+prefix_ std::string senf::console::str(Type const & value)
+{
+ return ArgumentTraits<Type>::str(value);
+}
+
+template <class Type>
prefix_ void senf::console::format(Type const & value, std::ostream & os)
{
ReturnValueTraits<Type>::format(value, os);
template <class Type>
void parse(ParseCommandInfo::TokensRange const & tokens, Type & out);
+ /** \brief Format value
+
+ This helper will call the correct ArgumentTraits::str function to format \a value
+
+ \see ArgumentTraits
+ */
+ template <class Type>
+ std::string str(Type const & value);
+
+ /** \brief Format return value
+
+ This helper will invoke the correct ReturnValueTraits::format function to write \a value
+ into the \a out stream.
+
+ \see ReturnValueTraits
+ */
template <class Type>
void format(Type const & value, std::ostream & os);
static void format(bool value, std::ostream & os);
};
+ template <>
+ struct ArgumentTraits<std::string>
+ {
+ typedef std::string type;
+ static bool const singleToken = true;
+
+ static void parse(ParseCommandInfo::TokensRange const & tokens, std::string & out);
+ static std::string description();
+ static std::string str(std::string const & value);
+ };
+
#endif
/** \brief Format boolean value as \c true / \c false */
prefix_ void senf::console::ReturnValueTraits< senf::console::ValueRange<T> >::
format(type const & value, std::ostream & os)
{
- os << value.low;
+ os << senf::console::str(value.low);
if (value.low != value.high)
- os << ':' << value.high;
+ os << ':' << senf::console::str(value.high);
}
///////////////////////////////ct.e////////////////////////////////////////