Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

FileParser Class Reference

#include <FileParser.hpp>

Inheritance diagram for FileParser::

Input CFile XMLParse List of all members.

Public Methods

char OpenFile (char *filename)
unsigned GetCurLineNo ()
char ReadStringUntil (char **destptr, int *destlen, char stopatwspace, char c1, char c2)
char ReadStringUntil (char **destptr, int *destlen, char c1)
char ReadWhiteSpaces (char **destptr, int *destlen)
char ReadStringUntil (char **destptr, int *destlen, char *searchstr)
void SkipChar ()
void GetChar (char *c)
void SkipData (int len)

Member Function Documentation

void FileParser::GetChar char *    c [inline]
 

Reimplemented from Input.

Definition at line 380 of file FileParser.hpp.

00382    {
00383       Input::GetChar(c);
00384       if(*c=='\n')
00385          curlineno++;
00386    }

unsigned FileParser::GetCurLineNo   [inline]
 

Definition at line 50 of file FileParser.hpp.

00050 {  return curlineno; }

char FileParser::OpenFile char *    filename [inline]
 

Reimplemented from Input.

Definition at line 42 of file FileParser.hpp.

00044    {
00045       curlineno=1;
00046 
00047       return Input::OpenFile(filename);
00048    }

char FileParser::ReadStringUntil char **    destptr,
int *    destlen,
char *    searchstr
[inline]
 

Definition at line 284 of file FileParser.hpp.

00291    {
00292       char  *ptr;
00293       int   len,stringlen;
00294       char  refilled=0;
00295       int   curoffset=0,i;
00296       char  *curptr;
00297 
00298       len=GetCurBlockPtr(&ptr);
00299       stringlen=strlen(searchstr);
00300 
00301       do
00302       {
00303          // We try to find the first character
00304          curptr=ptr+curoffset;
00305          i=len-curoffset;
00306          while(i!=0)
00307          {
00308             if(*curptr==searchstr[0])
00309                break;
00310             if(*curptr=='\n')
00311                curlineno++;
00312             curptr++;
00313             i--;
00314          }
00315          if(i==0)
00316             // We couldn't find characters --> Try to refill
00317          {
00318             if(!refilled)
00319             {
00320                curoffset=len; // We can skip the part that we already scanned
00321                refilled=1;
00322                RefillAndGetCurBlockPtr(&ptr,&len);
00323                continue;
00324             }
00325             else
00326                // We couldn't find the first character in the current block --> We return current block
00327             {
00328                *destptr=ptr;
00329                *destlen=len;
00330                FastSkipData(len);
00331                return 0;
00332             }
00333          }
00334 
00335          // We found the first character at *curptr
00336 
00337          curoffset=curptr-ptr;
00338 
00339          if(curoffset+stringlen>len)
00340             // There is not enough room for the search string?
00341          {
00342             if(!refilled) // If we didn't try refill yet, we try it now
00343             {
00344                refilled=1;
00345                RefillAndGetCurBlockPtr(&ptr,&len);
00346             }
00347             if(curoffset+stringlen>len) // Still not enough space?
00348             {
00349                *destptr=ptr;
00350                *destlen=curoffset; // We take everything up to (but excluding) the first character at *curptr
00351                FastSkipData(curoffset);
00352                return 0;
00353             }
00354          }
00355          // Now we check whether ptr+offset is equal to the searchstring
00356 
00357          if(memcmp(ptr+curoffset,searchstr,stringlen)==0)
00358          // We found it !
00359          {
00360             *destptr=ptr;
00361             *destlen=curoffset+stringlen;
00362             FastSkipData(*destlen);
00363             return 1;
00364          }
00365          // We didn't find it ==> We go to next character after ptr+curoffset
00366          curoffset++;
00367       }
00368       while(1);
00369    }

char FileParser::ReadStringUntil char **    destptr,
int *    destlen,
char    c1
[inline]
 

Definition at line 141 of file FileParser.hpp.

00149    {
00150       char *curptr,*ptr;
00151       int  len,i;
00152 
00153       len=GetCurBlockPtr(&ptr);
00154       curptr=ptr;
00155 
00156       i=len;
00157 
00158       // We search for character 'c1'.
00159       // If we find such a character, then we store the pointer in 'destptr'
00160       // and the length in 'destlen' and exit.
00161       while(i!=0)
00162       {
00163          if(*curptr==c1)
00164          {
00165             curptr++;
00166             *destptr=ptr;
00167             *destlen=curptr-ptr;
00168             FastSkipData(*destlen);
00169             return 1;
00170          }
00171          if(*curptr=='\n')
00172             curlineno++;
00173          curptr++;
00174          i--;
00175       }
00176 
00177       // We couldn't find characters --> Try to refill
00178 
00179       RefillAndGetCurBlockPtr(&ptr,&len);
00180       curptr=ptr;
00181 
00182       i=len;
00183 
00184       // Now we try the same thing again:
00185 
00186       // We search for character 'c1'.
00187       // If we find such a character, then we store the pointer in 'destptr'
00188       // and the length in 'destlen' and exit.
00189       while(i!=0)
00190       {
00191          if(*curptr==c1)
00192          {
00193             curptr++;
00194             *destptr=ptr;
00195             *destlen=curptr-ptr;
00196             FastSkipData(*destlen);
00197             return 1;
00198          }
00199          if(*curptr=='\n')
00200             curlineno++;
00201          curptr++;
00202          i--;
00203       }
00204 
00205       *destptr=ptr;
00206       *destlen=len;
00207       FastSkipData(len);
00208       return 0;
00209    }

