Mailinglist Archive: zypp-commit (233 mails)

< Previous Next >
[zypp-commit] <libzypp> master : sat::Solvable::SplitIdent: Also split ordinary strings (non IdStrings).
  • From: Michael Andres <ma@xxxxxxx>
  • Date: Mon, 2 Nov 2009 21:33:17 +0100
  • Message-id: <E1N53d6-0005cF-Nq@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit 2211d97494246c8ed754f843c0910eceb75985df
Author: Michael Andres <ma@xxxxxxx>
Date: Mon Nov 2 21:33:17 2009 +0100

sat::Solvable::SplitIdent: Also split ordinary strings (non IdStrings).
---
tests/sat/Solvable_test.cc | 39 ++++++++++++++++++++++++
zypp/sat/Solvable.cc | 71 +++++++++++++++++++++++++++----------------
zypp/sat/Solvable.h | 2 +
3 files changed, 85 insertions(+), 27 deletions(-)

diff --git a/tests/sat/Solvable_test.cc b/tests/sat/Solvable_test.cc
index 0ec48cc..e2655d0 100644
--- a/tests/sat/Solvable_test.cc
+++ b/tests/sat/Solvable_test.cc
@@ -103,3 +103,42 @@ BOOST_AUTO_TEST_CASE(asString)
#endif
}

+BOOST_AUTO_TEST_CASE(SplitIdent)
+{
+ sat::Solvable::SplitIdent split;
+ BOOST_CHECK_EQUAL( split.ident(), IdString() );
+ BOOST_CHECK_EQUAL( split.kind(), ResKind() );
+ BOOST_CHECK_EQUAL( split.name(), IdString() );
+
+ // kind defaults to package
+ split = sat::Solvable::SplitIdent( "foo" );
+ BOOST_CHECK_EQUAL( split.ident(), "foo" );
+ BOOST_CHECK_EQUAL( split.kind(), ResKind::package );
+ BOOST_CHECK_EQUAL( split.name(), "foo" );
+
+ // kind package and srcpackage do not have namespaced ident
+ split = sat::Solvable::SplitIdent( "package:foo" );
+ BOOST_CHECK_EQUAL( split.ident(), "foo" );
+ BOOST_CHECK_EQUAL( split.kind(), ResKind::package );
+ BOOST_CHECK_EQUAL( split.name(), "foo" );
+
+ split = sat::Solvable::SplitIdent( "srcpackage:foo" );
+ BOOST_CHECK_EQUAL( split.ident(), "foo" );
+ BOOST_CHECK_EQUAL( split.kind(), ResKind::srcpackage );
+ BOOST_CHECK_EQUAL( split.name(), "foo" );
+
+ // all other kinds do have namespaced ident
+ split = sat::Solvable::SplitIdent( "patch:foo" );
+ BOOST_CHECK_EQUAL( split.ident(), "patch:foo" );
+ BOOST_CHECK_EQUAL( split.kind(), ResKind::patch );
+ BOOST_CHECK_EQUAL( split.name(), "foo" );
+
+ // all other kinds do have namespaced ident
+ split = sat::Solvable::SplitIdent( "unknownkind:foo" );
+ BOOST_CHECK_EQUAL( split.ident(), "unknownkind:foo" );
+ BOOST_CHECK_EQUAL( split.kind(), ResKind("unknownkind") );
+ BOOST_CHECK_EQUAL( split.name(), "foo" );
+
+}
+
+
diff --git a/zypp/sat/Solvable.cc b/zypp/sat/Solvable.cc
index 7595687..8802ac7 100644
--- a/zypp/sat/Solvable.cc
+++ b/zypp/sat/Solvable.cc
@@ -35,45 +35,62 @@ namespace zypp
namespace sat
{ /////////////////////////////////////////////////////////////////

- Solvable::SplitIdent::SplitIdent( IdString ident_r )
- : _ident( ident_r )
+ namespace
{
- if ( ! ident_r )
- return;
+ void _doSplit( IdString & _ident, ResKind & _kind, IdString & _name )
+ {
+ if ( ! _ident )
+ return;

- const char * ident = ident_r.c_str();
- const char * sep = ::strchr( ident, ':' );
+ const char * ident = _ident.c_str();
+ const char * sep = ::strchr( ident, ':' );

- // no ':' in package names (hopefully)
- if ( ! sep )
- {
- _kind = ResKind::package;
- _name = ident_r;
- return;
- }
+ // no ':' in package names (hopefully)
+ if ( ! sep )
+ {
+ _kind = ResKind::package;
+ _name = _ident;
+ return;
+ }

- // save name
- _name = IdString( sep+1 );
- // quick check for well known kinds
- if ( sep-ident >= 4 )
- {
- switch ( ident[3] )
+ // save name
+ _name = IdString( sep+1 );
+
+ // Quick check for well known kinds.
+ // NOTE: kind package and srcpackage do not
+ // have namespaced ident!
+ if ( sep-ident >= 4 )
{
+ switch ( ident[3] )
+ {
#define OUTS(K,S) if ( !::strncmp( ident, ResKind::K.c_str(), S ) ) _kind =
ResKind::K
// ----v
- case 'c': OUTS( patch, 5 ); return; break;
- case 'd': OUTS( product, 7 ); return; break;
- case 'k': OUTS( package, 7 ); return; break;
- case 'p': OUTS( srcpackage, 10 ); return; break;
- case 't': OUTS( pattern, 7 ); return; break;
+ case 'c': OUTS( patch, 5 ); return; break;
+ case 'd': OUTS( product, 7 ); return; break;
+ case 'k': OUTS( package, 7 ); _ident = _name; return; break;
+ case 'p': OUTS( srcpackage, 10 ); _ident = _name; return; break;
+ case 't': OUTS( pattern, 7 ); return; break;
#undef OUTS
+ }
}
- }

- // an unknown kind
- _kind = ResKind( std::string( ident, sep-ident ) );
+ // an unknown kind
+ _kind = ResKind( std::string( ident, sep-ident ) );
+ }
}

+ Solvable::SplitIdent::SplitIdent( IdString ident_r )
+ : _ident( ident_r )
+ { _doSplit( _ident, _kind, _name ); }
+
+ Solvable::SplitIdent::SplitIdent( const char * ident_r )
+ : _ident( ident_r )
+ { _doSplit( _ident, _kind, _name ); }
+
+ Solvable::SplitIdent::SplitIdent( const std::string & ident_r )
+ : _ident( ident_r )
+ { _doSplit( _ident, _kind, _name ); }
+
Solvable::SplitIdent::SplitIdent( ResKind kind_r, IdString name_r )
: _kind( kind_r )
, _name( name_r )
diff --git a/zypp/sat/Solvable.h b/zypp/sat/Solvable.h
index 8de8d9d..ceb8417 100644
--- a/zypp/sat/Solvable.h
+++ b/zypp/sat/Solvable.h
@@ -251,6 +251,8 @@ namespace zypp
public:
SplitIdent() {}
SplitIdent( IdString ident_r );
+ SplitIdent( const char * ident_r );
+ SplitIdent( const std::string & ident_r );
SplitIdent( ResKind kind_r, IdString name_r );
SplitIdent( ResKind kind_r, const C_Str & name_r );

--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages