#include "zypp/sat/detail/PoolImpl.h"
#include "zypp/sat/WhatObsoletes.h"
#include "zypp/PoolQuery.h"
+#include "zypp/ServiceInfo.h"
#include "zypp/parser/ProductConfReader.h"
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() );
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 \\\\\"" );
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' ) );
+
}
#include <ostream>
#include <iostream>
+#include "zypp/base/String.h"
#include "zypp/parser/xml/XmlEscape.h"
#include "zypp/RepoInfo.h"
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
#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"
///////////////////////////////////////////////////////////////////
* 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) )
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
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;
}