summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArch Librarian <arch@canonical.com>2004-09-20 16:58:16 +0000
committerArch Librarian <arch@canonical.com>2004-09-20 16:58:16 +0000
commit47db89970b749eb28a4fd616fc944c00b5153a62 (patch)
tree064d92b2260377d5ae4240833bcb758c834fb0d5
parentd935bb170bacf117fdc433778402e41a45ad8d1b (diff)
Reverted CheckDomainList and LookupTag while adding new...
Author: jgg Date: 2001-05-29 04:40:34 GMT Reverted CheckDomainList and LookupTag while adding new comparision functions for iterators
-rw-r--r--apt-pkg/contrib/strutl.cc90
-rw-r--r--apt-pkg/contrib/strutl.h21
2 files changed, 97 insertions, 14 deletions
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index dc5e508a6..60a57b5c7 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.41 2001/05/27 23:30:45 jgg Exp $
+// $Id: strutl.cc,v 1.42 2001/05/29 04:40:34 jgg Exp $
/* ######################################################################
String Util - Some useful string functions.
@@ -440,6 +440,40 @@ int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd)
return -1;
return 1;
}
+int stringcmp(string::const_iterator A,string::const_iterator AEnd,
+ const char *B,const char *BEnd)
+{
+ for (; A != AEnd && B != BEnd; A++, B++)
+ if (*A != *B)
+ break;
+
+ if (A == AEnd && B == BEnd)
+ return 0;
+ if (A == AEnd)
+ return 1;
+ if (B == BEnd)
+ return -1;
+ if (*A < *B)
+ return -1;
+ return 1;
+}
+int stringcmp(string::const_iterator A,string::const_iterator AEnd,
+ string::const_iterator B,string::const_iterator BEnd)
+{
+ for (; A != AEnd && B != BEnd; A++, B++)
+ if (*A != *B)
+ break;
+
+ if (A == AEnd && B == BEnd)
+ return 0;
+ if (A == AEnd)
+ return 1;
+ if (B == BEnd)
+ return -1;
+ if (*A < *B)
+ return -1;
+ return 1;
+}
/*}}}*/
// stringcasecmp - Arbitary case insensitive string compare /*{{{*/
// ---------------------------------------------------------------------
@@ -460,6 +494,40 @@ int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd)
return -1;
return 1;
}
+int stringcasecmp(string::const_iterator A,string::const_iterator AEnd,
+ const char *B,const char *BEnd)
+{
+ for (; A != AEnd && B != BEnd; A++, B++)
+ if (toupper(*A) != toupper(*B))
+ break;
+
+ if (A == AEnd && B == BEnd)
+ return 0;
+ if (A == AEnd)
+ return 1;
+ if (B == BEnd)
+ return -1;
+ if (toupper(*A) < toupper(*B))
+ return -1;
+ return 1;
+}
+int stringcasecmp(string::const_iterator A,string::const_iterator AEnd,
+ string::const_iterator B,string::const_iterator BEnd)
+{
+ for (; A != AEnd && B != BEnd; A++, B++)
+ if (toupper(*A) != toupper(*B))
+ break;
+
+ if (A == AEnd && B == BEnd)
+ return 0;
+ if (A == AEnd)
+ return 1;
+ if (B == BEnd)
+ return -1;
+ if (toupper(*A) < toupper(*B))
+ return -1;
+ return 1;
+}
/*}}}*/
// LookupTag - Lookup the value of a tag in a taged string /*{{{*/
// ---------------------------------------------------------------------
@@ -469,22 +537,22 @@ string LookupTag(string Message,const char *Tag,const char *Default)
{
// Look for a matching tag.
int Length = strlen(Tag);
- for (const char *I = Message.c_str(); I + Length < Message.c_str() + Message.length(); I++)
+ for (string::iterator I = Message.begin(); I + Length < Message.end(); I++)
{
// Found the tag
if (I[Length] == ':' && stringcasecmp(I,I+Length,Tag) == 0)
{
// Find the end of line and strip the leading/trailing spaces
- const char *J;
+ string::iterator J;
I += Length + 1;
- for (; isspace(*I) != 0 && *I != 0; I++);
- for (J = I; *J != '\n' && *J != 0; J++);
+ for (; isspace(*I) != 0 && I < Message.end(); I++);
+ for (J = I; *J != '\n' && J < Message.end(); J++);
for (; J > I && isspace(J[-1]) != 0; J--);
return string(I,J);
}
- for (; *I != '\n' && *I != 0; I++);
+ for (; *I != '\n' && I < Message.end(); I++);
}
// Failed to find a match
@@ -887,16 +955,16 @@ void ioprintf(ostream &out,const char *format,...)
matched against the argument */
bool CheckDomainList(string Host,string List)
{
- const char *Start = List.c_str();
- for (const char *Cur = List.c_str(); *Cur != 0; Cur++)
+ string::const_iterator Start = List.begin();
+ for (string::const_iterator Cur = List.begin(); Cur <= List.end(); Cur++)
{
- if (*Cur != ',')
+ if (Cur < List.end() && *Cur != ',')
continue;
// Match the end of the string..
- if ((Host.size() >= (unsigned)(Cur - List.c_str())) &&
+ if ((Host.size() >= (unsigned)(Cur - List.begin())) &&
Cur - Start != 0 &&
- stringcasecmp(Host.c_str() + Host.length() - (Cur - Start),Host.c_str()+Host.length(),Start,Cur) == 0)
+ stringcasecmp(Host.end() - (Cur - Start),Host.end(),Start,Cur) == 0)
return true;
Start = Cur + 1;
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index 7112c8da7..872338919 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.19 2001/05/27 05:55:27 jgg Exp $
+// $Id: strutl.h,v 1.20 2001/05/29 04:40:34 jgg Exp $
/* ######################################################################
String Util - These are some useful string functions
@@ -65,11 +65,26 @@ inline int name(string A,const char *B) {return func(A.c_str(),A.c_str()+A.lengt
inline int name(string A,string B) {return func(A.c_str(),A.c_str()+A.length(),B.c_str(),B.c_str()+B.length());}; \
inline int name(string A,const char *B,const char *BEnd) {return func(A.c_str(),A.c_str()+A.length(),B,BEnd);};
+#define APT_MKSTRCMP2(name,func) \
+inline int name(const char *A,const char *AEnd,const char *B) {return func(A,AEnd,B,B+strlen(B));}; \
+inline int name(string A,const char *B) {return func(A.begin(),A.end(),B,B+strlen(B));}; \
+inline int name(string A,string B) {return func(A.begin(),A.end(),B.begin(),B.end());}; \
+inline int name(string A,const char *B,const char *BEnd) {return func(A.begin(),A.end(),B,BEnd);}; \
+inline int name(string::const_iterator A,string::const_iterator Aend,const char *B) {return func(A,Aend,B,B+strlen(B));};
+
int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
+int stringcmp(string::const_iterator A,string::const_iterator AEnd,
+ const char *B,const char *BEnd);
+int stringcmp(string::const_iterator A,string::const_iterator AEnd,
+ string::const_iterator B,string::const_iterator BEnd);
int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
+int stringcasecmp(string::const_iterator A,string::const_iterator AEnd,
+ const char *B,const char *BEnd);
+int stringcasecmp(string::const_iterator A,string::const_iterator AEnd,
+ string::const_iterator B,string::const_iterator BEnd);
-APT_MKSTRCMP(stringcmp,stringcmp);
-APT_MKSTRCMP(stringcasecmp,stringcasecmp);
+APT_MKSTRCMP2(stringcmp,stringcmp);
+APT_MKSTRCMP2(stringcasecmp,stringcasecmp);
inline const char *DeNull(const char *s) {return (s == 0?"(null)":s);};