Logo
~Apps~
~Projects~
~Contact~


ParseBT Class Reference

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

#include <ParseBT.h>

List of all members.


Public Member Functions

 ParseBT ()
 ParseBT (char *)
 ParseBT (char *, char *)
 ParseBT (char *, char *, short)
 ~ParseBT ()
short issplit (char)
void getsplit (void)
void getsplit (char *)
void getword (void)
void getword (char *)
void getword (char *, int)
void getword (char *, char *, int)
void getrest (char *)
long getvalue (void)
void setbreak (char)
int getwordlen (void)
int getrestlen (void)
void enablebreak (char c)
void disablebreak (char c)
void getline (void)
void getline (char *)
void getline (char *, int)
int getptr (void)
void EnableQuote (bool b)

Private Attributes

char * pa_the_str
char * pa_splits
char * pa_ord
int 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.

ParseBT.h - parse a string

Written: 1999-Feb-10 ah@instrumentpolen.se

Definition at line 55 of file ParseBT.h.


Constructor & Destructor Documentation

ParseBT::ParseBT (  ) 

ParseBT.cpp - parse a string

Written: 1999-Feb-10 ah@instrumentpolen.se

Definition at line 35 of file ParseBT.cpp.

References pa_breakchar, pa_disable, pa_enable, pa_nospace, pa_ord, pa_quote, pa_splits, pa_the_ptr, and pa_the_str.

00036 {
00037         pa_the_str = NULL;
00038         pa_splits = NULL;
00039         pa_ord = NULL;
00040         pa_the_ptr = 0;
00041         pa_breakchar = 0;
00042         pa_enable = pa_disable = 0;
00043         pa_nospace = 0;
00044         pa_quote = false;
00045 }

ParseBT::ParseBT ( char *   ) 

Definition at line 47 of file ParseBT.cpp.

References pa_breakchar, pa_disable, pa_enable, pa_nospace, pa_ord, pa_quote, pa_splits, pa_the_ptr, and pa_the_str.

00048 {
00049         pa_the_str = NULL;
00050         pa_splits = NULL;
00051         pa_ord = NULL;
00052         pa_the_ptr = 0;
00053         pa_breakchar = 0;
00054         pa_enable = pa_disable = 0;
00055         pa_nospace = 0;
00056         pa_quote = false;
00057 
00058         pa_the_str = new char[strlen(s) + 1];
00059         strcpy(pa_the_str,s);
00060         pa_ord = new char[strlen(s) + 1];
00061         *pa_ord = 0;
00062 }

ParseBT::ParseBT ( char *  ,
char *   
)

Definition at line 64 of file ParseBT.cpp.

References pa_breakchar, pa_disable, pa_enable, pa_nospace, pa_ord, pa_quote, pa_splits, pa_the_ptr, and pa_the_str.

00065 {
00066         pa_the_str = NULL;
00067         pa_splits = NULL;
00068         pa_ord = NULL;
00069         pa_the_ptr = 0;
00070         pa_breakchar = 0;
00071         pa_enable = pa_disable = 0;
00072         pa_nospace = 0;
00073         pa_quote = false;
00074 
00075         pa_the_str = new char[strlen(s) + 1];
00076         strcpy(pa_the_str,s);
00077         pa_splits = new char[strlen(sp) + 1];
00078         strcpy(pa_splits,sp);
00079         pa_ord = new char[strlen(s) + 1];
00080         *pa_ord = 0;
00081 }

ParseBT::ParseBT ( char *  ,
char *  ,
short   
)

Definition at line 83 of file ParseBT.cpp.

References pa_breakchar, pa_disable, pa_enable, pa_nospace, pa_ord, pa_quote, pa_splits, pa_the_ptr, and pa_the_str.

00084 {
00085         pa_the_str = NULL;
00086         pa_splits = NULL;
00087         pa_ord = NULL;
00088         pa_the_ptr = 0;
00089         pa_breakchar = 0;
00090         pa_enable = pa_disable = 0;
00091         pa_nospace = 0;
00092         pa_quote = false;
00093 
00094         pa_the_str = new char[strlen(s) + 1];
00095         strcpy(pa_the_str,s);
00096         pa_splits = new char[strlen(sp) + 1];
00097         strcpy(pa_splits,sp);
00098         pa_ord = new char[strlen(s) + 1];
00099         *pa_ord = 0;
00100         pa_nospace = 1;
00101 }

ParseBT::~ParseBT (  ) 

Definition at line 105 of file ParseBT.cpp.

References FREE, pa_ord, pa_splits, and pa_the_str.

00106 {
00107         FREE(pa_the_str);
00108         FREE(pa_splits);
00109         FREE(pa_ord);
00110 }


Member Function Documentation

