replace boost::replace_all by jano's implementation which is faster (replace in place)
authorJosef Reidinger <jreidinger@suse.cz>
Tue, 22 Apr 2008 09:57:59 +0000 (09:57 +0000)
committerJosef Reidinger <jreidinger@suse.cz>
Tue, 22 Apr 2008 09:57:59 +0000 (09:57 +0000)
zypp/PoolQuery.cc
zypp/PublicKey.cc
zypp/base/String.cc
zypp/base/String.h

index b14715a..0e23ede 100644 (file)
@@ -11,7 +11,6 @@
 */
 #include <iostream>
 #include <sstream>
-#include <boost/algorithm/string/replace.hpp>
 
 #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;
index ad5bee6..8ce9408 100644 (file)
@@ -11,8 +11,6 @@
 */
 #include <iostream>
 
-#include <boost/algorithm/string/replace.hpp>
-
 //#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]);
index e0d54ec..875ac78 100644 (file)
@@ -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;
+    }
+
     /******************************************************************
     **
     **
index 7238334..50e189f 100644 (file)
@@ -16,8 +16,6 @@
 #include <string>
 #include <string.h>
 
-#include <boost/algorithm/string/replace.hpp>
-
 #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.