libzypp: zypp/ng/sat/solvableident.cc Source File

libzypp 17.38.8

solvableident.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#include "solvableident.h"
10#include <zypp-core/base/String.h>
11#include <cstring>
12
13namespace zyppng::sat
14{
15 namespace
16 {
17 void _doSplit( IdString & _ident, ResKind & _kind, IdString & _name )
18 {
19 if ( ! _ident )
20 return;
21
22 ResKind explicitKind = ResKind::explicitBuiltin( _ident.c_str() );
23 // NOTE: kind package and srcpackage do not have namespaced ident!
24 if ( ! explicitKind )
25 {
26 _name = _ident;
27 // No kind defaults to package
28 if ( !_kind )
29 _kind = ResKind::package;
30 else if ( ! ( _kind == ResKind::package || _kind == ResKind::srcpackage ) )
31 _ident = IdString( zypp::str::form( "%s:%s", _kind.c_str(), _ident.c_str() ) );
32 }
33 else
34 {
35 // strip kind spec from name
36 _name = IdString( ::strchr( _ident.c_str(), ':' )+1 );
37 _kind = explicitKind;
38 if ( _kind == ResKind::package || _kind == ResKind::srcpackage )
39 _ident = _name;
40 }
41 return;
42 }
43 } // namespace
44
45 SplitIdent::SplitIdent( IdString ident_r )
46 : _ident( ident_r )
47 { _doSplit( _ident, _kind, _name ); }
48
49 SplitIdent::SplitIdent( const char * ident_r )
50 : _ident( ident_r )
51 { _doSplit( _ident, _kind, _name ); }
52
53 SplitIdent::SplitIdent( const std::string & ident_r )
54 : _ident( ident_r )
55 { _doSplit( _ident, _kind, _name ); }
56
57 SplitIdent::SplitIdent( ResKind kind_r, IdString name_r )
58 : _ident( name_r )
59 , _kind(std::move( kind_r ))
60 { _doSplit( _ident, _kind, _name ); }
61
62 SplitIdent::SplitIdent( ResKind kind_r, const zypp::C_Str & name_r )
63 : _ident( name_r )
64 , _kind(std::move( kind_r ))
65 { _doSplit( _ident, _kind, _name ); }
66
67} // namespace zyppng::sat
String.h
zypp::C_Str
Convenience char* constructible from std::string and char*, it maps (char*)0 to an empty string.
Definition String.h:92
zypp::IdString
Access to the sat-pools string space.
Definition IdString.h:55
zypp::ResKind
Resolvable kinds.
Definition ResKind.h:33
zypp::ResKind::srcpackage
static const ResKind srcpackage
Definition ResKind.h:44
zypp::ResKind::explicitBuiltin
static ResKind explicitBuiltin(const char *str_r)
Return the builtin kind if str_r explicitly prefixed.
Definition ResKind.cc:46
zypp::ResKind::package
static const ResKind package
Definition ResKind.h:40
zyppng::sat::SplitIdent::_name
IdString _name
Definition solvableident.h:47
zyppng::sat::SplitIdent::_ident
IdString _ident
Definition solvableident.h:45
zyppng::sat::SplitIdent::SplitIdent
SplitIdent()=default
zyppng::sat::SplitIdent::_kind
ResKind _kind
Definition solvableident.h:46
std
Definition ansi.h:855
zypp::str::form
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition String.cc:39
zyppng::sat
This file contains private API, this might break at any time between releases.
Definition capabilities.h:22
zyppng::IdString
zypp::IdString IdString
Definition idstring.h:16
solvableident.h