short ParseBT::issplit ( char   ) 

Definition at line 114 of file ParseBT.cpp.

References pa_splits.

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

00115 {
00116         short i;
00117 
00118         if (pa_splits)
00119                 for (i = 0; (size_t)i < strlen(pa_splits); i++)
00120                         if (pa_splits[i] == c)
00121                                 return 1;
00122         return 0;
00123 }

void ParseBT::getsplit ( void   ) 

Definition at line 125 of file ParseBT.cpp.

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

Referenced by getsplit().

00126 {
00127         int x;
00128 
00129         if (C == '=')
00130         {
00131                 x = pa_the_ptr++;
00132         } else
00133         {
00134                 while (C && (issplit(C)))
00135                         pa_the_ptr++;
00136                 x = pa_the_ptr;
00137                 while (C && !issplit(C) && C != '=')
00138                         pa_the_ptr++;
00139         }
00140         if (x == pa_the_ptr && C == '=')
00141                 pa_the_ptr++;
00142         strncpy(pa_ord,pa_the_str + x,pa_the_ptr - x);
00143         pa_ord[pa_the_ptr - x] = 0;
00144 }

void ParseBT::getsplit ( char *   ) 

Definition at line 234 of file ParseBT.cpp.

References getsplit(), and pa_ord.

00235 {
00236         ParseBT::getsplit();
00237         strcpy(s,pa_ord);
00238 }

void ParseBT::getword ( void   ) 

Definition at line 146 of file ParseBT.cpp.

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

Referenced by getvalue(), and getword().

00147 {
00148         int x;
00149         int disabled = 0;
00150         int quote = 0;
00151 
00152         if (pa_nospace)
00153         {
00154                 while (C && issplit(C))
00155                         pa_the_ptr++;
00156                 x = pa_the_ptr;
00157                 while (C && !issplit(C) && (C != pa_breakchar || !pa_breakchar || disabled))
00158                 {
00159                         if (pa_breakchar && C == pa_disable)
00160                                 disabled = 1;
00161                         if (pa_breakchar && C == pa_enable)
00162                                 disabled = 0;
00163                         if (pa_quote && C == '"')
00164                                 quote = 1;
00165                         pa_the_ptr++;
00166                         while (quote && C && C != '"')
00167                         {
00168                                 pa_the_ptr++;
00169                         }
00170                         if (pa_quote && C == '"')
00171                         {
00172                                 pa_the_ptr++;
00173                         }
00174                         quote = 0;
00175                 }
00176         } else
00177         {
00178                 if (C == pa_breakchar && pa_breakchar)
00179                 {
00180                         x = pa_the_ptr++;
00181                 } else
00182                 {
00183                         while (C && (C == ' ' || C == 9 || C == 13 || C == 10 || issplit(C)))
00184                                 pa_the_ptr++;
00185                         x = pa_the_ptr;
00186 #define DEB(x) 
00187 DEB(printf("Split starts at %d\n",x);)
00188                         while (C && C != ' ' && C != 9 && C != 13 && C != 10 && !issplit(C) &&
00189                          (C != pa_breakchar || !pa_breakchar || disabled))
00190                         {
00191 DEB(printf("Char '%c'\n",C);)
00192                                 if (pa_breakchar && C == pa_disable)
00193                                         disabled = 1;
00194                                 if (pa_breakchar && C == pa_enable)
00195                                         disabled = 0;
00196                                 if (pa_quote && C == '"')
00197                                 {
00198                                         quote = 1;
00199                                 pa_the_ptr++;
00200                                 while (quote && C && C != '"')
00201                                 {
00202                                         pa_the_ptr++;
00203                                 }
00204                                 if (pa_quote && C == '"')
00205                                 {
00206                                         pa_the_ptr++;
00207                                 }
00208                                 }
00209                                 else
00210                                         pa_the_ptr++;
00211                                 quote = 0;
00212                         }
00213                 }
00214                 if (x == pa_the_ptr && C == pa_breakchar && pa_breakchar)
00215                         pa_the_ptr++;
00216         }
00217         strncpy(pa_ord,pa_the_str + x,pa_the_ptr - x);
00218         pa_ord[pa_the_ptr - x] = 0;
00219 }

void ParseBT::getword ( char *   ) 

Definition at line 221 of file ParseBT.cpp.

References getword(), and pa_ord.

00222 {
00223         ParseBT::getword();
00224         strcpy(s,pa_ord);
00225 }

void ParseBT::getword ( char *  ,
int   
)

Definition at line 227 of file ParseBT.cpp.

References getword(), and pa_ord.

00228 {
00229         ParseBT::getword();
00230         strncpy(s,pa_ord,l - 1);
00231         s[l - 1] = 0;
00232 }

