proj home

Files   Classes   Functions   Hierarchy  

html Class Reference

Help write html documents. More...

#include <html.h>

Collaboration diagram for html:

List of all members.

Static Public Member Functions

static int insert (commandline &cmd)
 Insert text into file.
static int insert (stringc &file, stringc &tag1, stringc &tag2, stringc &text)

Static Public Attributes

static string space = "&nbsp;"
 hmtl space character.
static string br = "<br />"
 html break line tag.


Detailed Description

Help write html documents.

Definition at line 9 of file html.h.


Member Function Documentation

int html::insert ( stringc file,
stringc tag1,
stringc tag2,
stringc text 
) [static]

Definition at line 67 of file html.cpp.

References tokenizer::current, tokenizer::readaslines(), tokenizer::reset(), tokenizer::seq, filestring::serialize(), and filestring::serializeInverse().

00073 {
00074   string s1;
00075   if (filestring::serialize(s1,file)==false)
00076   {
00077     cout << "error: could not read " << file << endl;
00078     return 1;
00079   }
00080 
00081   tokenizer tk;
00082   tk.readaslines(s1);
00083 
00084   liststringi i1;
00085   liststringi i2;
00086 
00087   bool found1=false;
00088   bool found2=false;
00089   for (tk.reset(); !tk; ++tk)
00090   {
00091     if (found1==false)
00092     {
00093       if (tk()==tag1)
00094       {
00095         found1=true;
00096         i1=tk.current;
00097       }
00098       continue;
00099     }
00100   
00101 //cout << SHOW3(tk()) << endl;
00102 //cout << SHOW3(tag2) << endl;
00103     if (tk()==tag2)
00104     {
00105       found2=true;
00106       i2=tk.current;
00107     }
00108   }
00109 
00110   if (found1==false)
00111     return 1;
00112   if (found2==false)
00113     return 1;
00114 
00115   // See if there is data between the tags.
00116   liststringi i4=i1;
00117   ++i4;
00118   if (i4!=i2)
00119     tk.seq.erase(i4,i2); // [i4,i2)
00120 //cout << SHOW3( i4==i2 ) << endl;
00121 
00122 //  cout << "***" <<  print(tk.seq) << "***" << endl;
00123   
00124 //cout << SHOW3(*i1) << endl;
00125 //cout << SHOW3(*i2) << endl;
00126 
00127 //cout << SHOW3(*(i1+1)==*i2) << endl;
00128 //cout << "insert at i2 text" << endl;
00129   tk.seq.insert(i2,text);  // Insert before i2.
00130 
00131   // Add carriage return as tokenizer stripped these.
00132   for (tk.reset(); !tk; ++tk)
00133     *tk += "\n";
00134 
00135 //  cout << "***" <<  print(tk.seq) << "***" << endl;
00136   if (filestring::serializeInverse(file,(stringc)tk)==false)
00137     return 1;
00138 
00139   return 0;
00140 }

int html::insert ( commandline cmd  )  [static]

Insert text into file.

$ ./main prog=100 file="cmd02.txt"

cmd02.txt is an xml file.

<tag1> </tag1> beginning substitution marker. <tag2> </tag2> end substitution marker. <text> </text> string to be inserted <file> </file> file to be edited.

If successful 0 int returned.

Definition at line 10 of file html.cpp.

References commandline::mapvar(), tokenizerlocal::read(), and filestring::serialize().

Referenced by cireport::docfile_update(), cireport::reportfile_update(), and htmltest::test01().

00011 {
00012   string filename;
00013 
00014   cmd.mapvar(filename,"file");
00015   if (filename.empty())
00016   {
00017     cout << "error: file=\"\"" << endl;
00018     return 1;
00019   }
00020 
00021   string s0;
00022   if (filestring::serialize(s0,filename)==false)
00023   {
00024     cout << "error: unable to open " << filename << endl;
00025     return 1;
00026   };
00027 
00028   cout << "Reading " << filename << endl;
00029 
00030   tokenizer tk2(s0);
00031   tokenizerlocal tl2(tk2);
00032 
00033   string tag1;
00034   string tag2;
00035   string text;
00036   string file;
00037 
00038   int res=0;
00039   if (tl2.read(tag1,"tag1")==false)
00040   {
00041     res=1;
00042     cout << "error: no <tag1></tag1>" << endl;
00043   };
00044   if (tl2.read(tag2,"tag2")==false)
00045   {
00046     res=1;
00047     cout << "error: no <tag2></tag2>" << endl;
00048   };
00049   if (tl2.read(text,"text")==false)
00050   {
00051     res=1;
00052     cout << "error: no <text></text>" << endl;
00053   };
00054   if (tl2.read(file,"file")==false)
00055   {
00056     res=1;
00057     cout << "error: no <file></file>" << endl;
00058   };
00059   
00060   if (res==1)
00061     return 1;
00062 
00063   return insert(file,tag1,tag2,text);
00064 }


Member Data Documentation

string html::br = "<br />" [static]

html break line tag.

Definition at line 17 of file html.h.

string html::space = "&nbsp;" [static]

hmtl space character.

Definition at line 15 of file html.h.


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

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