Author: mlandres
Date: Tue Sep 9 17:58:48 2008
New Revision: 10982
URL: http://svn.opensuse.org/viewcvs/zypp?rev=10982&view=rev
Log:
Adapt ServiceInfo to/from .service
Modified:
trunk/libzypp/devel/devel.ma/NewPool.cc
trunk/libzypp/tests/zypp/base/String_test.cc
trunk/libzypp/zypp/ServiceInfo.cc
trunk/libzypp/zypp/base/String.h
trunk/libzypp/zypp/parser/ServiceFileReader.cc
Modified: trunk/libzypp/devel/devel.ma/NewPool.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.ma/NewPool.cc?rev=10982&r1=10981&r2=10982&view=diff
==============================================================================
--- trunk/libzypp/devel/devel.ma/NewPool.cc (original)
+++ trunk/libzypp/devel/devel.ma/NewPool.cc Tue Sep 9 17:58:48 2008
@@ -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 @@
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() );
Modified: trunk/libzypp/tests/zypp/base/String_test.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/base/String_test.cc?rev=10982&r1=10981&r2=10982&view=diff
==============================================================================
--- trunk/libzypp/tests/zypp/base/String_test.cc (original)
+++ trunk/libzypp/tests/zypp/base/String_test.cc Tue Sep 9 17:58:48 2008
@@ -57,7 +57,7 @@
ii = insert_iterator( 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_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( 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' ) );
+
}
Modified: trunk/libzypp/zypp/ServiceInfo.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/ServiceInfo.cc?rev=10982&r1=10981&r2=10982&view=diff
==============================================================================
--- trunk/libzypp/zypp/ServiceInfo.cc (original)
+++ trunk/libzypp/zypp/ServiceInfo.cc Tue Sep 9 17:58:48 2008
@@ -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 @@
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
Modified: trunk/libzypp/zypp/base/String.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/base/String.h?rev=10982&r1=10981&r2=10982&view=diff
==============================================================================
--- trunk/libzypp/zypp/base/String.h (original)
+++ trunk/libzypp/zypp/base/String.h Tue Sep 9 17:58:48 2008
@@ -12,10 +12,13 @@
#ifndef ZYPP_BASE_STRING_H
#define ZYPP_BASE_STRING_H
+#include <cstring>
+
#include <iosfwd>
+#include <vector>
#include <string>
-#include
+#include "zypp/base/Easy.h"
#include "zypp/base/PtrTypes.h"
///////////////////////////////////////////////////////////////////
@@ -342,6 +345,9 @@
* 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::vectorstd::string words;
* str::splitEscaped( "some line", std::back_inserter(words) )
@@ -515,10 +521,54 @@
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
Modified: trunk/libzypp/zypp/parser/ServiceFileReader.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/ServiceFileReader.cc?rev=10982&r1=10981&r2=10982&view=diff
==============================================================================
--- trunk/libzypp/zypp/parser/ServiceFileReader.cc (original)
+++ trunk/libzypp/zypp/parser/ServiceFileReader.cc Tue Sep 9 17:58:48 2008
@@ -68,6 +68,15 @@
service.setEnabled( str::strToTrue( it->second ) );
else if ( it->first == "autorefresh" )
service.setAutorefresh( str::strToTrue( it->second ) );
+ else if ( it->first == "catalogstoenable" )
+ {
+ std::vectorstd::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;
}
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org