1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Edition.cc
16 #include "zypp/base/String.h"
18 #include "zypp/Edition.h"
19 #include "zypp/sat/detail/PoolImpl.h"
21 ///////////////////////////////////////////////////////////////////
23 { /////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
29 inline std::string makeevrstr( const std::string & version_r,
30 const std::string & release_r,
31 Edition::epoch_t epoch_r )
33 std::string ret( version_r );
34 if ( ! release_r.empty() )
39 return ( epoch_r ? str::numstring( epoch_r ) + ":" + ret
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:""),
50 /////////////////////////////////////////////////////////////////
52 ///////////////////////////////////////////////////////////////////
54 const Edition Edition::noedition;
56 ///////////////////////////////////////////////////////////////////
58 Edition::Edition( const std::string & version_r,
59 const std::string & release_r,
61 : _str( makeevrstr( version_r, release_r, epoch_r ) )
64 Edition::Edition( const char * version_r,
65 const char * release_r,
67 : _str( makeevrstr( version_r, release_r, epoch_r ) )
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 ) ) )
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 ) ) )
82 Edition::epoch_t Edition::epoch() const
84 const char * str( c_str() );
85 const char * sep = str;
87 for ( ; *sep >= '0' && *sep <= '9'; ++sep )
90 return str::strtonum<epoch_t>( std::string( str, sep-str ) );
94 std::string Edition::version() const
96 const char * str( c_str() );
97 const char * sep = str;
99 for ( ; *sep >= '0' && *sep <= '9'; ++sep )
104 sep = ::strrchr( str, '-' );
106 return std::string( str, sep-str );
110 std::string Edition::release() const
112 const char * str( c_str() );
113 const char * sep = ::strrchr( str, '-' );
117 return std::string();
120 int Edition::_doCompare( const char * lhs, const char * rhs )
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 );
127 int Edition::_doMatch( const char * lhs, const char * rhs )
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 );
134 /////////////////////////////////////////////////////////////////
136 ///////////////////////////////////////////////////////////////////