proj home

Files   Classes   Functions   Hierarchy  

tokenizerlocal.cpp

Go to the documentation of this file.
00001 #include <typedefs.h>
00002 #include <tokenizerlocal.h>
00003 
00004 long int tokenizerlocal::countermax=10000000;
00005 
00006 tokenizerlocal::tokenizerlocal(tokenizer& ref_)
00007   : ref(ref_), parent(0)
00008 {
00009   i1=ref.current;
00010   i2=ref.seq.end();
00011   iend=ref.seq.end();
00012 }
00013 
00014 tokenizerlocal::tokenizerlocal
00015 (
00016   tokenizerlocal& tl
00017 )
00018   : ref(tl.ref), parent(&tl)
00019 {
00020   reset(tl);
00021 }
00022 
00023 stringc & tokenizerlocal::operator() () const 
00024 { 
00025   return *ref.current; 
00026 }
00027 
00028 void tokenizerlocal::operator ++ () 
00029 { 
00030   if (ref.current!=i2) 
00031     ++ref; 
00032 }
00033 
00034 boolc tokenizerlocal::atomize_next
00035 (
00036   stringc & atom1, 
00037   stringc& atom2
00038 )
00039 {
00040   if (ref.atomize_next(atom1)==false)
00041     return false;
00042   i1=ref.current;
00043 
00044   if (ref.atomize_next(atom2)==false)
00045     return false;
00046   i2=ref.current;
00047 
00048   return true;
00049 }
00050 
00051 boolc tokenizerlocal::scope(stringc& tag1)
00052 { 
00053   //bool res = ref.atomize_next_tag(i1,i2,tag1); 
00054   bool res = ref.atomize_next_tag(i1,i2,tag1,iend); 
00055 
00056 
00057 
00058 //cout << "scope(stringc&) " << res << endl;
00059 //cout << "  " << SHOW(*i1) << " " << SHOW(*i2) << SHOW(ref.current) << endl;
00060   return res;
00061 }
00062 
00063 boolc tokenizerlocal::scope
00064 (
00065   stringc& tag1, 
00066   stringc& tag2
00067 )
00068 {
00069   if (scope(tag1)==false)
00070     return false;
00071 
00072 //cout << "found " << SHOW(tag1) << endl;
00073   return scope(tag2);
00074 }
00075 
00076 boolc tokenizerlocal::scope
00077 (
00078   stringc& tag1, 
00079   stringc& tag2, 
00080   stringc& tag3
00081 )
00082 {
00083   if (scope(tag1,tag2)==false)
00084     return false;
00085 
00086   return scope(tag3);
00087 }
00088 
00089 boolc tokenizerlocal::scope
00090 (
00091   stringc& tag1, 
00092   stringc& tag2, 
00093   stringc& tag3,
00094   stringc& tag4
00095 )
00096 {
00097   if (scope(tag1,tag2,tag3)==false)
00098     return false;
00099 
00100   return scope(tag4);
00101 }
00102 
00103 boolc tokenizerlocal::scope
00104 (
00105   stringc& tag1, 
00106   stringc& tag2, 
00107   stringc& tag3,
00108   stringc& tag4,
00109   stringc& tag5
00110 )
00111 {
00112   if (scope(tag1,tag2,tag3,tag4)==false)
00113     return false;
00114 
00115   return scope(tag5);
00116 }
00117 
00118 boolc tokenizerlocal::scope
00119 (
00120   stringc& tag1, 
00121   stringc& tag2, 
00122   stringc& tag3,
00123   stringc& tag4,
00124   stringc& tag5,
00125   stringc& tag6
00126 )
00127 {
00128   if (scope(tag1,tag2,tag3,tag4,tag5)==false)
00129     return false;
00130 
00131   return scope(tag6);
00132 }
00133 
00134 boolc tokenizerlocal::operator ! () const 
00135 { 
00136   if (ref.current==i2) 
00137     return false; 
00138   assertreturnfalse(ref.current!=iend); 
00139   return true; 
00140 }
00141 
00142 void tokenizerlocal::reset()
00143 {
00144   // Global scope. No parent so reset the tokenizer.
00145   if (parent==0)
00146   {
00147     ref.reset();
00148     i1 = ref.current;
00149 
00150     return;
00151   }
00152 
00153   // parent != 0
00154   // Assume valid pointer.
00155   i1=parent->i1;
00156   i2=parent->i2;
00157   iend=parent->i2;
00158   ref.current=parent->i1;
00159 }
00160 
00161 void tokenizerlocal::reset(tokenizerlocal& tl)
00162 {
00163   i1=tl.i1;
00164   i2=tl.i2;
00165   iend=tl.i2;
00166   ref.current=i1;
00167 }
00168 
00169 void tokenizerlocal::endpointcontract()
00170 {
00171   iend=i2;
00172 }
00173 
00174 void tokenizerlocal::endpointexpand()
00175 {
00176   i2=iend;
00177 }
00178 
00179 void tokenizerlocal::endpointreset()
00180 {
00181   iend=ref.seq.end();
00182   i2=iend;
00183 }
00184 
00185 boolc tokenizerlocal::scopesearch(stringc& tag)
00186 {
00187   // Using the current as a starting point.
00188   string tag1=("<"+tag+">");
00189 
00190   for ( ; !ref; )
00191   {
00192     if (*ref==tag1)
00193       break;
00194 
00195     if (ref.current!=iend)
00196       ++ref;
00197   }
00198   if (ref.current==iend)
00199     return false;
00200 
00201   i1 = ref.current;
00202   ++ref;
00203 
00204   string tag2=("</"+tag+">");
00205   for ( ; !ref; )
00206   {
00207     if (*ref==tag2)
00208       break;
00209     if (ref.current!=iend)
00210       ++ref;
00211   }
00212   if (ref.current==iend)
00213     return false;
00214 
00215   i2 = ref.current;
00216 
00217   ref.current=i1;
00218 
00219   assert(*i1==tag1);
00220   assert(*i2==tag2);
00221 
00222   return true;
00223 }
00224 
00225 boolc tokenizerlocal::erasetag(stringc& tag)
00226 {
00227   ref.current=i1;
00228   assertreturnfalse( ref()==("<"+tag+">"));
00229   assertreturnfalse( *i2==("</"+tag+">") );
00230   ++i2;
00231   ref.seq.erase(i1,i2);
00232 
00233   return true;
00234 }
00235 
00236 boolc tokenizerlocal::writetag(stringc& val, stringc& tag)
00237 {
00238   //ref.current=i1;
00239 
00240   assertreturnfalse( scopesearch(tag) );
00241 
00242   assert( *i1==("<"+tag+">"));
00243   ++ref;  
00244   assert( *i2==("</"+tag+">") );
00245 /*
00246   assertreturnfalse( ref()==("<"+tag+">"));
00247   ++ref;  
00248   assertreturnfalse( *i2==("</"+tag+">") );
00249 */
00250   
00251   ref.seq.erase(ref.current,i2);
00252 
00253   // Insert the new element in.
00254   liststringi k=i1;
00255   ++k;
00256   ref.seq.insert(k,val);
00257   
00258   return true;
00259 }
00260 
00261 boolc tokenizerlocal::readtag(string& val, stringc& tag)
00262 {
00263   val="";
00264   assertreturnfalse( ref()==("<"+tag+">"));
00265   ++ref;
00266 
00267   static long int counter;
00268   counter=0;
00269 
00270   stringc tagend("</"+tag+">");
00271   val.empty();
00272   for ( ; ref()!=tagend; ++ref )
00273   {
00274     val += ref();
00275 
00276     // Exit counter logic if not end token found.
00277     ++counter;
00278     if(counter>countermax)
00279       return false;
00280   }
00281 
00282   return true;
00283 }
00284 
00285 boolc tokenizerlocal::read(string& str, stringc& tag1)
00286 {
00287   if( scope(tag1)==false)
00288     return false;
00289 
00290   return readtag(str,tag1);
00291 }
00292 
00293 boolc tokenizerlocal::read(string& str, stringc& tag1, stringc& tag2)
00294 {
00295   if( scope(tag1,tag2)==false)
00296     return false;
00297 
00298   return readtag(str,tag2);
00299 }
00300 
00301 boolc tokenizerlocal::read(string& str, stringc& tag1, stringc& tag2, stringc& tag3)
00302 {
00303   if( scope(tag1,tag2,tag3)==false)
00304     return false;
00305 
00306   return readtag(str,tag3);
00307 }
00308 
00309 boolc tokenizerlocal::read(string& str, stringc& tag1, stringc& tag2, stringc& tag3, stringc& tag4)
00310 {
00311   if( scope(tag1,tag2,tag3,tag4)==false)
00312     return false;
00313 
00314   return readtag(str,tag4);
00315 }
00316 
00317 boolc tokenizerlocal::read(string& str, stringc& tag1, stringc& tag2, stringc& tag3, stringc& tag4, stringc& tag5)
00318 {
00319   if( scope(tag1,tag2,tag3,tag4,tag5)==false)
00320     return false;
00321 
00322   return readtag(str,tag5);
00323 }
00324 
00325 boolc tokenizerlocal::read(string& str, stringc& tag1, stringc& tag2, stringc& tag3, stringc& tag4, stringc& tag5, stringc& tag6)
00326 {
00327   if( scope(tag1,tag2,tag3,tag4,tag5,tag6)==false)
00328     return false;
00329 
00330   return readtag(str,tag6);
00331 }
00332 
00333 boolc tokenizerlocal::boundscope(stringc& tag1)
00334 {
00335   if (scope(tag1)==false)
00336     return false;
00337 
00338   iend=i2;
00339   return true;
00340 }
00341 
00342 /*
00343 tokenizerscope::tokenizerscope
00344 (
00345   tokenizerlocal& tl_,
00346   stringc & scopetag_
00347 )
00348   : tokenizerlocal(tl_), tl(tl_),
00349   scopetag(scopetag_)
00350 {
00351   reset();
00352 }
00353 
00354 void tokenizerscope::reset()
00355 {
00356   tokenizerlocal::reset(tl);
00357 }
00358 
00359 boolc tokenizerscope::operator ! ()
00360 {
00361   return scope(scopetag);
00362 }
00363 
00364 tokenizerscope::tokenizerscope
00365 (
00366   tokenizer& tk,
00367   stringc & scopetag_
00368 )
00369   : tokenizerlocal(tk), tl(*this), scopetag(scopetag_)
00370 {
00371 }
00372 
00373 */
00374 
00375 stringc tokenizerlocal::debug01() const
00376 {
00377   string s0;
00378   s0 += ("i1=" + *i1);
00379   s0 += (" i2=" + *i2);
00380   s0 += (" iend=" + *iend);
00381   return s0;
00382 }
00383 
00384 tokenizerlocalvar::tokenizerlocalvar
00385 (
00386   tokenizerlocal& tkl, 
00387   stringc& objtag_
00388 )
00389   : tokenizerlocal(tkl), objtag(objtag_)
00390 {
00391 }
00392 
00393 boolc tokenizerlocalvar::operator ! ()
00394 {
00395   return scope(objtag);
00396 }
00397 

Generated on Fri Mar 4 00:49:29 2011 for Chelton Evans Source by  doxygen 1.5.8