provide str::asString for integral types
authorMichael Andres <ma@suse.de>
Sun, 1 Nov 2009 20:50:21 +0000 (21:50 +0100)
committerMichael Andres <ma@suse.de>
Tue, 3 Nov 2009 01:11:32 +0000 (02:11 +0100)
zypp/base/String.cc
zypp/base/String.h

index a101c5b..7cb79d9 100644 (file)
@@ -64,6 +64,7 @@ namespace zypp
               || t == "yes"
               || t == "true"
               || t == "on"
+              || t == "+"
               || strtonum<long long>( str )
             );
     }
@@ -80,6 +81,7 @@ namespace zypp
                  || t == "no"
                  || t == "false"
                  || t == "off"
+                 || t == "-"
                );
     }
 
index 550760a..2d4fbe5 100644 (file)
@@ -124,6 +124,10 @@ namespace zypp
         inline std::string asString( const std::string &t )
         { return t; }
 
+    template<>
+        inline std::string asString( const bool &t )
+        { return t ? "+" : "-"; }
+
     ///////////////////////////////////////////////////////////////////
     /** Printf style construction of std::string. */
     std::string form( const char * format, ... )
@@ -203,6 +207,17 @@ namespace zypp
     inline std::string numstring( unsigned long n,      int w = 0 ) { return form( "%*lu",   w, n ); }
     inline std::string numstring( long long n,          int w = 0 ) { return form( "%*lld",  w, n ); }
     inline std::string numstring( unsigned long long n, int w = 0 ) { return form( "%*llu",  w, n ); }
+
+    template<> inline std::string asString( const char & t )                   { return numstring( t ); }
+    template<> inline std::string asString( const unsigned char & t )          { return numstring( t ); }
+    template<> inline std::string asString( const short & t )                  { return numstring( t ); }
+    template<> inline std::string asString( const unsigned short & t )         { return numstring( t ); }
+    template<> inline std::string asString( const int & t )                    { return numstring( t ); }
+    template<> inline std::string asString( const unsigned & t )               { return numstring( t ); }
+    template<> inline std::string asString( const long & t )                   { return numstring( t ); }
+    template<> inline std::string asString( const unsigned long & t )          { return numstring( t ); }
+    template<> inline std::string asString( const long long & t )              { return numstring( t ); }
+    template<> inline std::string asString( const unsigned long long & t )     { return numstring( t ); }
     //@}
 
     ///////////////////////////////////////////////////////////////////