RepoVariables.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00009 
00010 #include <iostream>
00011 #include <map>
00012 #include <algorithm>
00013 #include "zypp/base/String.h"
00014 #include "zypp/repo/RepoException.h"
00015 #include "zypp/ZConfig.h"
00016 #include "RepoVariables.h"
00017 
00018 using namespace std;
00019 
00020 namespace zypp
00021 {
00022 namespace repo
00023 {
00024   
00025 RepoVariablesStringReplacer::RepoVariablesStringReplacer()
00026 {}
00027 
00028 RepoVariablesStringReplacer::~RepoVariablesStringReplacer()
00029 {}
00030 
00031 std::string RepoVariablesStringReplacer::operator()( const std::string &value ) const
00032 {
00033   string newvalue(value);
00034   
00035   // $arch
00036   newvalue = str::gsub( newvalue,
00037                         "$arch",
00038                         ZConfig::instance().systemArchitecture().asString() );
00039   // $basearch
00040   
00041   Arch::CompatSet cset( Arch::compatSet( ZConfig::instance().systemArchitecture() ) );
00042   Arch::CompatSet::const_iterator it = cset.end();
00043   --it;
00044   // now at noarch
00045   --it;
00046   
00047   Arch basearch = *it;
00048   if ( basearch == Arch_noarch )
00049   {
00050     basearch = ZConfig::instance().systemArchitecture();
00051   }
00052 
00053   newvalue = str::gsub( newvalue,
00054                         "$basearch",
00055                         basearch.asString() );
00056   return newvalue;
00057 }
00058 
00060 
00061 RepoVariablesUrlReplacer::RepoVariablesUrlReplacer()
00062 {}
00063 
00064 RepoVariablesUrlReplacer::~RepoVariablesUrlReplacer()
00065 {}
00066 
00067 
00068 Url RepoVariablesUrlReplacer::operator()( const Url &value ) const
00069 {
00070   RepoVariablesStringReplacer replacer;
00071   string transformed = replacer(value.asString());
00072   Url newurl;
00073   try {
00074     newurl = Url(transformed);
00075   }
00076   catch ( const Exception &e )
00077   {
00078     ZYPP_CAUGHT(e);
00079     // just return what we got
00080     return value;
00081   }
00082   return newurl;
00083 }
00084 
00085 } // ns repo
00086 } // ns zypp
00087 
00088 // vim: set ts=2 sts=2 sw=2 et ai:

Generated on Tue Sep 25 19:23:05 2007 for libzypp by  doxygen 1.5.3