summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/strutl.cc
diff options
context:
space:
mode:
authorArch Librarian <arch@canonical.com>2004-09-20 16:53:03 +0000
committerArch Librarian <arch@canonical.com>2004-09-20 16:53:03 +0000
commit6d5dd02a49b18017c296c2d76bc6bb1d9f1ef6ac (patch)
tree109a3da8b5af3304fdc9d2e9f753edb611e54b95 /apt-pkg/contrib/strutl.cc
parent10861bb5068971efe4de96e679a711ab45bb3e25 (diff)
Minor fixes for FTP support
Author: jgg Date: 1999-03-15 08:10:39 GMT Minor fixes for FTP support
Diffstat (limited to 'apt-pkg/contrib/strutl.cc')
-rw-r--r--apt-pkg/contrib/strutl.cc71
1 files changed, 48 insertions, 23 deletions
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index eb3ef96a2..a2464c9a3 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.20 1999/02/27 22:29:11 jgg Exp $
+// $Id: strutl.cc,v 1.21 1999/03/15 08:10:39 jgg Exp $
/* ######################################################################
String Util - Some usefull string functions.
@@ -20,7 +20,7 @@
#endif
#include <apt-pkg/strutl.h>
-#include <apt-pkg/fileutl.h>
+#include <apt-pkg//fileutl.h>
#include <ctype.h>
#include <string.h>
@@ -178,23 +178,20 @@ bool ParseCWord(const char *String,string &Res)
return true;
}
/*}}}*/
-// DeQuoteString - Convert a string from quoted from /*{{{*/
+// QuoteString - Convert a string into quoted from /*{{{*/
// ---------------------------------------------------------------------
-/* This undoes QuoteString */
-string DeQuoteString(string Str)
+/* */
+string QuoteString(string Str,const char *Bad)
{
string Res;
for (string::iterator I = Str.begin(); I != Str.end(); I++)
{
- if (*I == '%' && I + 2 < Str.end())
+ if (strchr(Bad,*I) != 0 || isprint(*I) == 0 ||
+ *I <= 0x20 || *I >= 0x7F)
{
- char Tmp[3];
- Tmp[0] = I[1];
- Tmp[1] = I[2];
- Tmp[2] = 0;
- Res += (char)strtol(Tmp,0,16);
- I += 2;
- continue;
+ char Buf[10];
+ sprintf(Buf,"%%%02x",(int)*I);
+ Res += Buf;
}
else
Res += *I;
@@ -202,27 +199,31 @@ string DeQuoteString(string Str)
return Res;
}
/*}}}*/
-// QuoteString - Convert a string into quoted from /*{{{*/
+// DeQuoteString - Convert a string from quoted from /*{{{*/
// ---------------------------------------------------------------------
-/* */
-string QuoteString(string Str,const char *Bad)
+/* This undoes QuoteString */
+string DeQuoteString(string Str)
{
string Res;
for (string::iterator I = Str.begin(); I != Str.end(); I++)
{
- if (strchr(Bad,*I) != 0 || isprint(*I) == 0 ||
- *I <= 0x20 || *I >= 0x7F)
+ if (*I == '%' && I + 2 < Str.end())
{
- char Buf[10];
- sprintf(Buf,"%%%02x",(int)*I);
- Res += Buf;
+ char Tmp[3];
+ Tmp[0] = I[1];
+ Tmp[1] = I[2];
+ Tmp[2] = 0;
+ Res += (char)strtol(Tmp,0,16);
+ I += 2;
+ continue;
}
else
Res += *I;
}
- return Res;
+ return Res;
}
- /*}}}*/
+
+ /*}}}*/
// SizeToStr - Convert a long into a human readable size /*{{{*/
// ---------------------------------------------------------------------
/* A max of 4 digits are shown before conversion to the next highest unit.
@@ -597,6 +598,30 @@ static int MonthConv(char *Month)
}
}
/*}}}*/
+// timegm - Internal timegm function if gnu is not available /*{{{*/
+// ---------------------------------------------------------------------
+/* Ripped this evil little function from wget - I prefer the use of
+ GNU timegm if possible as this technique will have interesting problems
+ with leap seconds, timezones and other.
+
+ Converts struct tm to time_t, assuming the data in tm is UTC rather
+ than local timezone (mktime assumes the latter).
+
+ Contributed by Roger Beeman <beeman@cisco.com>, with the help of
+ Mark Baushke <mdb@cisco.com> and the rest of the Gurus at CISCO. */
+#ifndef __USE_MISC // glib sets this
+static time_t timegm(struct tm *t)
+{
+ time_t tl, tb;
+
+ tl = mktime (t);
+ if (tl == -1)
+ return -1;
+ tb = mktime (gmtime (&tl));
+ return (tl <= tb ? (tl + (tl - tb)) : (tl - (tb - tl)));
+}
+#endif
+ /*}}}*/
// StrToTime - Converts a string into a time_t /*{{{*/
// ---------------------------------------------------------------------
/* This handles all 3 populare time formats including RFC 1123, RFC 1036