35 using zyppng::sat::StringPool;
41 template <
unsigned TLen = 5>
45 std::string & getNext()
46 {
unsigned c = _next; _next = (_next+1) % TLen; _buf[c].clear();
return _buf[c]; }
50 std::string _buf[TLen];
54 inline std::string::size_type backskipWs(
const std::string & str_r, std::string::size_type pos_r )
56 for ( ; pos_r != std::string::npos; --pos_r )
58 char ch = str_r[pos_r];
59 if ( ch !=
' ' && ch !=
'\t' )
66 inline std::string::size_type backskipNWs(
const std::string & str_r, std::string::size_type pos_r )
68 for ( ; pos_r != std::string::npos; --pos_r )
70 char ch = str_r[pos_r];
71 if ( ch ==
' ' || ch ==
'\t' )
78 void splitOpEdition( std::string & str_r,
Rel & op_r,
Edition & ed_r )
82 std::string::size_type ch( str_r.size()-1 );
85 if ( (ch = backskipWs( str_r, ch )) != std::string::npos )
87 std::string::size_type ee( ch );
88 if ( (ch = backskipNWs( str_r, ch )) != std::string::npos )
90 std::string::size_type eb( ch );
91 if ( (ch = backskipWs( str_r, ch )) != std::string::npos )
93 std::string::size_type oe( ch );
94 ch = backskipNWs( str_r, ch );
95 if ( op_r.parseFrom( str_r.substr( ch+1, oe-ch ) ) )
98 ed_r =
Edition( str_r.substr( eb+1, ee-eb ) );
99 if ( ch != std::string::npos )
100 ch = backskipWs( str_r, ch );
110 ch = str_r.find_last_of(
"<=>)" );
111 if ( ch != std::string::npos && str_r[ch] !=
')' )
113 std::string::size_type oe( ch );
116 ch = str_r.find_first_not_of(
" \t", oe+1 );
117 if ( ch != std::string::npos )
118 ed_r =
Edition( str_r.substr( ch ) );
122 if ( str_r[oe] !=
'=' )
124 op_r = ( str_r[oe] ==
'<' ) ?
Rel::LT :
Rel::GT;
128 if ( ch != std::string::npos )
132 case '<': --ch; op_r =
Rel::LE;
break;
133 case '>': --ch; op_r =
Rel::GE;
break;
134 case '!': --ch; op_r =
Rel::NE;
break;
136 default: op_r =
Rel::EQ;
break;
142 if ( ch != std::string::npos )
143 ch = backskipWs( str_r, ch );
154 const std::string & name_r,
167 nid = ::pool_rel2id( pool_r, nid,
IdString(ARCH_SRC).
id(), REL_ARCH,
true );
173 nid = ::pool_rel2id( pool_r, nid, arch_r.id(), REL_ARCH,
true );
179 nid = ::pool_rel2id( pool_r, nid, ed_r.id(), op_r.bits(),
true );
189 const std::string & name_r,
Rel op_r,
const Edition & ed_r,
203 std::string name( name_r );
205 std::string::size_type asep( name_r.rfind(
'.' ) );
206 if ( asep != std::string::npos )
208 Arch ext( name_r.substr( asep+1 ) );
209 if ( ext.isBuiltIn() || ext == srcArch || ext == nosrcArch )
216 return relFromStr( pool_r, arch, name, op_r, ed_r, kind_r );
223 const std::string & str_r,
const ResKind & kind_r,
226 std::string name( str_r );
231 splitOpEdition( name, op, ed );
234 if ( arch_r.empty() )
235 return relFromStr( pool_r, name, op, ed, kind_r );
237 return relFromStr( pool_r, arch_r, name, op, ed, kind_r );
243 if ( str_r[0] ==
'(' ) {
245 if ( res )
return res;
249 return relFromStr( pool_r,
Arch_empty, str_r, prefix_r, flag_r );
262 :
_id( richOrRelFromStr(
StringPool::instance().getPool(), str_r, prefix_r, flag_r ) )
266 :
_id( richOrRelFromStr(
StringPool::instance().getPool(), str_r, prefix_r, flag_r ) )
270 :
_id( relFromStr(
StringPool::instance().getPool(), arch_r, str_r, prefix_r, flag_r ) )
274 :
_id( relFromStr(
StringPool::instance().getPool(), arch_r, str_r, prefix_r, flag_r ) )
286 :
_id( relFromStr(
StringPool::instance().getPool(), arch_r, str_r, prefix_r, flag_r ) )
290 :
_id( relFromStr(
StringPool::instance().getPool(), arch_r, str_r, prefix_r, flag_r ) )
304 :
_id( relFromStr(
StringPool::instance().getPool(), name_r, op_r, ed_r, prefix_r ) )
311 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 )
318 :
_id( relFromStr(
StringPool::instance().getPool(),
Arch(arch_r), name_r, op_r, ed_r, prefix_r ) )
324 :
_id( relFromStr(
StringPool::instance().getPool(), arch_r, name_r, op_r,
Edition(ed_r), prefix_r ) )
327 :
_id( relFromStr(
StringPool::instance().getPool(), arch_r, name_r, op_r, ed_r, prefix_r ) )
343 :
_id( ::pool_rel2id(
StringPool::instance().getPool(), lhs_r.
id(), rhs_r.
id(), rel_r, true ) )
350 inline const char * opstr(
int op_r )
354 case REL_GT:
return " > ";
355 case REL_EQ:
return " = ";
356 case REL_LT:
return " < ";
357 case REL_GT|REL_EQ:
return " >= ";
358 case REL_LT|REL_EQ:
return " <= ";
359 case REL_GT|REL_LT:
return " != ";
360 case REL_GT|REL_LT|REL_EQ:
return " <=> ";
361 case REL_AND:
return " and ";
362 case REL_OR:
return " or ";
363 case REL_COND:
return " if ";
364 case REL_UNLESS:
return " unless ";
365 case REL_ELSE:
return " else ";
366 case REL_WITH:
return " with ";
367 case REL_WITHOUT:
return " without ";
369 return "UNKNOWNCAPREL";
372 inline bool isBoolOp(
int op_r )
387 inline bool needsBrace(
int op_r,
int parop_r )
389 return ( isBoolOp( parop_r ) || parop_r == 0 ) && isBoolOp( op_r )
390 && ( parop_r != op_r || op_r == REL_COND || op_r == REL_UNLESS || op_r == REL_ELSE )
391 && not ( ( parop_r == REL_COND || parop_r == REL_UNLESS ) && op_r == REL_ELSE );
396 if ( ISRELDEP(id_r) ) {
397 ::Reldep * rd = GETRELDEP( pool_r, id_r );
401 if ( rd->evr == ARCH_SRC || rd->evr == ARCH_NOSRC ) {
408 cap2strHelper( outs_r, pool_r, rd->name, op );
410 cap2strHelper( outs_r, pool_r, rd->evr, op );
415 cap2strHelper( outs_r, pool_r, rd->name, op );
417 cap2strHelper( outs_r, pool_r, rd->evr, op );
422 if ( op == REL_FILECONFLICT )
424 cap2strHelper( outs_r, pool_r, rd->name, op );
428 if ( needsBrace( op, parop_r ) ) {
430 cap2strHelper( outs_r, pool_r, rd->name, op );
431 outs_r += opstr( op );
432 cap2strHelper( outs_r, pool_r, rd->evr, op );
437 cap2strHelper( outs_r, pool_r, rd->name, op );
438 outs_r += opstr( op );
439 cap2strHelper( outs_r, pool_r, rd->evr, op );
449 if ( not
id() )
return "";
452 static TempStrings<5> tempstrs;
454 std::string & outs { tempstrs.getNext() };
514 "/(s?bin|lib(64)?|etc)/|^/usr/(games/|share/(dict/words|magic\\.mime)$)|^/opt/gnome/games/",
528 if (
detail.isNamed() && !::strpbrk(
detail.name().c_str(),
"*?[{" )
533 std::string guess(
detail.name().asString() );
534 std::string::size_type pos( guess.rfind(
'-' ) );
552 if ( (pos = guess.rfind(
'-', pos-1 )) != std::string::npos )
615 std::optional<
decltype(lvl_r.rbegin())> lastch;
616 if ( not lvl_r.empty() )
617 lastch = lvl_r.rbegin();
619 if ( d.isExpression() ) {
620 static const char* ts =
" +|+ ";
621 const char* t = lastch && **lastch ==
'l' ? ts : ts+2;
622 if ( lastch ) **lastch = t[0];
624 if ( lastch ) **lastch = t[1];
625 str << lvl_r <<
"<" << d.capRel() << endl;
626 if ( lastch ) **lastch = t[2];
629 if ( lastch ) **lastch =
' ';
630 str << lvl_r <<
'"' << d <<
'"';
648 if ( ! ISRELDEP(
_lhs) )
664 if ( ! ISRELDEP(
_lhs) )
700 static const char archsep =
'.';
701 switch ( obj.
kind() )
704 return str <<
"<NoCap>";
718 return str <<
" " << obj.
op() <<
" " << obj.
ed();
727 cap2strHelper( outs,
pool, obj.
lhs().
id(), op );
729 cap2strHelper( outs,
pool, obj.
rhs().
id(), op );
734 cap2strHelper( outs,
pool, obj.
lhs().
id(), op );
736 cap2strHelper( outs,
pool, obj.
rhs().
id(), op );
743 return str <<
"<UnknownCap(" << obj.
lhs() <<
" " << obj.
capRel() <<
" " << obj.
rhs() <<
")>";
755 return str <<
"UnknownCap";
761 return str <<
"NoCapRel";
762 return str << static_cast<Capability::CapRel>(obj);
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.
bool empty() const
Whether the Capability is empty.
CapRel
Enum values correspond with libsolv defines.
@ CAP_ARCH
Used internally.
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].
Range< Edition, Match > MatchRange
Edition Range based on Match.
static const Edition noedition
Value representing noedition ("") This is in fact a valid Edition.
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.
static const ResKind srcpackage
static ResPool instance()
Singleton ctor.
static StringPool & instance()
Access the global StringPool instance.
Helper that splits an identifier into kind and name or vice versa.
Container of Solvable providing a Capability (read only).
bool empty() const
Whether the container is empty.
@ nosubs
Support for substring addressing of matches is not required.
Regular expression match result.
Singleton manager for the underlying libsolv string pool.
detail::CPool * getPool() const
Explicit accessor for the raw sat-pool.
detail::IdType parserpmrichdep(const char *capstr_r)
libsolv capability parser
bool regex_match(const char *s, smatch &matches, const regex ®ex) ZYPP_API
Regular expression matching.
String related utilities and Regular expression matching.
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.
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.
bool overlaps(const Range< Tp, TCompare > &lhs, const Range< Tp, TCompare > &rhs)
const Arch Arch_empty(IdString::Empty)
constexpr IdString asIdString(ResolverNamespace obj)
relates: ResolverNamespace The underlying libsolv ID
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
relates: Capability Detailed stream output
std::string asString(const Patch::Category &obj)
relates: Patch::Category string representation.
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
static bool isRel(unsigned bits_r)
Test whether bits_r is a valid Rel (no extra bits set).
std::ostream & _dumpRec(std::ostream &str, Capability cap_r, std::string lvl_r="") const
std::ostream & dumpOn(std::ostream &str) const