void ParseBT::getword ( char *  ,
char *  ,
int   
)

Definition at line 240 of file ParseBT.cpp.

References getword(), and pa_ord.

00241 {
00242         ParseBT::getword();
00243         *s = 0;
00244         while (strlen(s) + strlen(pa_ord) < (size_t)l)
00245                 strcat(s,fill);
00246         strcat(s,pa_ord);
00247 }

void ParseBT::getrest ( char *   ) 

Definition at line 249 of file ParseBT.cpp.

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

00250 {
00251         while (C && (C == ' ' || C == 9 || issplit(C)))
00252                 pa_the_ptr++;
00253         strcpy(s,pa_the_str + pa_the_ptr);
00254 }

long ParseBT::getvalue ( void   ) 

Definition at line 256 of file ParseBT.cpp.

References getword(), and pa_ord.

00257 {
00258         ParseBT::getword();
00259         return atol(pa_ord);
00260 }

void ParseBT::setbreak ( char   ) 

Definition at line 262 of file ParseBT.cpp.

References pa_breakchar.

00263 {
00264         pa_breakchar = c;
00265 }

int ParseBT::getwordlen ( void   ) 

Definition at line 267 of file ParseBT.cpp.

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

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

int ParseBT::getrestlen ( void   ) 

Definition at line 289 of file ParseBT.cpp.

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

00290 {
00291         int y = pa_the_ptr,len;
00292 
00293         while (C && (C == ' ' || C == 9 || issplit(C)))
00294                 pa_the_ptr++;
00295         len = strlen(pa_the_str + pa_the_ptr);
00296         pa_the_ptr = y;
00297         return len;
00298 }

void ParseBT::enablebreak ( char  c  )  [inline]

Definition at line 75 of file ParseBT.h.

References pa_enable.

00075                                  {
00076                 pa_enable = c;
00077         }

void ParseBT::disablebreak ( char  c  )  [inline]

Definition at line 78 of file ParseBT.h.

References pa_disable.

00078                                   {
00079                 pa_disable = c;
00080         }

void ParseBT::getline ( void   ) 

Definition at line 300 of file ParseBT.cpp.

References C, pa_ord, pa_the_ptr, and pa_the_str.

Referenced by getline().

00301 {
00302         int x;
00303 
00304 //      while (C && (C == 13 || C == 10))
00305 //              pa_the_ptr++;
00306         x = pa_the_ptr;
00307         while (C && C != 13 && C != 10)
00308                 pa_the_ptr++;
00309         strncpy(pa_ord,pa_the_str + x,pa_the_ptr - x);
00310         pa_ord[pa_the_ptr - x] = 0;
00311         if (C == 13)
00312                 pa_the_ptr++;
00313         if (C == 10)
00314                 pa_the_ptr++;
00315 }

void ParseBT::getline ( char *   ) 

Definition at line 317 of file ParseBT.cpp.

References getline(), and pa_ord.

00318 {
00319         getline();
00320         strcpy(s,pa_ord);
00321 }

void ParseBT::getline ( char *  ,
int   
)

Definition at line 323 of file ParseBT.cpp.

References getline(), and pa_ord.

00324 {
00325         getline();
00326         strncpy(s,pa_ord,l - 1);
00327         s[l - 1] = 0;
00328 }

int ParseBT::getptr ( void   )  [inline]

Definition at line 84 of file ParseBT.h.

References pa_the_ptr.

00084 { return pa_the_ptr; }

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

Definition at line 85 of file ParseBT.h.

References pa_quote.

00085 { pa_quote = b; }


Member Data Documentation

char* ParseBT::pa_the_str [private]

Definition at line 88 of file ParseBT.h.

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

char* ParseBT::pa_splits [private]

Definition at line 89 of file ParseBT.h.

Referenced by issplit(), ParseBT(), and ~ParseBT().

char* ParseBT::pa_ord [private]

Definition at line 90 of file ParseBT.h.

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

int ParseBT::pa_the_ptr [private]

Definition at line 91 of file ParseBT.h.

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

char ParseBT::pa_breakchar [private]

Definition at line 92 of file ParseBT.h.

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

char ParseBT::pa_enable [private]

Definition at line 93 of file ParseBT.h.

Referenced by enablebreak(), getword(), and ParseBT().

char ParseBT::pa_disable [private]

Definition at line 94 of file ParseBT.h.

Referenced by disablebreak(), getword(), and ParseBT().

short ParseBT::pa_nospace [private]

Definition at line 95 of file ParseBT.h.

Referenced by getword(), and ParseBT().

bool ParseBT::pa_quote [private]

Definition at line 96 of file ParseBT.h.

Referenced by EnableQuote(), getword(), and ParseBT().


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4