]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/strutl.cc
remove the Section member from package struct
[apt.git] / apt-pkg / contrib / strutl.cc
index 61fcc6a7d79095f46254a542f0b971915621001f..ce69c7a027ea6306c5a1d421e8c756fcd9885a4a 100644 (file)
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/error.h>
 
+#include <stddef.h>
+#include <stdlib.h>
+#include <time.h>
+#include <string>
+#include <vector>
 #include <ctype.h>
 #include <string.h>
 #include <sstream>
@@ -33,9 +38,9 @@
 #include <iconv.h>
 
 #include <apti18n.h>
-
-using namespace std;
                                                                        /*}}}*/
+using namespace std;
+
 // Strip - Remove white space from the front and back of a string       /*{{{*/
 // ---------------------------------------------------------------------
 namespace APT {
@@ -429,23 +434,30 @@ string TimeToStr(unsigned long Sec)
 /* This replaces all occurrences of Subst with Contents in Str. */
 string SubstVar(const string &Str,const string &Subst,const string &Contents)
 {
+   if (Subst.empty() == true)
+      return Str;
+
    string::size_type Pos = 0;
    string::size_type OldPos = 0;
    string Temp;
-   
-   while (OldPos < Str.length() && 
+
+   while (OldPos < Str.length() &&
          (Pos = Str.find(Subst,OldPos)) != string::npos)
    {
-      Temp += string(Str,OldPos,Pos) + Contents;
-      OldPos = Pos + Subst.length();      
+      if (OldPos != Pos)
+        Temp.append(Str, OldPos, Pos - OldPos);
+      if (Contents.empty() == false)
+        Temp.append(Contents);
+      OldPos = Pos + Subst.length();
    }
-   
+
    if (OldPos == 0)
       return Str;
-   
+
+   if (OldPos >= Str.length())
+      return Temp;
    return Temp + string(Str,OldPos);
 }
-
 string SubstVar(string Str,const struct SubstVar *Vars)
 {
    for (; Vars->Subst != 0; Vars++)