aboutsummaryrefslogtreecommitdiff
path: root/src/xmlreader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmlreader.cpp')
-rw-r--r--src/xmlreader.cpp108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/xmlreader.cpp b/src/xmlreader.cpp
new file mode 100644
index 0000000..432ecc1
--- /dev/null
+++ b/src/xmlreader.cpp
@@ -0,0 +1,108 @@
1#include "xmlreader.h"
2
3Bu::XmlReader::XmlReader( Bu::Stream &sIn ) :
4 sIn( sIn )
5{
6}
7
8Bu::XmlReader::~XmlReader()
9{
10}
11
12const char *Bu::XmlReader::lookahead( int nAmnt )
13{
14 if( sBuf.getSize() >= nAmnt )
15 return sBuf.getStr();
16
17 int nNew = nAmnt - sBuf.getSize();
18 char *buf = new char[nNew];
19 sIn.read( buf, nNew );
20 sBuf.append( buf );
21
22 return sBuf.getStr();
23}
24
25void Bu::XmlReader::burn( int nAmnt )
26{
27 if( sBuf.getSize() < nAmnt )
28 {
29 lookahead( nAmnt );
30 }
31
32 sBuf.remove( nAmnt );
33}
34
35void Bu::XmlNode::checkString( const char *str, int nLen )
36{
37 if( !strncmp( str, lookahead( nLen ), nLen ) )
38 {
39 burn( nLen );
40 return;
41 }
42
43 throw Bu::ExceptionBase("Expected string '%s'", str );
44}
45
46Bu::XmlNode *Bu::XmlReader::read()
47{
48 prolog();
49}
50
51void Bu::XmlReader::prolog()
52{
53 XMLDecl();
54 Misc();
55}
56
57void Bu::XmlReader::XMLDecl()
58{
59 checkString("<?xml", 5 );
60 VersionInfo();
61 EncodingDecl();
62 SDDecl();
63 S();
64}
65
66void Bu::XmlReader::Misc()
67{
68}
69
70void Bu::XmlReader::S()
71{
72 for( int j = 0;; j++ )
73 {
74 char c = *lookahead( 1 );
75 if( c == 0x20 || c == 0x9 || c == 0xD || c == 0xA )
76 continue;
77 if( j == 0 )
78 printf("Error, expected whitespace!\n");
79 return;
80 }
81}
82
83void Bu::XmlReader::S()
84{
85 for(;;)
86 {
87 char c = *lookahead( 1 );
88 if( c == 0x20 || c == 0x9 || c == 0xD || c == 0xA )
89 continue;
90 return;
91 }
92}
93
94void Bu::XmlReader::VersionInfo()
95{
96 S();
97 checkString("version", 7 );
98
99}
100
101void Bu::XmlReader::Eq()
102{
103 Sq();
104 checkString("=", 1 );
105 Sq();
106}
107
108