#include "Traits.ih"
// Custom includes
-#include <boost/format.hpp>
#include <senf/Utils/senfassert.hh>
//#include "Traits.mpp"
#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++,"\\");
- else if (rv[i] < ' ' || rv[i] > 126) {
- rv.insert(i+1, (boost::format("x%02x")
- % unsigned(static_cast<unsigned char>(rv[i]))).str().c_str());
- rv[i] = '\\';
- i += 3;
- }
-
- 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)
// Custom includes
#include <sstream>
#include <boost/lexical_cast.hpp>
+#include <boost/format.hpp>
#include <senf/Utils/TypeInfo.hh>
#define prefix_ inline
{
std::stringstream ss;
senf::console::format(value, ss);
+ std::string rv (ss.str());
+
+ if (rv.empty() || ! boost::algorithm::all(rv, CommandParser::isWordChar)) {
+ for (std::string::size_type i (0); i < rv.size(); ++i)
+ if (rv[i] == '"' || rv[i] == '\\')
+ rv.insert(i++,"\\");
+ else if (rv[i] < ' ' || rv[i] > 126) {
+ rv.insert(i+1, (boost::format("x%02x")
+ % unsigned(static_cast<unsigned char>(rv[i]))).str().c_str());
+ rv[i] = '\\';
+ i += 3;
+ }
+
+ rv.insert(0,"\"");
+ rv.push_back('"');
+ return rv;
+ }
+
return ss.str();
}
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);
- };
-
template <> struct ArgumentTraits<char> : public detail::CharArgumentTraits<char> {};
template <> struct ReturnValueTraits<char> : public detail::CharReturnValueTraits<char> {};
template <> struct ArgumentTraits<signed char> : public detail::CharArgumentTraits<signed char> {};