libzypp  13.10.6
RepoVariables.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
9 
10 #include "zypp/base/LogTools.h"
11 #include "zypp/base/String.h"
12 
13 #include "zypp/ZConfig.h"
14 #include "zypp/Target.h"
15 #include "zypp/Arch.h"
17 #include "zypp/base/NonCopyable.h"
18 
20 namespace zypp
21 {
23  namespace repo
24  {
26  namespace
27  {
30  struct ReplacerData : private zypp::base::NonCopyable
31  {
32  const std::string & sysarch() const
33  {
34  if ( _sysarch.empty() )
35  initArchStr();
36  return _sysarch;
37  }
38 
39  const std::string & basearch() const
40  {
41  if ( _basearch.empty() )
42  initArchStr();
43  return _basearch;
44  }
45 
46  const std::string & releasever() const
47  {
48  if( _releasever.empty() )
49  _releasever = Target::distributionVersion( Pathname()/*guess*/ );
50  return _releasever;
51  }
52 
53  private:
54  void initArchStr() const
55  {
56  Arch arch( ZConfig::instance().systemArchitecture() );
57  _sysarch = arch.asString();
58  _basearch = arch.baseArch().asString();
59  }
60  private:
61  mutable std::string _sysarch;
62  mutable std::string _basearch;
63  mutable std::string _releasever;
64  };
65 
71  std::string replacer( const std::string & value_r )
72  {
73  static ReplacerData _data;
74 
75  std::string ret( value_r );
76  // Don't need to capture static (non automatic) _data in lambda
77  ret = str::replaceAllFun( ret, "$arch", []()-> std::string { return _data.sysarch(); } );
78  ret = str::replaceAllFun( ret, "$basearch", []()-> std::string { return _data.basearch(); } );
79  ret = str::replaceAllFun( ret, "$releasever", []()-> std::string { return _data.releasever(); } );
80  return ret;
81  }
82 
83  } // namespace
85 
86  std::string RepoVariablesStringReplacer::operator()( const std::string & value ) const
87  {
88  return replacer( value );
89  }
90 
92  {
93  Url newurl( value );
94  newurl.setPathData( replacer( value.getPathData() ) );
95  newurl.setQueryString( replacer( value.getQueryString() ) );
96  return newurl;
97  }
98 
99  } // namespace repo
101 } // namespace zypp
std::string getPathData() const
Returns the encoded path component of the URL.
Definition: Url.cc:542
static ZConfig & instance()
Singleton ctor.
Definition: ZConfig.cc:655
std::string _basearch
std::string distributionVersion() const
This is version attribute of the installed base product.
Definition: Target.cc:129
std::string _releasever
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
std::list< PublicKeyData > _data
Definition: KeyRing.cc:99
std::string operator()(const std::string &value_r) const
void setPathData(const std::string &pathdata)
Set the path data component in the URL.
Definition: Url.cc:700
std::string getQueryString() const
Returns the encoded query string component of the URL.
Definition: Url.cc:550
std::string & replaceAllFun(std::string &str_r, const std::string &from_r, function< std::string()> to_r)
Definition: String.cc:324
void setQueryString(const std::string &querystr)
Set the query string in the URL.
Definition: Url.cc:708
Url operator()(const Url &url_r) const
std::string _sysarch
Url manipulation class.
Definition: Url.h:87