libzypp 17.31.7
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/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
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
unsigned epoch_t
Type of an epoch.
Definition: Edition.h:64
std::string version() const
Version.
Definition: Edition.cc:94
Edition()
Default ctor: noedition.
Definition: Edition.h:77
std::string release() const
Release.
Definition: Edition.cc:110
static int _doMatch(const char *lhs, const char *rhs)
Definition: Edition.cc:127
epoch_t epoch() const
Epoch.
Definition: Edition.cc:82
static int _doCompare(const char *lhs, const char *rhs)
Definition: Edition.cc:120
static const Edition noedition
Value representing noedition ("") This is in fact a valid Edition.
Definition: Edition.h:73
const char * c_str() const
Definition: IdStringType.h:105
String related utilities and Regular expression matching.
std::string numstring(char n, int w=0)
Definition: String.h:289
TInt strtonum(const C_Str &str)
Parsing numbers from string.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
static PoolImpl & myPool()
Definition: PoolImpl.cc:184