From 2688551762d93de3cb352ddd4169d0c9d08ad266 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Fri, 28 Aug 2009 16:36:06 +0200 Subject: [PATCH] Provide non-throwing Rel::parseFrom(std::string) --- zypp/Rel.cc | 11 +++++++++++ zypp/Rel.h | 9 +++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/zypp/Rel.cc b/zypp/Rel.cc index 089ca7c..1839c63 100644 --- a/zypp/Rel.cc +++ b/zypp/Rel.cc @@ -86,6 +86,17 @@ namespace zypp : _op( parse( strval_r, default_r ) ) {} + bool Rel::parseFrom( const std::string & strval_r ) + { + std::map::const_iterator it = findStr( strval_r ); + if ( it == _table.end() ) + { + return false; + } + _op = it->second; + return true; + } + /////////////////////////////////////////////////////////////////// // // METHOD NAME : Rel::asString diff --git a/zypp/Rel.h b/zypp/Rel.h index a5ca5f8..1162abe 100644 --- a/zypp/Rel.h +++ b/zypp/Rel.h @@ -87,15 +87,20 @@ namespace zypp * * \throw PARSE if \a strval_r is not legal. * \todo refine exceptions and check throw. - */ + */ explicit Rel( const std::string & strval_r ); /** Ctor from string (non-throwing). * Illegal string values resolve to \c default_r - */ + */ Rel( const std::string & strval_r, const Rel & default_r ); + /** Assign from string IFF it contains a legal value. + * \return Whether \a strval_r contained a legal value. + */ + bool parseFrom( const std::string & strval_r ); + /** Ctor from bits. */ explicit Rel( unsigned bits_r ) -- 2.7.4