]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/strutl.cc
Fixes for file opening
[apt.git] / apt-pkg / contrib / strutl.cc
index 2c3106cebff2e35f7d43da0408e7a040acca5c4d..d5f765dd466d507ab78ec7e3a38fd26e2ebc1647 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: strutl.cc,v 1.10 1998/11/01 05:27:37 jgg Exp $
+// $Id: strutl.cc,v 1.13 1998/11/05 07:21:44 jgg Exp $
 /* ######################################################################
 
    String Util - Some usefull string functions.
    ##################################################################### */
                                                                        /*}}}*/
 // Includes                                                            /*{{{*/
+#ifdef __GNUG__
+#pragma implementation "strutl.h"
+#endif
+
 #include <strutl.h>
 #include <apt-pkg/fileutl.h>
 
 #include <ctype.h>
 #include <string.h>
 #include <stdio.h>
-#include <time.h>
                                                                        /*}}}*/
 
 // strstrip - Remove white space from the front and back of a string   /*{{{*/
@@ -620,29 +623,22 @@ void URI::CopyFrom(string U)
    for (; I < U.end() && *I != ':' ; I++);
    string::const_iterator FirstColon = I;
 
-   // Determine if this is a host type URI with a leading double //
+   /* Determine if this is a host type URI with a leading double //
+      and then search for the first single / */
    string::const_iterator SingleSlash = I;
    if (I + 3 < U.end() && I[1] == '/' && I[2] == '/')
-   {
-      // Locate the single / that starts the path
-      for (; I < U.end(); I++)
-      {
-        if (*I == '/' && I[1] == '/')
-           I += 2;
-        else 
-           if (*I == '/')
-              break;
-      }
-      if (I > U.end())
-        I = U.end();
-      SingleSlash = I;      
-   }
+      SingleSlash += 3;
+   for (; SingleSlash < U.end() && *SingleSlash != '/'; SingleSlash++);
+   if (SingleSlash > U.end())
+        SingleSlash = U.end();
 
    // We can now write the access and path specifiers
    Access = string(U,0,FirstColon - U.begin());
    if (SingleSlash != U.end())
-      Path = string(U,SingleSlash - U.begin() + 1);
-   
+      Path = string(U,SingleSlash - U.begin());
+   if (Path.empty() == true)
+      Path = "/";
+
    // Now we attempt to locate a user:pass@host fragment
    FirstColon += 3;
    if (FirstColon >= U.end())
@@ -693,6 +689,7 @@ URI::operator string()
    string Res = Access + ':';
    if (Host.empty() == false)
    {
+      Res += "//";
       if (User.empty() == false)
       {
         Res += "//" + User;
@@ -701,10 +698,21 @@ URI::operator string()
         Res += "@";
       }
       Res += Host;
+      if (Port != 0)
+      {
+        char S[30];
+        sprintf(S,":%u",Port);
+        Res += S;
+      }         
    }
    
    if (Path.empty() == false)
-      Res += "/" + Path;
+   {
+      if (Path[0] != '/')
+        Res += "/" + Path;
+      else
+        Res += Path;
+   }
    
    return Res;
 }