Adapt ServiceInfo to/from .service
authorMichael Andres <ma@suse.de>
Tue, 9 Sep 2008 15:58:48 +0000 (15:58 +0000)
committerMichael Andres <ma@suse.de>
Tue, 9 Sep 2008 15:58:48 +0000 (15:58 +0000)
devel/devel.ma/NewPool.cc
tests/zypp/base/String_test.cc
zypp/ServiceInfo.cc
zypp/base/String.h
zypp/parser/ServiceFileReader.cc

index 6de4e8c..d64f093 100644 (file)
@@ -43,6 +43,7 @@
 #include "zypp/sat/detail/PoolImpl.h"
 #include "zypp/sat/WhatObsoletes.h"
 #include "zypp/PoolQuery.h"
+#include "zypp/ServiceInfo.h"
 
 #include "zypp/parser/ProductConfReader.h"
 
@@ -442,6 +443,21 @@ try {
   INT << "===[START]==========================================" << endl;
   ZConfig::instance();
 
+  ServiceInfo s( "STest", Url("dir:///somewhere") );
+  DBG << s << endl;
+  s.addCatalogToEnable( "foo" );
+  s.addCatalogToEnable( "ba a" );
+  s.addCatalogToEnable( "kaa" );
+  DBG << s << endl;
+  s.delCatalogToEnable( "kaa" );
+  DBG << s << endl;
+
+  ///////////////////////////////////////////////////////////////////
+  INT << "===[END]============================================" << endl << endl;
+  zypp::base::LogControl::instance().logNothing();
+  return 0;
+
+
   ResPool   pool( ResPool::instance() );
   sat::Pool satpool( sat::Pool::instance() );
 
index 66c1418..e08a9af 100644 (file)
@@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(testsplitEscaped)
   ii = insert_iterator<vector<string> >( v, v.end() );
   splitEscaped( s, ii );
   BOOST_CHECK_EQUAL( v.size(), 1 );
-  BOOST_CHECK_EQUAL( v.front(), string( "escaped sentence " ) ); 
+  BOOST_CHECK_EQUAL( v.front(), string( "escaped sentence " ) );
 
    v.clear();
    s = string( "\"escaped \\\\sent\\\"ence \\\\\"" );
@@ -66,11 +66,24 @@ BOOST_AUTO_TEST_CASE(testsplitEscaped)
    BOOST_CHECK_EQUAL( v.size(), 1 );
    BOOST_CHECK_EQUAL( v.front(), string( "escaped \\sent\"ence \\" ) );
 
-  
+
    v.clear();
    s = string( "escaped sentence\\ with\\ space" );
    ii = insert_iterator<vector<string> >( v, v.end() );
    splitEscaped( s, ii );
    BOOST_CHECK_EQUAL( v.size(), 2 );
    BOOST_CHECK_EQUAL( v[1], string( "sentence with space" ) );
+
+   // split - join
+   v.clear();
+   s = "some line \"\" foo\\ a foo\\\\ b";
+   str::splitEscaped( s, std::back_inserter(v) );
+   BOOST_CHECK_EQUAL( s, str::joinEscaped( v.begin(), v.end() ) );
+
+   // split - join using alternate sepchar
+   s = str::joinEscaped( v.begin(), v.end(), 'o' );
+   v.clear();
+   str::splitEscaped( s, std::back_inserter(v), "o" );
+   BOOST_CHECK_EQUAL( s, str::joinEscaped( v.begin(), v.end(), 'o' ) );
+
 }
index ca66714..0c3ab71 100644 (file)
@@ -12,6 +12,7 @@
 #include <ostream>
 #include <iostream>
 
+#include "zypp/base/String.h"
 #include "zypp/parser/xml/XmlEscape.h"
 
 #include "zypp/RepoInfo.h"
@@ -111,8 +112,10 @@ namespace zypp
 
   std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
   {
-    return RepoInfoBase::dumpAsIniOn(str)
-        << "url = " << url() << endl;
+    RepoInfoBase::dumpAsIniOn(str) << "url = " << url() << endl;
+    if ( ! catalogsToEnableEmpty() )
+      str << "catalogstoenable = " << str::joinEscaped( catalogsToEnableBegin(), catalogsToEnableEnd() ) << endl;
+    return str;
   }
 
   std::ostream & ServiceInfo::dumpAsXMLOn( std::ostream & str) const
index c63022a..68a2cfb 100644 (file)
 #ifndef ZYPP_BASE_STRING_H
 #define ZYPP_BASE_STRING_H
 
+#include <cstring>
+
 #include <iosfwd>
+#include <vector>
 #include <string>
-#include <string.h>
 
+#include "zypp/base/Easy.h"
 #include "zypp/base/PtrTypes.h"
 
 ///////////////////////////////////////////////////////////////////
@@ -342,6 +345,9 @@ namespace zypp
      * Any sequence of characters in \a sepchars_r is treated as
      * delimiter if not inside "" or "" or escaped by \, but not \\.
      * The words are passed to OutputIterator \a result_r.
+     *
+     * \see \ref splitEscaped
+     *
      * \code
      * std::vector<std::string> words;
      * str::splitEscaped( "some line", std::back_inserter(words) )
@@ -515,10 +521,54 @@ namespace zypp
       std::string join( const _Container & cont_r,
                         const C_Str & sep_r = " " )
       { return join( cont_r.begin(), cont_r.end(), sep_r ); }
-    //@}
 
+    /** Join strings using separator \a sep_r, quoting or escaping the values.
+     * Separator defaults to BLANK. Use \ref splitEscaped to restore the
+     * values.
+     */
+    template <class _Iterator>
+      std::string joinEscaped( _Iterator begin, _Iterator end,
+                               const char sep_r = ' ' )
+      {
+        std::vector<char> buf;
+        for ( _Iterator iter = begin; iter != end; ++ iter )
+        {
+          if ( iter != begin )
+            buf.push_back( sep_r );
+
+          if ( iter->empty() )
+          {
+            // empty string goes ""
+            buf.push_back( '"' );
+            buf.push_back( '"' );
+          }
+          else
+          {
+            std::string toadd( asString(*iter) );
+            for_( ch, toadd.begin(), toadd.end() )
+            {
+              switch ( *ch )
+              {
+                case '"':
+                case '\'':
+                case '\\':
+                  buf.push_back( '\\' );
+                  buf.push_back( *ch );
+                  break;
+                default:
+                  if ( *ch == sep_r )
+                    buf.push_back( '\\' );
+                  buf.push_back( *ch );
+              }
+            }
+          }
+        }
+        return std::string( buf.begin(), buf.end() );
+      }
 
+    //@}
     ///////////////////////////////////////////////////////////////////
+
     /** \name Case conversion. */
     //@{
     /** Return lowercase version of \a s
index f198a25..4fe2f00 100644 (file)
@@ -68,6 +68,15 @@ namespace zypp
             service.setEnabled( str::strToTrue( it->second ) );
           else if ( it->first == "autorefresh" )
             service.setAutorefresh( str::strToTrue( it->second ) );
+          else if ( it->first == "catalogstoenable" )
+          {
+            std::vector<std::string> aliases;
+            str::splitEscaped( it->second, std::back_inserter(aliases) );
+            for_( ait, aliases.begin(), aliases.end() )
+            {
+              service.addCatalogToEnable( *ait );
+            }
+          }
           else
             ERR << "Unknown attribute " << it->second << " ignored" << endl;
         }