template<>
const ResKind ResTraits<Application>::kind( ResKind::application );
+ ResKind ResKind::explicitBuiltin( const char * str_r )
+ {
+ if ( str_r && str_r[0] && str_r[1] && str_r[2] )
+ {
+ switch ( str_r[3] )
+ {
+ // NOTE: it needs to be assertd that the separating ':' is present
+ // if a known kind is retuirned. Dependent code relies on this!
+ #define OUTS(K,S) if ( !::strncmp( str_r, ResKind::K.c_str(), S ) && str_r[S] == ':' ) return ResKind::K
+ // ----v
+ case 'c': OUTS( patch, 5 ); break;
+ case 'd': OUTS( product, 7 ); break;
+ case 'k': OUTS( package, 7 ); break;
+ case 'l': OUTS( application, 11 );break;
+ case 'p': OUTS( srcpackage, 10 ); break;
+ case 't': OUTS( pattern, 7 ); break;
+ #undef OUTS
+ }
+ }
+ return nokind;
+ }
+
std::string ResKind::satIdent( const ResKind & refers_r, const std::string & name_r )
{
if ( ! refers_r || refers_r == package || refers_r == srcpackage )
static const ResKind application;
//@}
+ /** Return the builtin kind if \a str_r explicitly prefixed.
+ * \a str_r must start with a builtin kind followed by a \c ':'.
+ * If no builtin kind is detected, \ref nokind is returned,
+ * which usually indicates a \ref package or \ref srcpackage.
+ */
+ static ResKind explicitBuiltin( const char * str_r );
+ /** \overload */
+ static ResKind explicitBuiltin( const std::string & str_r )
+ { return explicitBuiltin( str_r.c_str() ); }
+ /** \overload */
+ static ResKind explicitBuiltin( const IdString & str_r )
+ { return explicitBuiltin( str_r.c_str() ); }
+
public:
/** Default ctor: \ref nokind */
ResKind() {}
if ( ! _ident )
return;
- ResKind explicitKind = Solvable::SplitIdent::explicitKind( _ident.c_str() );
+ ResKind explicitKind = ResKind::explicitBuiltin( _ident.c_str() );
// NOTE: kind package and srcpackage do not have namespaced ident!
if ( ! explicitKind )
{
// No kind defaults to package
if ( !_kind )
_kind = ResKind::package;
- if ( ! ( _kind == ResKind::package || _kind == ResKind::srcpackage ) )
+ else if ( ! ( _kind == ResKind::package || _kind == ResKind::srcpackage ) )
_ident = IdString( str::form( "%s:%s", _kind.c_str(), _ident.c_str() ) );
}
else
, _kind( kind_r )
{ _doSplit( _ident, _kind, _name ); }
- ResKind Solvable::SplitIdent::explicitKind( const char * ident_r )
- {
- if ( ! ident_r )
- return ResKind();
-
- const char * sep = ::strchr( ident_r, ':' );
- if ( ! sep )
- return ResKind();
-
- ResKind ret;
- if ( sep-ident_r >= 4 )
- {
- switch ( ident_r[3] )
- {
- #define OUTS(K,S) if ( !::strncmp( ident_r, ResKind::K.c_str(), S ) && ident_r[S] == ':' ) ret = ResKind::K
- // ----v
- case 'c': OUTS( patch, 5 ); break;
- case 'd': OUTS( product, 7 ); break;
- case 'k': OUTS( package, 7 ); break;
- case 'p': OUTS( srcpackage, 10 ); break;
- case 't': OUTS( pattern, 7 ); break;
- #undef OUTS
- }
- }
- return ret;
- }
-
/////////////////////////////////////////////////////////////////
const Solvable Solvable::noSolvable;
break;
}
+ // either explicitly prefixed...
const char * ident = IdString( _solvable->name ).c_str();
- const char * sep = ::strchr( ident, ':' );
+ ResKind knownKind( ResKind::explicitBuiltin( ident ) );
+ if ( knownKind )
+ return knownKind;
- // no ':' in package names (hopefully)
+ // ...or no ':' in package names (hopefully)...
+ const char * sep = ::strchr( ident, ':' );
if ( ! sep )
- return ResKind::package;
-
- // quick check for well known kinds
- if ( sep-ident >= 4 )
- {
- switch ( ident[3] )
- {
-#define OUTS(K,S) if ( !::strncmp( ident, ResKind::K.c_str(), S ) ) return ResKind::K
- // ----v
- case 'c': OUTS( patch, 5 ); break;
- case 'd': OUTS( product, 7 ); break;
- case 'k': OUTS( package, 7 ); break;
- case 'p': OUTS( srcpackage, 10 ); break;
- case 't': OUTS( pattern, 7 ); break;
-#undef OUTS
- }
- }
+ return ResKind::package;
- // an unknown kind
+ // ...or something unknown.
return ResKind( std::string( ident, sep-ident ) );
}
ResKind kind() const { return _kind; }
IdString name() const { return _name; }
- /** Return an idents explicit kind prefix, or \ref ResKind() if none.
- * Mainly to detect whether a given ident string is explicitly prefixed
- * by a known kind (e.g \c pattern:foo or \c package:foo).
- */
- static ResKind explicitKind( IdString ident_r ) { return explicitKind( ident_r.c_str() ); }
- static ResKind explicitKind( const char * ident_r );
- static ResKind explicitKind( const std::string & ident_r ) { return explicitKind( ident_r.c_str() ); }
-
private:
IdString _ident;
ResKind _kind;