libzypp: zypp/Edition.cc Source File

libzypp 17.38.14

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/ng/sat/stringpool.h>
20
22namespace zypp
23{
24
25 using zyppng::sat::StringPool;
26
28 namespace
29 {
30
31 inline std::string makeevrstr( const std::string & version_r,
32 const std::string & release_r,
33 Edition::epoch_t epoch_r )
34 {
35 std::string ret( version_r );
36 if ( ! release_r.empty() )
37 {
38 ret += "-";
39 ret += release_r;
40 }
41 return ( epoch_r ? str::numstring( epoch_r ) + ":" + ret
42 : ret );
43 }
44
45 inline std::string makeevrstr( const char * version_r,
46 const char * release_r,
47 Edition::epoch_t epoch_r )
48 { return makeevrstr( std::string(version_r?version_r:""),
49 std::string(release_r?release_r:""),
50 epoch_r );
51 }
53 } // namespace
55
56 const Edition Edition::noedition;
57
59
60 Edition::Edition( const std::string & version_r,
61 const std::string & release_r,
62 epoch_t epoch_r )
63 : _str( makeevrstr( version_r, release_r, epoch_r ) )
64 {}
65
66 Edition::Edition( const char * version_r,
67 const char * release_r,
68 epoch_t epoch_r )
69 : _str( makeevrstr( version_r, release_r, epoch_r ) )
70 {}
71
72 Edition::Edition( const std::string & version_r,
73 const std::string & release_r,
74 const std::string & epoch_r )
75 : _str( makeevrstr( version_r, release_r, str::strtonum<epoch_t>( epoch_r ) ) )
76 {}
77
78 Edition::Edition( const char * version_r,
79 const char * release_r,
80 const char * epoch_r )
81 : _str( makeevrstr( version_r, release_r, str::strtonum<epoch_t>( epoch_r ) ) )
82 {}
83
84 Edition::epoch_t Edition::epoch() const
85 {
86 const char * str( c_str() );
87 const char * sep = str;
88 // skip edition
89 for ( ; *sep >= '0' && *sep <= '9'; ++sep )
90 ; // NOOP
91 if ( *sep == ':' )
92 return str::strtonum<epoch_t>( std::string( str, sep-str ) );
93 return 0;
94 }
95
96 std::string Edition::version() const
97 {
98 const char * str( c_str() );
99 const char * sep = str;
100 // skip edition
101 for ( ; *sep >= '0' && *sep <= '9'; ++sep )
102 ; // NOOP
103 if ( *sep == ':' )
104 str = sep+1;
105 // strip release
106 sep = ::strrchr( str, '-' );
107 if ( sep )
108 return std::string( str, sep-str );
109 return str;
110 }
111
112 std::string Edition::release() const
113 {
114 const char * str( c_str() );
115 const char * sep = ::strrchr( str, '-' );
116 // get release
117 if ( sep )
118 return sep+1;
119 return std::string();
120 }
121
122 int Edition::_doCompare( const char * lhs, const char * rhs )
123 {
124 if ( lhs == rhs ) return 0;
125 if ( lhs && rhs ) return ::pool_evrcmp_str( StringPool::instance().getPool(), lhs, rhs, EVRCMP_COMPARE );
126 return( lhs ? 1 : -1 );
127 }
128
129 int Edition::_doMatch( const char * lhs, const char * rhs )
130 {
131 if ( lhs == rhs ) return 0;
132 if ( lhs && rhs ) return ::pool_evrcmp_str( StringPool::instance().getPool(), lhs, rhs, EVRCMP_MATCH );
133 return( lhs ? 1 : -1 );
134 }
135
137} // namespace zypp
139
140
Edition.h
String.h
zypp::Edition
Edition represents [epoch:]version[-release].
Definition Edition.h:60
zypp::Edition::_str
IdString _str
Definition Edition.h:176
zypp::Edition::version
std::string version() const
Version.
Definition Edition.cc:96
zypp::Edition::Edition
Edition()
Default ctor: noedition.
Definition Edition.h:76
zypp::Edition::epoch_t
unsigned int epoch_t
Type of an epoch.
Definition Edition.h:63
zypp::Edition::release
std::string release() const
Release.
Definition Edition.cc:112
zypp::Edition::_doMatch
static int _doMatch(const char *lhs, const char *rhs)
Definition Edition.cc:129
zypp::Edition::epoch
epoch_t epoch() const
Epoch.
Definition Edition.cc:84
zypp::Edition::_doCompare
static int _doCompare(const char *lhs, const char *rhs) ZYPP_API
Definition Edition.cc:122
zypp::Edition::noedition
static const Edition noedition
Value representing noedition ("") This is in fact a valid Edition.
Definition Edition.h:72
zypp::StringPool::instance
static StringPool & instance()
Access the global StringPool instance.
Definition stringpool.cc:18
zypp::IdStringType< Edition >::c_str
const char * c_str() const
Definition IdStringType.h:115
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
stringpool.h