From: Josef Reidinger Date: Tue, 22 Apr 2008 09:57:59 +0000 (+0000) Subject: replace boost::replace_all by jano's implementation which is faster (replace in place) X-Git-Tag: BASE-SuSE-Linux-11_0-Branch~198 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5ee3418a5f2a60f67154db05a2ed5ef05c016f17;p=platform%2Fupstream%2Flibzypp.git replace boost::replace_all by jano's implementation which is faster (replace in place) --- diff --git a/zypp/PoolQuery.cc b/zypp/PoolQuery.cc index b14715a..0e23ede 100644 --- a/zypp/PoolQuery.cc +++ b/zypp/PoolQuery.cc @@ -11,7 +11,6 @@ */ #include #include -#include #include "zypp/base/Gettext.h" #include "zypp/base/Logger.h" @@ -1079,7 +1078,7 @@ attremptycheckend: else { string s = attrName; - boost::replace_all( s,"_",":" ); + str::replace_all( s,"_",":" ); SolvAttr a(s); addAttribute(a,attrValue); } @@ -1177,7 +1176,7 @@ attremptycheckend: for_( it, attributes().begin(), attributes().end() ) { string s = it->first.asString(); - boost::replace_all(s,":","_"); + str::replace_all(s,":","_"); for_( it2,it->second.begin(),it->second.end() ) { str << s <<": "<< *it2 << delim; diff --git a/zypp/PublicKey.cc b/zypp/PublicKey.cc index ad5bee6..8ce9408 100644 --- a/zypp/PublicKey.cc +++ b/zypp/PublicKey.cc @@ -11,8 +11,6 @@ */ #include -#include - //#include "zypp/base/Logger.h" #include "zypp/base/String.h" @@ -168,7 +166,7 @@ namespace zypp _id = what[5]; _name = what[10]; //replace all escaped semicolon with real - boost::replace_all(_name,"\\x3a",":"); + str::replace_all(_name,"\\x3a",":"); _created = createDate(what[6]); _expires = createDate(what[7]); diff --git a/zypp/base/String.cc b/zypp/base/String.cc index e0d54ec..875ac78 100644 --- a/zypp/base/String.cc +++ b/zypp/base/String.cc @@ -207,9 +207,24 @@ namespace zypp } } + return sNew; } + string & replace_all(string & str, const string & from, const string & to) + { + string::size_type pos = 0; + while((pos = str.find(from, pos)) != string::npos) + { + str.replace(pos, from.size(), to); + pos += to.size(); + + if (pos >= str.length()) + break; + } + return str; + } + /****************************************************************** ** ** diff --git a/zypp/base/String.h b/zypp/base/String.h index 7238334..50e189f 100644 --- a/zypp/base/String.h +++ b/zypp/base/String.h @@ -16,8 +16,6 @@ #include #include -#include - #include "zypp/base/PtrTypes.h" /////////////////////////////////////////////////////////////////// @@ -287,6 +285,22 @@ namespace zypp { return( default_r ? strToFalse( str ) : strToTrue( str ) ); } //@} + /** + * \short Looks for text in a string and replaces it. + * + * \note It only perform substtution in one pass + */ + std::string gsub( const std::string& sData, const std::string& sFrom, const std::string& sTo); + + /** + * \short Looks for text in string and replaces it in place + * + * + * \note It only perform substtution in one pass + * \note use only if you replace same lenght strings, otherwise use gsub + */ + std::string& replace_all( std::string & str, const std::string & from, const std::string & to); + /////////////////////////////////////////////////////////////////// /** \name Split. */ //@{ @@ -381,11 +395,11 @@ namespace zypp std::string s( beg+1, cur-beg-2 ); //without quotes //transform escaped escape - boost::replace_all( s, "\\\\", "\\" ); + replace_all( s, "\\\\", "\\" ); //transform escaped quotes (only same as open char tmpn[2] = { closeChar, 0 }; char tmpo[3] = { '\\', closeChar, 0 }; - boost::replace_all( s, tmpo, tmpn ); + replace_all( s, tmpo, tmpn ); *result_r = s; } @@ -404,7 +418,7 @@ namespace zypp // build string std::string s( beg, cur-beg ); //transform escaped escape - boost::replace_all( s, "\\\\", "\\" ); + replace_all( s, "\\\\", "\\" ); const char *delimeter = sepchars_r; while ( *delimeter ) @@ -413,7 +427,7 @@ namespace zypp const char tmp[2] = { *delimeter, '\0' }; std::string del(tmp); ds+= del; - boost::replace_all( s, ds, del ); + replace_all( s, ds, del ); ++delimeter; } @@ -516,14 +530,6 @@ namespace zypp inline bool endsWith(const std::string& s, const char* str) { return s.find(str) == s.size() - strlen(str); } inline bool contains(const std::string& s, const char* str) { return s.find(str) != std::string::npos; } - /** - * \short Looks for text in a string and replaces it. - * - * \note It only perform substtution in one pass - */ - std::string gsub( const std::string& sData, const std::string& sFrom, const std::string& sTo); - - /////////////////////////////////////////////////////////////////// /** \name String prefix handling.