13#include <zypp/base/Logger.h>
15#include <zypp/base/String.h>
16#include <zypp/base/Regex.h>
17#include <zypp/base/Gettext.h>
18#include <zypp/base/Exception.h>
25#include <zypp/sat/detail/PoolImpl.h>
40 template <
unsigned TLen = 5>
44 std::string & getNext()
53 inline std::string::size_type backskipWs(
const std::string & str_r, std::string::size_type pos_r )
55 for ( ; pos_r != std::string::npos; --pos_r )
57 char ch = str_r[pos_r];
58 if ( ch !=
' ' && ch !=
'\t' )
65 inline std::string::size_type backskipNWs(
const std::string & str_r, std::string::size_type pos_r )
67 for ( ; pos_r != std::string::npos; --pos_r )
69 char ch = str_r[pos_r];
70 if ( ch ==
' ' || ch ==
'\t' )
77 void splitOpEdition( std::string & str_r, Rel & op_r, Edition & ed_r )
81 std::string::size_type ch( str_r.size()-1 );
84 if ( (ch = backskipWs( str_r, ch )) != std::string::npos )
86 std::string::size_type ee( ch );
87 if ( (ch = backskipNWs( str_r, ch )) != std::string::npos )
89 std::string::size_type eb( ch );
90 if ( (ch = backskipWs( str_r, ch )) != std::string::npos )
92 std::string::size_type oe( ch );
93 ch = backskipNWs( str_r, ch );
94 if ( op_r.parseFrom( str_r.substr( ch+1, oe-ch ) ) )
97 ed_r = Edition( str_r.substr( eb+1, ee-eb ) );
98 if ( ch != std::string::npos )
99 ch = backskipWs( str_r, ch );
109 ch = str_r.find_last_of(
"<=>)" );
110 if ( ch != std::string::npos && str_r[ch] !=
')' )
112 std::string::size_type oe( ch );
115 ch = str_r.find_first_not_of(
" \t", oe+1 );
116 if ( ch != std::string::npos )
117 ed_r = Edition( str_r.substr( ch ) );
121 if ( str_r[oe] !=
'=' )
127 if ( ch != std::string::npos )
131 case '<': --ch; op_r =
Rel::LE;
break;
132 case '>': --ch; op_r =
Rel::GE;
break;
133 case '!': --ch; op_r =
Rel::NE;
break;
135 default: op_r =
Rel::EQ;
break;
141 if ( ch != std::string::npos )
142 ch = backskipWs( str_r, ch );
153 const std::string & name_r,
155 const Edition & ed_r,
156 const ResKind & kind_r )
159 sat::Solvable::SplitIdent
split( kind_r, name_r );
166 nid = ::pool_rel2id( pool_r, nid, IdString(ARCH_SRC).
id(), REL_ARCH,
true );
172 nid = ::pool_rel2id( pool_r, nid, arch_r.id(), REL_ARCH,
true );
178 nid = ::pool_rel2id( pool_r, nid, ed_r.id(), op_r.bits(),
true );
188 const std::string & name_r, Rel op_r,
const Edition & ed_r,
189 const ResKind & kind_r )
191 static const Arch srcArch( IdString(ARCH_SRC).
asString() );
192 static const Arch nosrcArch( IdString(ARCH_NOSRC).
asString() );
202 std::string name( name_r );
204 std::string::size_type asep( name_r.rfind(
"." ) );
205 if ( asep != std::string::npos )
207 Arch ext( name_r.substr( asep+1 ) );
208 if ( ext.isBuiltIn() || ext == srcArch || ext == nosrcArch )
215 return relFromStr( pool_r, arch, name, op_r, ed_r, kind_r );
222 const std::string & str_r,
const ResKind & kind_r,
225 std::string name( str_r );
230 splitOpEdition( name, op, ed );
233 if ( arch_r.empty() )
234 return relFromStr( pool_r, name, op, ed, kind_r );
236 return relFromStr( pool_r, arch_r, name, op, ed, kind_r );
242 if ( str_r[0] ==
'(' ) {
244 if ( res )
return res;
248 return relFromStr( pool_r,
Arch_empty, str_r, prefix_r, flag_r );
261 : _id( richOrRelFromStr( myPool().getPool(), str_r, prefix_r, flag_r ) )
265 : _id( richOrRelFromStr( myPool().getPool(), str_r, prefix_r, flag_r ) )
269 : _id( relFromStr( myPool().getPool(), arch_r, str_r, prefix_r, flag_r ) )
273 : _id( relFromStr( myPool().getPool(), arch_r, str_r, prefix_r, flag_r ) )
277 : _id( relFromStr( myPool().getPool(),
Arch_empty, str_r, prefix_r, flag_r ) )
281 : _id( relFromStr( myPool().getPool(),
Arch_empty, str_r, prefix_r, flag_r ) )
285 : _id( relFromStr( myPool().getPool(), arch_r, str_r, prefix_r, flag_r ) )
289 : _id( relFromStr( myPool().getPool(), arch_r, str_r, prefix_r, flag_r ) )
297 : _id( relFromStr( myPool().getPool(), name_r,
Rel(op_r),
Edition(ed_r), prefix_r ) )
300 : _id( relFromStr( myPool().getPool(), name_r, op_r,
Edition(ed_r), prefix_r ) )
303 : _id( relFromStr( myPool().getPool(), name_r, op_r, ed_r, prefix_r ) )
310 Capability::Capability(
const std::string & arch_r,
const std::string & name_r,
const std::string & op_r,
const std::string & ed_r,
const ResKind & prefix_r )
311 : _id( relFromStr( myPool().getPool(),
Arch(arch_r), name_r,
Rel(op_r),
Edition(ed_r), prefix_r ) )
314 : _id( relFromStr( myPool().getPool(),
Arch(arch_r), name_r, op_r,
Edition(ed_r), prefix_r ) )
317 : _id( relFromStr( myPool().getPool(),
Arch(arch_r), name_r, op_r, ed_r, prefix_r ) )
320 : _id( relFromStr( myPool().getPool(), arch_r, name_r,
Rel(op_r),
Edition(ed_r), prefix_r ) )
323 : _id( relFromStr( myPool().getPool(), arch_r, name_r, op_r,
Edition(ed_r), prefix_r ) )
326 : _id( relFromStr( myPool().getPool(), arch_r, name_r, op_r, ed_r, prefix_r ) )
334 : _id( ::pool_rel2id( myPool().getPool(), asIdString(namespace_r).id(), (value_r.empty() ? STRID_NULL : value_r.id() ), REL_NAMESPACE, true ) )
341 inline const char * opstr(
int op_r )
345 case REL_GT:
return " > ";
346 case REL_EQ:
return " = ";
347 case REL_LT:
return " < ";
348 case REL_GT|REL_EQ:
return " >= ";
349 case REL_LT|REL_EQ:
return " <= ";
350 case REL_GT|REL_LT:
return " != ";
351 case REL_GT|REL_LT|REL_EQ:
return " <=> ";
352 case REL_AND:
return " and ";
353 case REL_OR:
return " or ";
354 case REL_COND:
return " if ";
355 case REL_UNLESS:
return " unless ";
356 case REL_ELSE:
return " else ";
357 case REL_WITH:
return " with ";
358 case REL_WITHOUT:
return " without ";
360 return "UNKNOWNCAPREL";
363 inline bool isBoolOp(
int op_r )
378 inline bool needsBrace(
int op_r,
int parop_r )
380 return ( isBoolOp( parop_r ) || parop_r == 0 ) && isBoolOp( op_r )
381 && ( parop_r != op_r || op_r == REL_COND || op_r == REL_UNLESS || op_r == REL_ELSE )
382 && not ( ( parop_r == REL_COND || parop_r == REL_UNLESS ) && op_r == REL_ELSE );
387 if ( ISRELDEP(id_r) ) {
388 ::Reldep * rd = GETRELDEP( pool_r, id_r );
392 if ( rd->evr == ARCH_SRC || rd->evr == ARCH_NOSRC ) {
396 outs_r += IdString(rd->name).c_str();
399 cap2strHelper( outs_r, pool_r, rd->name, op );
401 cap2strHelper( outs_r, pool_r, rd->evr, op );
406 cap2strHelper( outs_r, pool_r, rd->name, op );
408 cap2strHelper( outs_r, pool_r, rd->evr, op );
413 if ( op == REL_FILECONFLICT )
415 cap2strHelper( outs_r, pool_r, rd->name, op );
419 if ( needsBrace( op, parop_r ) ) {
421 cap2strHelper( outs_r, pool_r, rd->name, op );
422 outs_r += opstr( op );
423 cap2strHelper( outs_r, pool_r, rd->evr, op );
428 cap2strHelper( outs_r, pool_r, rd->name, op );
429 outs_r += opstr( op );
430 cap2strHelper( outs_r, pool_r, rd->evr, op );
433 outs_r += IdString(id_r).c_str();
440 if ( not
id() )
return "";
443 static TempStrings<5> tempstrs;
445 std::string & outs { tempstrs.getNext() };
446 cap2strHelper( outs,
myPool().getPool(),
id(), 0 );
505 "/(s?bin|lib(64)?|etc)/|^/usr/(games/|share/(dict/words|magic\\.mime)$)|^/opt/gnome/games/",
525 std::string::size_type pos( guess.rfind(
'-' ) );
543 if ( (pos = guess.rfind(
'-', pos-1 )) != std::string::npos )
598 if ( ! ISRELDEP(
_lhs) )
605 ::Reldep * rd = GETRELDEP(
myPool().getPool(),
_lhs );
614 if ( ! ISRELDEP(
_lhs) )
650 static const char archsep =
'.';
651 switch ( obj.
kind() )
654 return str <<
"<NoCap>";
668 return str <<
" " << obj.
op() <<
" " << obj.
ed();
677 cap2strHelper( outs, pool, obj.
lhs().
id(), op );
679 cap2strHelper( outs, pool, obj.
rhs().
id(), op );
684 cap2strHelper( outs, pool, obj.
lhs().
id(), op );
686 cap2strHelper( outs, pool, obj.
rhs().
id(), op );
693 return str <<
"<UnknownCap(" << obj.
lhs() <<
" " << obj.
capRel() <<
" " << obj.
rhs() <<
")>";
705 return str <<
"UnknownCap";
Helper providing more detailed information about a Capability.
sat::detail::IdType _archIfSimple
CapRel
Enum values corresponding with libsolv defines.
@ REL_NONE
Not an expression.
@ CAP_ARCH
Used internally.
Tri state Capability match result.
static const CapMatch irrelevant
static const CapMatch yes
sat::detail::IdType id() const
Expert backdoor.
static const Capability Null
No or Null Capability ( Id 0 ).
Capability()
Default ctor, Empty capability.
CapDetail detail() const
Helper providing more detailed information about a Capability.
const char * c_str() const
Conversion to const char *
static CapMatch _doMatch(sat::detail::IdType lhs, sat::detail::IdType rhs)
Match two Capabilities.
static bool isInterestingFileSpec(const IdString &name_r)
Test for a filename that is likely being REQUIRED.
static const Capability Empty
Empty Capability.
static Capability guessPackageSpec(const std::string &str_r)
Capability parser also guessing "libzypp-1.2.3-4.5.x86_64" formats.
Edition represents [epoch:]version[-release]
static const Edition noedition
Value representing noedition ("") This is in fact a valid Edition.
const char * c_str() const
Access to the sat-pools string space.
const char * c_str() const
Conversion to const char *
constexpr bool empty() const
Whether the string is empty.
IdType id() const
Expert backdoor.
std::string asString() const
Conversion to std::string
static const ResKind srcpackage
static ResPool instance()
Singleton ctor.
byIdent_iterator byIdentBegin(const ByIdent &ident_r) const
byIdent_iterator byIdentEnd(const ByIdent &ident_r) const
static Pool instance()
Singleton ctor.
detail::CPool * get() const
Expert backdoor.
Container of Solvable providing a Capability (read only).
bool empty() const
Whether the container is empty.
sat::detail::IdType parserpmrichdep(const char *capstr_r)
libsolv capability parser
@ nosubs
Support for substring addressing of matches is not required.
Regular expression match result.
String related utilities and Regular expression matching.
std::string asString(TInt val, char zero='0', char one='1')
For printing bits.
static const IdType emptyId(1)
static const IdType noId(0)
int IdType
Generic Id type.
::s_Pool CPool
Wrapped libsolv C data type exposed as backdoor.
std::string numstring(char n, int w=0)
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
bool regex_match(const std::string &s, smatch &matches, const regex ®ex)
\relates regex \ingroup ZYPP_STR_REGEX \relates regex \ingroup ZYPP_STR_REGEX
void split(ParamVec &pvec, const std::string &pstr, const std::string &psep)
Split into a parameter vector.
Easy-to use interface to the ZYPP dependency resolver.
ResolverNamespace
The resolver's dependency namespaces.
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
bool overlaps(const Range< Tp, TCompare > &lhs, const Range< Tp, TCompare > &rhs)
const Arch Arch_empty(IdString::Empty)
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
static bool isRel(unsigned bits_r)
Test whether bits_r is a valid Rel (no extra bits set).
static PoolImpl & myPool()