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 52 of file Parse.h.


Constructor & Destructor Documentation

Parse::Parse (  ) 

Definition at line 44 of file Parse.cpp.

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

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

Definition at line 57 of file Parse.cpp.

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

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

Definition at line 70 of file Parse.cpp.

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

Parse::Parse ( const std::string &  ,
const std::string &  ,
short   
)

Definition at line 83 of file Parse.cpp.

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

Parse::~Parse (  ) 

Definition at line 97 of file Parse.cpp.

00098 {
00099 }


Member Function Documentation

short Parse::issplit ( const   char  ) 

Definition at line 103 of file Parse.cpp.

References pa_splits.

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

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

void Parse::getsplit (  ) 

Definition at line 111 of file Parse.cpp.

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

Referenced by getsplit().

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

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

Definition at line 219 of file Parse.cpp.

References getsplit(), and pa_ord.

00220 {
00221         Parse::getsplit();
00222         s = pa_ord;
00223 }

std::string Parse::getword (  ) 

Definition at line 131 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 getvalue(), getword(), HttpdForm::HttpdForm(), Utility::isipv6(), SmtpdSocket::OnLine(), ResolvSocket::OnLine(), MinionSocket::OnLine(), MinderSocket::OnLine(), HTTPSocket::OnLine(), MinionSocket::OnVerifiedLine(), and HTTPSocket::url_this().

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

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

Definition at line 214 of file Parse.cpp.

References getword().

00215 {
00216         s = Parse::getword();
00217 }

void Parse::getword ( std::string &  ,
std::string &  ,
int   
)

Definition at line 225 of file Parse.cpp.

References getword(), and pa_ord.

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

std::string Parse::getrest (  ) 

Definition at line 234 of file Parse.cpp.

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

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

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

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

Definition at line 243 of file Parse.cpp.

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

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

long Parse::getvalue (  ) 

Definition at line 250 of file Parse.cpp.

References getword(), and pa_ord.

Referenced by MinionSocket::OnLine(), MinderSocket::OnLine(), MinionSocket::OnVerifiedLine(), and HTTPSocket::url_this().

00251 {
00252         Parse::getword();
00253         return atol(pa_ord.c_str());
00254 }

void Parse::setbreak ( const   char  ) 

Definition at line 256 of file Parse.cpp.

References pa_breakchar.

00257 {
00258         pa_breakchar = c;
00259 }

int Parse::getwordlen (  ) 

Definition at line 261 of file Parse.cpp.

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

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

int Parse::getrestlen (  ) 

Definition at line 283 of file Parse.cpp.

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

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

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

Definition at line 72 of file Parse.h.

00072                                        {
00073                 pa_enable = c;
00074         }

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

Definition at line 75 of file Parse.h.

00075                                         {
00076                 pa_disable = c;
00077         }

void Parse::getline (  ) 

Definition at line 295 of file Parse.cpp.

References C, pa_ord, pa_the_ptr, and pa_the_str.

Referenced by getline().

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

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

Definition at line 309 of file Parse.cpp.

References getline(), and pa_ord.

00310 {
00311         getline();
00312         s = pa_ord;
00313 }

size_t Parse::getptr (  )  [inline]

Definition at line 80 of file Parse.h.

00080 { return pa_the_ptr; }

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

Definition at line 81 of file Parse.h.

Referenced by HttpdForm::HttpdForm().

00081 { pa_quote = b; }


Member Data Documentation

std::string Parse::pa_the_str [private]

Definition at line 84 of file Parse.h.

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

std::string Parse::pa_splits [private]

Definition at line 85 of file Parse.h.

Referenced by issplit().

std::string Parse::pa_ord [private]

Definition at line 86 of file Parse.h.

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

size_t Parse::pa_the_ptr [private]

Definition at line 87 of file Parse.h.

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

char Parse::pa_breakchar [private]

Definition at line 88 of file Parse.h.

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

char Parse::pa_enable [private]

Definition at line 89 of file Parse.h.

Referenced by getword().

char Parse::pa_disable [private]

Definition at line 90 of file Parse.h.

Referenced by getword().

short Parse::pa_nospace [private]

Definition at line 91 of file Parse.h.

Referenced by getword().

bool Parse::pa_quote [private]

Definition at line 92 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