// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: strutl.cc,v 1.38 2001/03/11 07:22:19 jgg Exp $
+// $Id: strutl.cc,v 1.41 2001/05/27 23:30:45 jgg Exp $
/* ######################################################################
String Util - Some useful string functions.
#include <regex.h>
#include <errno.h>
#include <stdarg.h>
+
+using namespace std;
/*}}}*/
// strstrip - Remove white space from the front and back of a string /*{{{*/
string DeQuoteString(string Str)
{
string Res;
- for (string::iterator I = Str.begin(); I != Str.end(); I++)
+ for (string::const_iterator I = Str.begin(); I != Str.end(); I++)
{
if (*I == '%' && I + 2 < Str.end())
{
{
// Look for a matching tag.
int Length = strlen(Tag);
- for (string::iterator I = Message.begin(); I + Length < Message.end(); I++)
+ for (const char *I = Message.c_str(); I + Length < Message.c_str() + Message.length(); I++)
{
// Found the tag
if (I[Length] == ':' && stringcasecmp(I,I+Length,Tag) == 0)
{
// Find the end of line and strip the leading/trailing spaces
- string::iterator J;
+ const char *J;
I += Length + 1;
- for (; isspace(*I) != 0 && I < Message.end(); I++);
- for (J = I; *J != '\n' && J < Message.end(); J++);
+ for (; isspace(*I) != 0 && *I != 0; I++);
+ for (J = I; *J != '\n' && *J != 0; J++);
for (; J > I && isspace(J[-1]) != 0; J--);
- return string(I,J-I);
+ return string(I,J);
}
- for (; *I != '\n' && I < Message.end(); I++);
+ for (; *I != '\n' && *I != 0; I++);
}
// Failed to find a match
// Hex2Num - Convert a long hex number into a buffer /*{{{*/
// ---------------------------------------------------------------------
/* The length of the buffer must be exactly 1/2 the length of the string. */
-bool Hex2Num(const char *Start,const char *End,unsigned char *Num,
- unsigned int Length)
+bool Hex2Num(string Str,unsigned char *Num,unsigned int Length)
{
- if (End - Start != (signed)(Length*2))
+ if (Str.length() != Length*2)
return false;
// Convert each digit. We store it in the same order as the string
int J = 0;
- for (const char *I = Start; I < End;J++, I += 2)
+ for (string::const_iterator I = Str.begin(); I != Str.end();J++, I += 2)
{
if (isxdigit(*I) == 0 || isxdigit(I[1]) == 0)
return false;
matched against the argument */
bool CheckDomainList(string Host,string List)
{
- const char *Start = List.begin();
- for (const char *Cur = List.begin(); Cur <= List.end() ; Cur++)
+ const char *Start = List.c_str();
+ for (const char *Cur = List.c_str(); *Cur != 0; Cur++)
{
- if (Cur < List.end() && *Cur != ',')
+ if (*Cur != ',')
continue;
// Match the end of the string..
- if ((Host.size() >= (unsigned)(Cur - List.begin())) &&
+ if ((Host.size() >= (unsigned)(Cur - List.c_str())) &&
Cur - Start != 0 &&
- stringcasecmp(Host.end() - (Cur - Start),Host.end(),Start,Cur) == 0)
+ stringcasecmp(Host.c_str() + Host.length() - (Cur - Start),Host.c_str()+Host.length(),Start,Cur) == 0)
return true;
Start = Cur + 1;