char FileParser::ReadStringUntil char **    destptr,
int *    destlen,
char    stopatwspace,
char    c1,
char    c2
[inline]
 

Definition at line 52 of file FileParser.hpp.

00062    {
00063       char *curptr,*ptr;
00064       int  len,i;
00065 
00066       // Let's get as much as possible from the input buffer
00067       len=GetCurBlockPtr(&ptr);
00068       curptr=ptr;
00069 
00070       i=len;
00071       // We search for characters 'c1', 'c2', ' ', '\t' ...
00072       // If we find such a character, then we store the pointer in 'destptr'
00073       // and the length in 'destlen' and exit.
00074       while(i!=0)
00075       {
00076          if(*curptr=='\n')
00077             curlineno++;
00078 
00079          if((*curptr==c1)||(*curptr==c2))
00080          {
00081             curptr++;
00082             *destptr=ptr;
00083             *destlen=curptr-ptr;
00084             FastSkipData(*destlen);
00085             return 1;
00086          }
00087          if((stopatwspace)&&((*curptr==' ')||(*curptr=='\t')||(*curptr=='\r')||(*curptr=='\n')))
00088          {
00089             *destptr=ptr;
00090             *destlen=curptr-ptr;
00091             FastSkipData(*destlen);
00092             return 1;
00093          }
00094          curptr++;
00095          i--;
00096       }
00097 
00098       // We couldn't find characters --> Try to refill
00099 
00100       RefillAndGetCurBlockPtr(&ptr,&len);
00101 
00102       curptr=ptr;
00103 
00104       i=len;
00105 
00106       // Now we try the same thing again:
00107 
00108       // We search for characters 'c1', 'c2', ' ', '\t' ...
00109       // If we find such a character, then we store the pointer in 'destptr'
00110       // and the length in 'destlen' and exit.
00111       while(i!=0)
00112       {
00113          if(*curptr=='\n')
00114             curlineno++;
00115 
00116          if((*curptr==c1)||(*curptr==c2))
00117          {
00118             curptr++;
00119             *destptr=ptr;
00120             *destlen=curptr-ptr;
00121             FastSkipData(*destlen);
00122             return 1;
00123          }
00124          if((stopatwspace)&&((*curptr==' ')||(*curptr=='\t')||(*curptr=='\r')||(*curptr=='\n')))
00125          {
00126             *destptr=ptr;
00127             *destlen=curptr-ptr;
00128             FastSkipData(*destlen);
00129             return 1;
00130          }
00131          curptr++;
00132          i--;
00133       }
00134 
00135       *destptr=ptr;
00136       *destlen=len;
00137       FastSkipData(len);
00138       return 0;
00139    }

char FileParser::ReadWhiteSpaces char **    destptr,
int *    destlen
[inline]
 

Definition at line 211 of file FileParser.hpp.

00219    {
00220       char *curptr,*ptr;
00221       int  len,i;
00222 
00223       len=GetCurBlockPtr(&ptr);
00224       curptr=ptr;
00225 
00226       i=len;
00227 
00228       // We search for non-white-space characters
00229       // If we find such a character, then we store the pointer in 'destptr'
00230       // and the length in 'destlen' and exit.
00231       while(i!=0)
00232       {
00233          if((*curptr!=' ')&&(*curptr!='\t')&&(*curptr!='\r')&&(*curptr!='\n'))
00234             // No white space?
00235          {
00236             *destptr=ptr;
00237             *destlen=curptr-ptr;
00238             FastSkipData(*destlen);
00239             return 1;
00240          }
00241          if(*curptr=='\n')
00242             curlineno++;
00243          curptr++;
00244          i--;
00245       }
00246 
00247       // We couldn't find characters --> Try to refill
00248 
00249       RefillAndGetCurBlockPtr(&ptr,&len);
00250       curptr=ptr;
00251 
00252       i=len;
00253 
00254       // Now we try the same thing again:
00255 
00256       // We search for non-white-space characters
00257       // If we find such a character, then we store the pointer in 'destptr'
00258       // and the length in 'destlen' and exit.
00259       while(i!=0)
00260       {
00261          if((*curptr!=' ')&&(*curptr!='\t')&&(*curptr!='\r')&&(*curptr!='\n'))
00262             // No white space?
00263          {
00264             *destptr=ptr;
00265             *destlen=curptr-ptr;
00266             FastSkipData(*destlen);
00267             return 1;
00268          }
00269          if(*curptr=='\n')
00270             curlineno++;
00271          curptr++;
00272          i--;
00273       }
00274 
00275       // We look through the entire buffer and couldn't find a non-white-space
00276       // character?
00277 
00278       *destptr=ptr;
00279       *destlen=len;
00280       FastSkipData(len);
00281       return 0;
00282    }

void FileParser::SkipChar   [inline]
 

Reimplemented from Input.

Definition at line 371 of file FileParser.hpp.

00373    {
00374       char c;
00375       Input::GetChar(&c);
00376       if(c=='\n')
00377          curlineno++;
00378    }

void FileParser::SkipData int    len [inline]
 

Reimplemented from Input.

Definition at line 388 of file FileParser.hpp.

00390    {
00391       char *ptr;
00392       int  mylen;
00393       mylen=GetCurBlockPtr(&ptr);
00394 
00395       for(int i=0;i<len;i++)
00396       {
00397          if(*ptr=='\n')
00398             curlineno++;
00399          ptr++;
00400       }
00401       Input::SkipData(len);
00402    }


The documentation for this class was generated from the following file:
Generated on Sat Oct 13 16:08:53 2001 for XMILL by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001