// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: strutl.cc,v 1.40 2001/05/27 05:36:04 jgg Exp $
+// $Id: strutl.cc,v 1.41 2001/05/27 23:30:45 jgg Exp $
/* ######################################################################
String Util - Some useful string functions.
string QuoteString(string Str,const char *Bad)
{
string Res;
- for (const char *I = Str.c_str(); *I != 0; I++)
+ for (string::iterator I = Str.begin(); I != Str.end(); I++)
{
if (strchr(Bad,*I) != 0 || isprint(*I) == 0 ||
*I <= 0x20 || *I >= 0x7F)
string DeQuoteString(string Str)
{
string Res;
- for (const char *I = Str.c_str(); *I != 0; I++)
+ for (string::const_iterator I = Str.begin(); I != Str.end(); I++)
{
- if (*I == '%' && I + 2 < Str.c_str() + Str.length())
+ if (*I == '%' && I + 2 < Str.end())
{
char Tmp[3];
Tmp[0] = I[1];
// "\x00-\x20{}|\\\\^\\[\\]<>\"\x7F-\xFF";
URI = QuoteString(U,"\\|{}[]<>\"^~_=!@#$%^&*");
- char *J = const_cast<char *>(URI.c_str());
- for (; *J != 0; J++)
+ string::iterator J = URI.begin();
+ for (; J != URI.end(); J++)
if (*J == '/')
*J = '_';
return URI;
/* Transform the 3x8 bits to 4x6 bits, as required by
base64. */
- for (const char *I = S.c_str(); I < (S.c_str() + S.length()); I += 3)
+ for (string::const_iterator I = S.begin(); I < S.end(); I += 3)
{
char Bits[3] = {0,0,0};
Bits[0] = I[0];
- if (I + 1 < S.c_str() + S.length())
+ if (I + 1 < S.end())
Bits[1] = I[1];
- if (I + 2 < S.c_str() + S.length())
+ if (I + 2 < S.end())
Bits[2] = I[2];
Final += tbl[Bits[0] >> 2];
Final += tbl[((Bits[0] & 3) << 4) + (Bits[1] >> 4)];
- if (I + 1 >= S.c_str() + S.length())
+ if (I + 1 >= S.end())
break;
Final += tbl[((Bits[1] & 0xf) << 2) + (Bits[2] >> 6)];
- if (I + 2 >= S.c_str() + S.length())
+ if (I + 2 >= S.end())
break;
Final += tbl[Bits[2] & 0x3f];
/* This parses the URI into all of its components */
void URI::CopyFrom(string U)
{
- const char *I = U.c_str();
+ string::const_iterator I = U.begin();
// Locate the first colon, this separates the scheme
- for (; *I != 0 && *I != ':' ; I++);
- const char *FirstColon = I;
+ for (; I < U.end() && *I != ':' ; I++);
+ string::const_iterator FirstColon = I;
/* Determine if this is a host type URI with a leading double //
and then search for the first single / */
- const char *SingleSlash = I;
- if (I + 3 < U.c_str() + U.length() && I[1] == '/' && I[2] == '/')
+ string::const_iterator SingleSlash = I;
+ if (I + 3 < U.end() && I[1] == '/' && I[2] == '/')
SingleSlash += 3;
/* Find the / indicating the end of the hostname, ignoring /'s in the
square brackets */
bool InBracket = false;
- for (; SingleSlash < U.c_str() + U.length() && (*SingleSlash != '/' || InBracket == true); SingleSlash++)
+ for (; SingleSlash < U.end() && (*SingleSlash != '/' || InBracket == true); SingleSlash++)
{
if (*SingleSlash == '[')
InBracket = true;
InBracket = false;
}
- if (SingleSlash > U.c_str() + U.length())
- SingleSlash = U.c_str() + U.length();
+ if (SingleSlash > U.end())
+ SingleSlash = U.end();
// We can now write the access and path specifiers
- Access = string(U,0,FirstColon - U.c_str());
- if (*SingleSlash != 0)
- Path = string(U,SingleSlash - U.c_str());
+ Access = string(U,0,FirstColon - U.begin());
+ if (SingleSlash != U.end())
+ Path = string(U,SingleSlash - U.begin());
if (Path.empty() == true)
Path = "/";
FirstColon += 3;
else
FirstColon += 1;
- if (FirstColon >= U.c_str() + U.length())
+ if (FirstColon >= U.end())
return;
if (FirstColon > SingleSlash)
if (I > SingleSlash)
I = SingleSlash;
for (; I < SingleSlash && *I != ':'; I++);
- const char *SecondColon = I;
+ string::const_iterator SecondColon = I;
// Search for the @ after the colon
for (; I < SingleSlash && *I != '@'; I++);
- const char *At = I;
+ string::const_iterator At = I;
// Now write the host and user/pass
if (At == SingleSlash)
{
if (FirstColon < SingleSlash)
- Host = string(U,FirstColon - U.c_str(),SingleSlash - FirstColon);
+ Host = string(U,FirstColon - U.begin(),SingleSlash - FirstColon);
}
else
{
- Host = string(U,At - U.c_str() + 1,SingleSlash - At - 1);
- User = string(U,FirstColon - U.c_str(),SecondColon - FirstColon);
+ Host = string(U,At - U.begin() + 1,SingleSlash - At - 1);
+ User = string(U,FirstColon - U.begin(),SecondColon - FirstColon);
if (SecondColon < At)
- Password = string(U,SecondColon - U.c_str() + 1,At - SecondColon - 1);
+ Password = string(U,SecondColon - U.begin() + 1,At - SecondColon - 1);
}
// Now we parse the RFC 2732 [] hostnames.