[zypp-devel] JFYI: Parsing boolean from string
zypp/base/String.h + /** Parsing boolean from string. + */ + //@{ + /** Return \c true if str is <tt>1, true, yes, on</tt>. */ + bool strToTrue( const std::string & str ); + + /** Return \c false if str is <tt>0, false, no, off</tt>. */ + bool strToFalse( const std::string & str ); + + /** Parse \c str into a bool depending on the default value. + * If the \c default is true, look for a legal \c false string. + * If the \c default is false, look for a legal \c true string. + */ + inline bool strToBool( const std::string & str, bool default_r ) + { return( default_r ? strToFalse( str ) : strToTrue( str ) ); } + //@} bool flag = str::strToBool( "1", false ); -> true bool flag = str::strToBool( "Yes", false ); -> true bool flag = str::strToBool( "on", false ); -> true bool flag = str::strToBool( "true", false ); -> true bool flag = str::strToBool( "otherwise",false ); -> false bool flag = str::strToBool( "0", true ); -> false bool flag = str::strToBool( "no", true ); -> false bool flag = str::strToBool( "OFF", true ); -> false bool flag = str::strToBool( "False", true ); -> false bool flag = str::strToBool( "otherwise",true ); -> true -- cu, Michael Andres +------------------------------------------------------------------+ Key fingerprint = 2DFA 5D73 18B1 E7EF A862 27AC 3FB8 9E3A 27C6 B0E4 +------------------------------------------------------------------+ Michael Andres YaST Development ma@novell.com SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nuernberg) Maxfeldstrasse 5, D-90409 Nuernberg, Germany, ++49 (0)911 - 740 53-0 +------------------------------------------------------------------+ -- To unsubscribe, e-mail: zypp-devel+unsubscribe@opensuse.org For additional commands, e-mail: zypp-devel+help@opensuse.org
participants (1)
-
Michael Andres