summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/strutl.cc21
-rw-r--r--apt-pkg/contrib/strutl.h3
2 files changed, 22 insertions, 2 deletions
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index 8c1f7005c..f30d9ffe7 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: strutl.cc,v 1.2 1998/07/16 06:08:41 jgg Exp $
+// $Id: strutl.cc,v 1.3 1998/07/19 04:22:08 jgg Exp $
/* ######################################################################
String Util - Some usefull string functions.
@@ -243,6 +243,25 @@ string SubstVar(string Str,string Subst,string Contents)
return Temp + string(Str,OldPos);
}
/*}}}*/
+// URItoFileName - Convert the uri into a unique file name /*{{{*/
+// ---------------------------------------------------------------------
+/* This converts a URI into a safe filename. It quotes all unsafe characters
+ and converts / to _ and removes the scheme identifier. The resulting
+ file name should be unique and never occur again for a different file */
+string URItoFileName(string URI)
+{
+ string::const_iterator I = URI.begin() + URI.find(':') + 1;
+ for (; I < URI.end() && *I == '/'; I++);
+
+ // "\x00-\x20{}|\\\\^\\[\\]<>\"\x7F-\xFF";
+ URI = QuoteString(string(I,URI.end() - I),"\\|{}[]<>\"^~_=!@#$%^&*");
+ string::iterator J = URI.begin();
+ for (; J != URI.end(); J++)
+ if (*J == '/')
+ *J = '_';
+ return URI;
+}
+ /*}}}*/
// Base64Encode - Base64 Encoding routine for short strings /*{{{*/
// ---------------------------------------------------------------------
/* This routine performs a base64 transformation on a string. It was ripped
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index 0aabf0186..b49b1a52d 100644
--- a/apt-pkg/contrib/strutl.h
+++ b/apt-pkg/contrib/strutl.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: strutl.h,v 1.2 1998/07/09 05:12:35 jgg Exp $
+// $Id: strutl.h,v 1.3 1998/07/19 04:22:09 jgg Exp $
/* ######################################################################
String Util - These are some usefull string functions
@@ -29,6 +29,7 @@ string SizeToStr(double Bytes);
string TimeToStr(unsigned long Sec);
string SubstVar(string Str,string Subst,string Contents);
string Base64Encode(string Str);
+string URItoFileName(string URI);
int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
inline int stringcmp(const char *A,const char *AEnd,const char *B) {return stringcmp(A,AEnd,B,B+strlen(B));};