- Implement hasSection and hasEntry in IniDict
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 23 Jul 2007 08:56:09 +0000 (08:56 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 23 Jul 2007 08:56:09 +0000 (08:56 +0000)
- test cases

tests/parser/inifile/inidict_test.cc
zypp/parser/IniDict.cc
zypp/parser/IniDict.h

index a8de14a..dcdd4ae 100644 (file)
@@ -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)
index 44ad08d..c1c2153 100644 (file)
@@ -104,6 +104,28 @@ namespace zypp
       _dict.erase(section);
     }
     
+    bool IniDict::hasSection( const std::string &section ) const
+    {
+      SectionSet::const_iterator secit = _dict.find(section);
+      if ( secit == _dict.end() )
+        return false;
+      return true;
+    }
+
+    bool IniDict::hasEntry( const std::string &section,
+                            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<<
index 1e87f57..23415cf 100644 (file)
@@ -109,6 +109,22 @@ namespace zypp
        */
       void deleteSection( const std::string &section );
 
+      /**
+       * \short True if there is a section with that name
+       * \param section Section Name
+       */
+      bool hasSection( const std::string &section ) 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 &section,
+                     const std::string &entry ) const;
     public:
 
       /** Called when a section is found. */