Mailinglist Archive: zypp-commit (233 mails)

< Previous Next >
[zypp-commit] <libzypp> master : provide str::asString for integral types
  • From: Michael Andres <ma@xxxxxxx>
  • Date: Tue, 3 Nov 2009 02:11:32 +0100
  • Message-id: <E1N57x6-0001Nn-Fz@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit 238505a4859bdf976bef7006a2e8a81cb5bbb840
Author: Michael Andres <ma@xxxxxxx>
Date: Sun Nov 1 21:50:21 2009 +0100

provide str::asString for integral types
---
zypp/base/String.cc | 2 ++
zypp/base/String.h | 15 +++++++++++++++
2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/zypp/base/String.cc b/zypp/base/String.cc
index a101c5b..7cb79d9 100644
--- a/zypp/base/String.cc
+++ b/zypp/base/String.cc
@@ -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 == "-"
);
}

diff --git a/zypp/base/String.h b/zypp/base/String.h
index 550760a..2d4fbe5 100644
--- a/zypp/base/String.h
+++ b/zypp/base/String.h
@@ -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 ); }
//@}

///////////////////////////////////////////////////////////////////
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages