From: g0dil Date: Mon, 16 Nov 2009 11:42:35 +0000 (+0000) Subject: Utils/Console: generic ArgumentTraits::str() quoting X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=0e83cd2ee1ebc409cf73d8774b01bf01f3df22f4;p=senf.git Utils/Console: generic ArgumentTraits::str() quoting git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1529 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Utils/Console/Traits.cc b/senf/Utils/Console/Traits.cc index 64daded..6f75d60 100644 --- a/senf/Utils/Console/Traits.cc +++ b/senf/Utils/Console/Traits.cc @@ -27,35 +27,12 @@ #include "Traits.ih" // Custom includes -#include #include //#include "Traits.mpp" #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -prefix_ std::string senf::console::ArgumentTraits::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(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) { diff --git a/senf/Utils/Console/Traits.cci b/senf/Utils/Console/Traits.cci index 4386af1..6625e60 100644 --- a/senf/Utils/Console/Traits.cci +++ b/senf/Utils/Console/Traits.cci @@ -70,20 +70,6 @@ prefix_ std::string senf::console::ArgumentTraits::str(bool value) } /////////////////////////////////////////////////////////////////////////// -// senf::console::ArgumentTraits - -prefix_ void senf::console::ArgumentTraits:: -parse(ParseCommandInfo::TokensRange const & tokens, std::string & out) -{ - senf_console_parse_argument(tokens,out); -} - -prefix_ std::string senf::console::ArgumentTraits::description() -{ - return "string"; -} - -/////////////////////////////////////////////////////////////////////////// // senf::console::ReturnValueTraits prefix_ void senf::console::ReturnValueTraits::format(bool value, std::ostream & os) diff --git a/senf/Utils/Console/Traits.cti b/senf/Utils/Console/Traits.cti index 2d9c65a..224f57f 100644 --- a/senf/Utils/Console/Traits.cti +++ b/senf/Utils/Console/Traits.cti @@ -28,6 +28,7 @@ // Custom includes #include #include +#include #include #define prefix_ inline @@ -88,6 +89,24 @@ prefix_ std::string senf::console::ArgumentTraits::str(Type const & value) { 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(rv[i]))).str().c_str()); + rv[i] = '\\'; + i += 3; + } + + rv.insert(0,"\""); + rv.push_back('"'); + return rv; + } + return ss.str(); } diff --git a/senf/Utils/Console/Traits.hh b/senf/Utils/Console/Traits.hh index 19565b8..a42893c 100644 --- a/senf/Utils/Console/Traits.hh +++ b/senf/Utils/Console/Traits.hh @@ -238,17 +238,6 @@ namespace console { static void format(bool value, std::ostream & os); }; - template <> - struct ArgumentTraits - { - 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 : public detail::CharArgumentTraits {}; template <> struct ReturnValueTraits : public detail::CharReturnValueTraits {}; template <> struct ArgumentTraits : public detail::CharArgumentTraits {};