Logo
~Sockets~
~Examples~
~Contact~


Parse Class Reference
[Utilities]

Splits a string whatever way you want. More...

#include <Parse.h>

List of all members.


Public Member Functions

 Parse ()
 Parse (const std::string &)
 Parse (const std::string &, const std::string &)
 Parse (const std::string &, const std::string &, short)
 ~Parse ()
short issplit (const char)
void getsplit ()
void getsplit (std::string &)
std::string getword ()
void getword (std::string &)
void getword (std::string &, std::string &, int)
std::string getrest ()
void getrest (std::string &)
long getvalue ()
void setbreak (const char)
int getwordlen ()
int getrestlen ()
void enablebreak (const char c)
void disablebreak (const char c)
void getline ()
void getline (std::string &)
size_t getptr ()
void EnableQuote (bool b)

Private Attributes

std::string pa_the_str
std::string pa_splits
std::string pa_ord
size_t pa_the_ptr
char pa_breakchar
char pa_enable
char pa_disable
short pa_nospace
bool pa_quote

Detailed Description

Splits a string whatever way you want.

Definition at line 54 of file Parse.h.


Constructor & Destructor Documentation

Parse::Parse (  ) 

Definition at line 46 of file Parse.cpp.

00047 :pa_the_str("")
00048 ,pa_splits("")
00049 ,pa_ord("")
00050 ,pa_the_ptr(0)
00051 ,pa_breakchar(0)
00052 ,pa_enable(0)
00053 ,pa_disable(0)
00054 ,pa_nospace(0)
00055 ,pa_quote(false)
00056 {
00057 }

Parse::Parse ( const std::string &  s  ) 

Definition at line 59 of file Parse.cpp.

00060 :pa_the_str(s)
00061 ,pa_splits("")
00062 ,pa_ord("")
00063 ,pa_the_ptr(0)
00064 ,pa_breakchar(0)
00065 ,pa_enable(0)
00066 ,pa_disable(0)
00067 ,pa_nospace(0)
00068 ,pa_quote(false)
00069 {
00070 }

Parse::Parse ( const std::string &  s,
const std::string &  sp 
)

Definition at line 72 of file Parse.cpp.

00073 :pa_the_str(s)
00074 ,pa_splits(sp)
00075 ,pa_ord("")
00076 ,pa_the_ptr(0)
00077 ,pa_breakchar(0)
00078 ,pa_enable(0)
00079 ,pa_disable(0)
00080 ,pa_nospace(0)
00081 ,pa_quote(false)
00082 {
00083 }

Parse::Parse ( const std::string &  s,
const std::string &  sp,
short  nospace 
)

Definition at line 85 of file Parse.cpp.

00086 :pa_the_str(s)
00087 ,pa_splits(sp)
00088 ,pa_ord("")
00089 ,pa_the_ptr(0)
00090 ,pa_breakchar(0)
00091 ,pa_enable(0)
00092 ,pa_disable(0)
00093 ,pa_nospace(1)
00094 ,pa_quote(false)
00095 {
00096 }

Parse::~Parse (  ) 

Definition at line 99 of file Parse.cpp.

00100 {
00101 }


Member Function Documentation

short Parse::issplit ( const   char  ) 

Definition at line 105 of file Parse.cpp.

References pa_splits.

Referenced by getrest(), getrestlen(), getsplit(), getword(), and getwordlen().

00106 {
00107         for (size_t i = 0; i < pa_splits.size(); i++)
00108                 if (pa_splits[i] == c)
00109                         return 1;
00110         return 0;
00111 }

void Parse::getsplit (  ) 

Definition at line 113 of file Parse.cpp.

References C, issplit(), pa_ord, pa_the_ptr, and pa_the_str.

Referenced by getsplit().

00114 {
00115         size_t x;
00116 
00117         if (C == '=')
00118         {
00119                 x = pa_the_ptr++;
00120         } else
00121         {
00122                 while (C && (issplit(C)))
00123                         pa_the_ptr++;
00124                 x = pa_the_ptr;
00125                 while (C && !issplit(C) && C != '=')
00126                         pa_the_ptr++;
00127         }
00128         if (x == pa_the_ptr && C == '=')
00129                 pa_the_ptr++;
00130         pa_ord = (x < pa_the_str.size()) ? pa_the_str.substr(x,pa_the_ptr - x) : "";
00131 }

void Parse::getsplit ( std::string &  s  ) 

Definition at line 221 of file Parse.cpp.

References getsplit(), and pa_ord.

00222 {
00223         Parse::getsplit();
00224         s = pa_ord;
00225 }

std::string Parse::getword (  ) 

Definition at line 133 of file Parse.cpp.

