libzypp: zypp/Edition.cc Source File

libzypp 17.38.5

Edition.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12extern "C"
13{
14#include <solv/evr.h>
15}
16#include <zypp-core/base/String.h>
17
18#include <zypp/Edition.h>
19#include <zypp/sat/detail/PoolImpl.h>
20
22namespace zypp
23{
24
26 namespace
27 {
28
29 inline std::string makeevrstr( const std::string & version_r,
30 const std::string & release_r,
31 Edition::epoch_t epoch_r )
32 {
33 std::string ret( version_r );
34 if ( ! release_r.empty() )
35 {
36 ret += "-";
37 ret += release_r;
38 }
39 return ( epoch_r ? str::numstring( epoch_r ) + ":" + ret
40 : ret );
41 }
42
43 inline std::string makeevrstr( const char * version_r,
44 const char * release_r,
45 Edition::epoch_t epoch_r )
46 { return makeevrstr( std::string(version_r?version_r:""),
47 std::string(release_r?release_r:""),
48 epoch_r );
49 }
51 } // namespace
53
54 const Edition Edition::noedition;
55
57
58 Edition::Edition( const std::string & version_r,
59 const std::string & release_r,
60 epoch_t epoch_r )
61 : _str( makeevrstr( version_r, release_r, epoch_r ) )
62 {}
63
64 Edition::Edition( const char * version_r,
65 const char * release_r,
66 epoch_t epoch_r )
67 : _str( makeevrstr( version_r, release_r, epoch_r ) )
68 {}
69
70 Edition::Edition( const std::string & version_r,
71 const std::string & release_r,
72 const std::string & epoch_r )
73 : _str( makeevrstr( version_r, release_r, str::strtonum<epoch_t>( epoch_r ) ) )
74 {}
75
76 Edition::Edition( const char * version_r,
77 const char * release_r,
78 const char * epoch_r )
79 : _str( makeevrstr( version_r, release_r, str::strtonum<epoch_t>( epoch_r ) ) )
80 {}
81
82 Edition::epoch_t Edition::epoch() const
83 {
84 const char * str( c_str() );
85 const char * sep = str;
86 // skip edition
87 for ( ; *sep >= '0' && *sep <= '9'; ++sep )
88 ; // NOOP
89 if ( *sep == ':' )
90 return str::strtonum<epoch_t>( std::string( str, sep-str ) );
91 return 0;
92 }
93
94 std::string Edition::version() const
95 {
96 const char * str( c_str() );
97 const char * sep = str;
98 // skip edition
99 for ( ; *sep >= '0' && *sep <= '9'; ++sep )
100 ; // NOOP
101 if ( *sep == ':' )
102 str = sep+1;
103 // strip release
104 sep = ::strrchr( str, '-' );
105 if ( sep )
106 return std::string( str, sep-str );
107 return str;
108 }
109
110 std::string Edition::release() const
111 {
112 const char * str( c_str() );
113 const char * sep = ::strrchr( str, '-' );
114 // get release
115 if ( sep )
116 return sep+1;
117 return std::string();
118 }
119
120 int Edition::_doCompare( const char * lhs, const char * rhs )
121 {
122 if ( lhs == rhs ) return 0;
123 if ( lhs && rhs ) return ::pool_evrcmp_str( myPool().getPool(), lhs, rhs, EVRCMP_COMPARE );
124 return( lhs ? 1 : -1 );
125 }
126
127 int Edition::_doMatch( const char * lhs, const char * rhs )
128 {
129 if ( lhs == rhs ) return 0;
130 if ( lhs && rhs ) return ::pool_evrcmp_str( myPool().getPool(), lhs, rhs, EVRCMP_MATCH );
131 return( lhs ? 1 : -1 );
132 }
133
135} // namespace zypp
137
138
Edition.h
String.h
zypp::Edition
Edition represents [epoch:]version[-release].
Definition Edition.h:61
zypp::Edition::_str
IdString _str
Definition Edition.h:177
zypp::Edition::version
std::string version() const
Version.
Definition Edition.cc:94
zypp::Edition::Edition
Edition()
Default ctor: noedition.
Definition Edition.h:77
zypp::Edition::epoch_t
unsigned int epoch_t
Type of an epoch.
Definition Edition.h:64
zypp::Edition::release
std::string release() const
Release.
Definition Edition.cc:110
zypp::Edition::_doMatch
static int _doMatch(const char *lhs, const char *rhs)
Definition Edition.cc:127
zypp::Edition::epoch
epoch_t epoch() const
Epoch.
Definition Edition.cc:82
zypp::Edition::_doCompare
static int _doCompare(const char *lhs, const char *rhs) ZYPP_API
Definition Edition.cc:120
zypp::Edition::noedition
static const Edition noedition
Value representing noedition ("") This is in fact a valid Edition.
Definition Edition.h:73
zypp::IdStringType< Edition >::c_str
const char * c_str() const
Definition IdStringType.h:107
str
String related utilities and Regular expression matching.
zypp::str::numstring
std::string numstring(char n, int w=0)
Definition String.h:290
zypp::str::strtonum
TInt strtonum(const C_Str &str)
Parsing numbers from string.
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
PoolImpl.h
zypp::sat::detail::PoolMember::myPool
static PoolImpl & myPool()
Definition PoolImpl.cc:185