proj home

Files   Classes   Functions   Hierarchy  

stringtagparser Class Reference

Primitive xml reading parser. More...

#include <stringtagparser.h>

Inheritance diagram for stringtagparser:
Collaboration diagram for stringtagparser:

List of all members.

Public Member Functions

 stringtagparser (stringc &arg_)
 Argument string for parsing.
stringc data (stringc &tag1)
 Hierarchical one level deep.
stringc data (stringc &tag1, stringc &tag2)
 Hierarchical two levels deep.
stringc data (stringc &tag1, stringc &tag2, stringc &tag3)
 Hierarchical three levels deep.
stringc data (stringc &tag1, stringc &tag2, stringc &tag3, stringc &tag4)
 Hierarchical four levels deep.
stringc data (stringc &tag1, stringc &tag2, stringc &tag3, stringc &tag4, stringc &tag5)
 Hierarchical five levels deep.
stringc data (stringc &tag1, stringc &tag2, stringc &tag3, stringc &tag4, stringc &tag5, stringc &tag6)
 Hierarchical six levels deep.
stringc data_with_tags (stringc &tag1) const
 Another function could interpret hence the tags need to be extracted with the data.

Public Attributes

string arg
 The string being parsed.
bool tagfound
 State set to true when data(tag1.


Detailed Description

Primitive xml reading parser.

For a parser with reading, writing and scope see tokenizerlocal.h .

Taking a subset of XML where tagged hierarchical data can be extracted.

No space in tags. < maze> should be <maze>.

Not concerned with efficiency as reading and writing done infrequently.

The data need not strictly be xml/tagged. For example the client interprets the data, so the parser just extracts a string that was wrapped in tags. This data could be order dependent and interpreted by the class.

e.g. "1 2 .02" could serialize a particular class/object. Order dependent data is easier to code.

Or the data may not be order independent. So could "start=1 end=2 changex=.02".

By restricting the data to be only tagged from the stringtagparser's perspective we get a full parser. The work is now up to the client classes to organize the data for simple parsing.

For example properties <mytag val="25"> in the tags are not supported, non-unique tag lists are not supported (see stringtagiter class below). <funkyobj><obj>23,12,9</obj><obj>12,-3,-1</obj></funkyobj> representation could become

  <funkyobj><obj>
    <n>2</n>
    <1>23,12,9</1>
    <2>12,-3,-1</2>
  </funkyobj>
  or keep tag which I recommend
  <funkyobj>
    <n>2</n>
    <1><obj>13,12,9</obj></1>
    <2><obj>13,12,9</obj></2>
  </funkyobj>
 and the non-unique data is made unique.

An alternative to above example is order dependent data. <funkyobj><obj>2 23,12,9 12,-3,-1</obj></funkyobj> <funkyobj><obj><n>2</n> <array>23,12,9 12,-3,-1</array></obj></funkyobj>

I like wrapping a non-unique object in a unique tags. This lets the data structures serialization be written independently (when reading extract the tagged data), it then is up to the client to first extract the unique data out.

Definition at line 68 of file stringtagparser.h.


Constructor & Destructor Documentation

stringtagparser::stringtagparser ( stringc arg_  ) 

Argument string for parsing.

Definition at line 6 of file stringtagparser.cpp.

00007   : arg(arg_)
00008 {
00009 }


Member Function Documentation

stringc stringtagparser::data ( stringc tag1,
stringc tag2,
stringc tag3,
stringc tag4,
stringc tag5,
stringc tag6 
)

Hierarchical six levels deep.

Definition at line 117 of file stringtagparser.cpp.

References data().

00125 {
00126   stringtagparser sp( data(tag1) );
00127   return sp.data(tag2,tag3,tag4,tag5,tag6);
00128 }

stringc stringtagparser::data ( stringc tag1,
stringc tag2,
stringc tag3,
stringc tag4,
stringc tag5 
)

Hierarchical five levels deep.

Definition at line 103 of file stringtagparser.cpp.

References data().

00110 {
00111   stringtagparser sp( data(tag1) );
00112   return sp.data(tag2,tag3,tag4,tag5);
00113 }

stringc stringtagparser::data ( stringc tag1,
stringc tag2,
stringc tag3,
stringc tag4 
)

Hierarchical four levels deep.

Definition at line 91 of file stringtagparser.cpp.

References data().

00097 {
00098   stringtagparser sp( data(tag1) );
00099   return sp.data(tag2,tag3,tag4);
00100 }

stringc stringtagparser::data ( stringc tag1,
stringc tag2,
stringc tag3 
)

Hierarchical three levels deep.

Definition at line 80 of file stringtagparser.cpp.

References data().

00085 {
00086   stringtagparser sp( data(tag1) );
00087   return sp.data(tag2,tag3);
00088 }

stringc stringtagparser::data ( stringc tag1,
stringc tag2 
)

Hierarchical two levels deep.

Definition at line 70 of file stringtagparser.cpp.

References data().

00074 {
00075   stringtagparser sp( data(tag1) );
00076   return sp.data(tag2);
00077 }

stringc stringtagparser::data ( stringc tag1  ) 

Hierarchical one level deep.

Definition at line 11 of file stringtagparser.cpp.

References arg, and tagfound.

Referenced by data(), pathlineseg::serializeInverse(), stringtagparsertest::test01(), stringtagparsertest::test02(), stringtagparsertest::test04(), stringtagparsertest::unittest01(), and stringtagparsertest::unittest02().

00012 {
00013   tagfound=false;
00014 
00015   string tagbeg="<"+tag1+">";
00016   string tagend="</"+tag1+">";
00017   string::size_type i0 = arg.find(tagbeg);
00018 
00019   if (i0==string::npos)
00020     return "";
00021 
00022   //assertreturnT(!(i0==string::npos),"");
00023 
00024 //cout << "i0=" << i0 << endl;
00025   string::size_type i1 = arg.find(tagend);
00026   if (i1==string::npos)
00027     return "";
00028   //assertreturnT(i1==string::npos,"");
00029   tagfound=true; 
00030 //cout << "i1=" << i1 << endl;
00031 
00032 //cout << i1-i0 - tagbeg.length() << endl;
00033   
00034 
00035 //cout << arg.substr(i0) << endl;
00036   string::size_type i2=i0+tagbeg.length();
00037 //cout << arg.substr(i2,i1-i2) << endl;
00038 
00039   return arg.substr(i2,i1-i2);
00040 }

stringc stringtagparser::data_with_tags ( stringc tag1  )  const

Another function could interpret hence the tags need to be extracted with the data.

Definition at line 42 of file stringtagparser.cpp.

References arg.

Referenced by stringtagparsertest::test01(), and stringtagparsertest::unittest01().

00043 {
00044   string tagbeg="<"+tag1+">";
00045   string tagend="</"+tag1+">";
00046   string::size_type i0 = arg.find(tagbeg);
00047 
00048   //assertreturnT(!(i0==string::npos),"");
00049   if (i0==string::npos)
00050     return "";
00051 
00052 //cout << "i0=" << i0 << endl;
00053   string::size_type i1 = arg.find(tagend);
00054   if (i1==string::npos)
00055     return "";
00056   //assertreturnT(!(i1==string::npos),"");
00057 //cout << "i1=" << i1 << endl;
00058 
00059 //cout << i1-i0 - tagbeg.length() << endl;
00060   
00061 
00062 //cout << arg.substr(i0) << endl;
00063 //  string::size_type i2=i0+tagbeg.length();
00064 //cout << arg.substr(i2,i1-i2) << endl;
00065 
00066   return arg.substr(i0,i1-i0+tagend.length());
00067 }


Member Data Documentation

The string being parsed.

Definition at line 77 of file stringtagparser.h.

Referenced by data(), data_with_tags(), and stringtagiter::reset().

State set to true when data(tag1.

..) finds the matching tags.

Definition at line 81 of file stringtagparser.h.

Referenced by data(), and stringtagparsertest::unittest02().


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:50:18 2011 for Chelton Evans Source by  doxygen 1.5.8