References C, issplit(), pa_breakchar, pa_disable, pa_enable, pa_nospace, pa_ord, pa_quote, pa_the_ptr, and pa_the_str.

Referenced by HttpRequest::AddCookie(), getvalue(), getword(), HttpRequest::HttpRequest(), Utility::isipv6(), SmtpdSocket::OnLine(), ResolvSocket::OnLine(), HTTPSocket::OnLine(), HTTPSocket::OnRawData(), HttpdForm::ParseFormData(), HttpResponse::SetCookie(), and HTTPSocket::url_this().

00134 {
00135         size_t x;
00136         int disabled = 0;
00137         int quote = 0;
00138         int rem = 0;
00139 
00140         if (pa_nospace)
00141         {
00142                 while (C && issplit(C))
00143                         pa_the_ptr++;
00144                 x = pa_the_ptr;
00145                 while (C && !issplit(C) && (C != pa_breakchar || !pa_breakchar || disabled))
00146                 {
00147                         if (pa_breakchar && C == pa_disable)
00148                                 disabled = 1;
00149                         if (pa_breakchar && C == pa_enable)
00150                                 disabled = 0;
00151                         if (pa_quote && C == '"')
00152                                 quote = 1;
00153                         pa_the_ptr++;
00154                         while (quote && C && C != '"')
00155                         {
00156                                 pa_the_ptr++;
00157                         }
00158                         if (pa_quote && C == '"')
00159                         {
00160                                 pa_the_ptr++;
00161                         }
00162                         quote = 0;
00163                 }
00164         } else
00165         {
00166                 if (C == pa_breakchar && pa_breakchar)
00167                 {
00168                         x = pa_the_ptr++;
00169                         rem = 1;
00170                 } else
00171                 {
00172                         while (C && (C == ' ' || C == 9 || C == 13 || C == 10 || issplit(C)))
00173                                 pa_the_ptr++;
00174                         x = pa_the_ptr;
00175                         while (C && C != ' ' && C != 9 && C != 13 && C != 10 && !issplit(C) &&
00176                          (C != pa_breakchar || !pa_breakchar || disabled))
00177                         {
00178                                 if (pa_breakchar && C == pa_disable)
00179                                         disabled = 1;
00180                                 if (pa_breakchar && C == pa_enable)
00181                                         disabled = 0;
00182                                 if (pa_quote && C == '"')
00183                                 {
00184                                         quote = 1;
00185                                 pa_the_ptr++;
00186                                 while (quote && C && C != '"')
00187                                 {
00188                                         pa_the_ptr++;
00189                                 }
00190                                 if (pa_quote && C == '"')
00191                                 {
00192                                         pa_the_ptr++;
00193                                 }
00194                                 }
00195                                 else
00196                                         pa_the_ptr++;
00197                                 quote = 0;
00198                         }
00199                         pa_the_ptr++;
00200                         rem = 1;
00201                 }
00202                 if (x == pa_the_ptr && C == pa_breakchar && pa_breakchar)
00203                         pa_the_ptr++;
00204         }
00205         if (x < pa_the_str.size())
00206         {
00207                 pa_ord = pa_the_str.substr(x,pa_the_ptr - x - rem);
00208         }
00209         else
00210         {
00211                 pa_ord = "";
00212         }
00213         return pa_ord;
00214 }

void Parse::getword ( std::string &  s  ) 

Definition at line 216 of file Parse.cpp.

References getword().

00217 {
00218         s = Parse::getword();
00219 }

void Parse::getword ( std::string &  s,
std::string &  fill,
int  l 
)

Definition at line 227 of file Parse.cpp.

References getword(), and pa_ord.

00228 {
00229         Parse::getword();
00230         s = "";
00231         while (s.size() + pa_ord.size() < (size_t)l)
00232                 s += fill;
00233         s += pa_ord;
00234 }

std::string Parse::getrest (  ) 

Definition at line 236 of file Parse.cpp.

References C, issplit(), pa_the_ptr, and pa_the_str.

Referenced by HttpRequest::HttpRequest(), SmtpdSocket::OnLine(), ResolvSocket::OnLine(), HTTPSocket::OnLine(), HttpdForm::ParseFormData(), and HTTPSocket::url_this().

00237 {
00238         std::string s;
00239         while (C && (C == ' ' || C == 9 || issplit(C)))
00240                 pa_the_ptr++;
00241         s = (pa_the_ptr < pa_the_str.size()) ? pa_the_str.substr(pa_the_ptr) : "";
00242         return s;
00243 }

void Parse::getrest ( std::string &  s  ) 

Definition at line 245 of file Parse.cpp.

References C, issplit(), pa_the_ptr, and pa_the_str.

00246 {
00247         while (C && (C == ' ' || C == 9 || issplit(C)))
00248                 pa_the_ptr++;
00249         s = (pa_the_ptr < pa_the_str.size()) ? pa_the_str.substr(pa_the_ptr) : "";
00250 }

