From: Duncan Mac-Vicar P Date: Mon, 23 Jul 2007 08:56:09 +0000 (+0000) Subject: - Implement hasSection and hasEntry in IniDict X-Git-Tag: BASE-SuSE-Linux-10_3-Branch~504 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a40e3992d504c3d049571982f3e0f1c008b30c20;p=platform%2Fupstream%2Flibzypp.git - Implement hasSection and hasEntry in IniDict - test cases --- diff --git a/tests/parser/inifile/inidict_test.cc b/tests/parser/inifile/inidict_test.cc index a8de14a..dcdd4ae 100644 --- a/tests/parser/inifile/inidict_test.cc +++ b/tests/parser/inifile/inidict_test.cc @@ -38,6 +38,11 @@ void ini_read_test(const string &dir) MIL << " - " << (*it2).first << " | " << (*it2).second << endl; } } + + BOOST_CHECK( dict.hasSection("addons") ); + BOOST_CHECK( !dict.hasSection("uhlala") ); + BOOST_CHECK( dict.hasEntry("contrib", "name") ); + BOOST_CHECK( !dict.hasEntry("foo", "bar") ); } void ini_read_test2(const string &dir) diff --git a/zypp/parser/IniDict.cc b/zypp/parser/IniDict.cc index 44ad08d..c1c2153 100644 --- a/zypp/parser/IniDict.cc +++ b/zypp/parser/IniDict.cc @@ -104,6 +104,28 @@ namespace zypp _dict.erase(section); } + bool IniDict::hasSection( const std::string §ion ) const + { + SectionSet::const_iterator secit = _dict.find(section); + if ( secit == _dict.end() ) + return false; + return true; + } + + bool IniDict::hasEntry( const std::string §ion, + const std::string &entry ) const + { + SectionSet::const_iterator secit = _dict.find(section); + if ( secit == _dict.end() ) + return false; + + EntrySet::const_iterator entryit = (secit->second).find(entry); + if ( entryit == (secit->second).end() ) + return false; + + return true; + } + /****************************************************************** ** ** FUNCTION NAME : operator<< diff --git a/zypp/parser/IniDict.h b/zypp/parser/IniDict.h index 1e87f57..23415cf 100644 --- a/zypp/parser/IniDict.h +++ b/zypp/parser/IniDict.h @@ -109,6 +109,22 @@ namespace zypp */ void deleteSection( const std::string §ion ); + /** + * \short True if there is a section with that name + * \param section Section Name + */ + bool hasSection( const std::string §ion ) const; + + /** + * \short True if an entry exists in the section + * \param section Section name + * \param entry entry name + * + * \note If the given section does not exist, this will + * of course return false. + */ + bool hasEntry( const std::string §ion, + const std::string &entry ) const; public: /** Called when a section is found. */