long Parse::getvalue (  ) 

Definition at line 252 of file Parse.cpp.

References getword(), and pa_ord.

Referenced by HTTPSocket::url_this().

00253 {
00254         Parse::getword();
00255         return atol(pa_ord.c_str());
00256 }

void Parse::setbreak ( const   char  ) 

Definition at line 258 of file Parse.cpp.

References pa_breakchar.

00259 {
00260         pa_breakchar = c;
00261 }

int Parse::getwordlen (  ) 

Definition at line 263 of file Parse.cpp.

References C, issplit(), pa_breakchar, and pa_the_ptr.

00264 {
00265         size_t x,y = pa_the_ptr,len;
00266 
00267         if (C == pa_breakchar && pa_breakchar)
00268         {
00269                 x = pa_the_ptr++;
00270         } else
00271         {
00272                 while (C && (C == ' ' || C == 9 || C == 13 || C == 10 || issplit(C)))
00273                         pa_the_ptr++;
00274                 x = pa_the_ptr;
00275                 while (C && C != ' ' && C != 9 && C != 13 && C != 10 && !issplit(C) && (C != pa_breakchar || !pa_breakchar))
00276                         pa_the_ptr++;
00277         }
00278         if (x == pa_the_ptr && C == pa_breakchar && pa_breakchar)
00279                 pa_the_ptr++;
00280         len = pa_the_ptr - x;
00281         pa_the_ptr = y;
00282         return (int)len;
00283 }

int Parse::getrestlen (  ) 

Definition at line 285 of file Parse.cpp.

References C, issplit(), pa_the_ptr, and pa_the_str.

00286 {
00287         size_t y = pa_the_ptr;
00288         size_t len;
00289 
00290         while (C && (C == ' ' || C == 9 || issplit(C)))
00291                 pa_the_ptr++;
00292         len = strlen(pa_the_str.c_str() + pa_the_ptr);
00293         pa_the_ptr = y;
00294         return (int)len;
00295 }

void Parse::enablebreak ( const char  c  )  [inline]

Definition at line 74 of file Parse.h.

00074                                        {
00075                 pa_enable = c;
00076         }

void Parse::disablebreak ( const char  c  )  [inline]

Definition at line 77 of file Parse.h.

00077                                         {
00078                 pa_disable = c;
00079         }

void Parse::getline (  ) 

Definition at line 297 of file Parse.cpp.

References C, pa_ord, pa_the_ptr, and pa_the_str.

Referenced by getline().

00298 {
00299         size_t x;
00300 
00301         x = pa_the_ptr;
00302         while (C && C != 13 && C != 10)
00303                 pa_the_ptr++;
00304         pa_ord = (x < pa_the_str.size()) ? pa_the_str.substr(x,pa_the_ptr - x) : "";
00305         if (C == 13)
00306                 pa_the_ptr++;
00307         if (C == 10)
00308                 pa_the_ptr++;
00309 }

void Parse::getline ( std::string &  s  ) 

Definition at line 311 of file Parse.cpp.

References getline(), and pa_ord.

00312 {
00313         getline();
00314         s = pa_ord;
00315 }

size_t Parse::getptr (  )  [inline]

Definition at line 82 of file Parse.h.

00082 { return pa_the_ptr; }

void Parse::EnableQuote ( bool  b  )  [inline]

Definition at line 83 of file Parse.h.

Referenced by HttpdForm::ParseFormData().

00083 { pa_quote = b; }


Member Data Documentation

std::string Parse::pa_the_str [private]

Definition at line 86 of file Parse.h.

Referenced by getline(), getrest(), getrestlen(), getsplit(), and getword().

std::string Parse::pa_splits [private]

Definition at line 87 of file Parse.h.

Referenced by issplit().

std::string Parse::pa_ord [private]

Definition at line 88 of file Parse.h.

Referenced by getline(), getsplit(), getvalue(), and getword().

size_t Parse::pa_the_ptr [private]

Definition at line 89 of file Parse.h.

Referenced by getline(), getrest(), getrestlen(), getsplit(), getword(), and getwordlen().

char Parse::pa_breakchar [private]

Definition at line 90 of file Parse.h.

Referenced by getword(), getwordlen(), and setbreak().

char Parse::pa_enable [private]

Definition at line 91 of file Parse.h.

Referenced by getword().

char Parse::pa_disable [private]

Definition at line 92 of file Parse.h.

Referenced by getword().

short Parse::pa_nospace [private]

Definition at line 93 of file Parse.h.

Referenced by getword().

bool Parse::pa_quote [private]

Definition at line 94 of file Parse.h.

Referenced by getword().


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4