aboutsummaryrefslogtreecommitdiff
path: root/src/inprogress
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-05-09 15:04:31 +0000
committerMike Buland <eichlan@xagasoft.com>2007-05-09 15:04:31 +0000
commitad92dc50b7cdf7cfe086f21d19442d03a90fd05d (patch)
tree9ca6f7bde704cb44276a05b6e83f36754e07f732 /src/inprogress
parent2e035fee36768e3c765b7f5dc10bf0a3b7d2448b (diff)
downloadlibbu++-ad92dc50b7cdf7cfe086f21d19442d03a90fd05d.tar.gz
libbu++-ad92dc50b7cdf7cfe086f21d19442d03a90fd05d.tar.bz2
libbu++-ad92dc50b7cdf7cfe086f21d19442d03a90fd05d.tar.xz
libbu++-ad92dc50b7cdf7cfe086f21d19442d03a90fd05d.zip
Just a few things re-arranged, moved the new taf/xml systems to the inprogress
directory, and moved the old xml system in, so it will require heavy changes.
Diffstat (limited to 'src/inprogress')
-rw-r--r--src/inprogress/tafdocument.cpp9
-rw-r--r--src/inprogress/tafdocument.h22
-rw-r--r--src/inprogress/tafnode.cpp9
-rw-r--r--src/inprogress/tafnode.h21
-rw-r--r--src/inprogress/tafreader.cpp11
-rw-r--r--src/inprogress/tafreader.h25
-rw-r--r--src/inprogress/tafwriter.cpp9
-rw-r--r--src/inprogress/tafwriter.h22
-rw-r--r--src/inprogress/xmldocument.cpp9
-rw-r--r--src/inprogress/xmldocument.h22
-rw-r--r--src/inprogress/xmlnode.cpp9
-rw-r--r--src/inprogress/xmlnode.h22
-rw-r--r--src/inprogress/xmlreader.cpp267
-rw-r--r--src/inprogress/xmlreader.h121
-rw-r--r--src/inprogress/xmlwriter.cpp9
-rw-r--r--src/inprogress/xmlwriter.h22
16 files changed, 609 insertions, 0 deletions
diff --git a/src/inprogress/tafdocument.cpp b/src/inprogress/tafdocument.cpp
new file mode 100644
index 0000000..bd44dd5
--- /dev/null
+++ b/src/inprogress/tafdocument.cpp
@@ -0,0 +1,9 @@
1#include "tafdocument.h"
2
3Bu::TafDocument::TafDocument()
4{
5}
6
7Bu::TafDocument::~TafDocument()
8{
9}
diff --git a/src/inprogress/tafdocument.h b/src/inprogress/tafdocument.h
new file mode 100644
index 0000000..171f829
--- /dev/null
+++ b/src/inprogress/tafdocument.h
@@ -0,0 +1,22 @@
1#ifndef BU_TAF_DOCUMENT_H
2#define BU_TAF_DOCUMENT_H
3
4#include <stdint.h>
5
6namespace Bu
7{
8 /**
9 *
10 */
11 class TafDocument
12 {
13 public:
14 TafDocument();
15 virtual ~TafDocument();
16
17 private:
18
19 };
20}
21
22#endif
diff --git a/src/inprogress/tafnode.cpp b/src/inprogress/tafnode.cpp
new file mode 100644
index 0000000..c9756ec
--- /dev/null
+++ b/src/inprogress/tafnode.cpp
@@ -0,0 +1,9 @@
1#include "tafnode.h"
2
3Bu::TafNode::TafNode()
4{
5}
6
7Bu::TafNode::~TafNode()
8{
9}
diff --git a/src/inprogress/tafnode.h b/src/inprogress/tafnode.h
new file mode 100644
index 0000000..34f5289
--- /dev/null
+++ b/src/inprogress/tafnode.h
@@ -0,0 +1,21 @@
1#ifndef BU_TAF_NODE_H
2#define BU_TAF_NODE_H
3
4#include <stdint.h>
5
6namespace Bu
7{
8 /**
9 *
10 */
11 class TafNode
12 {
13 public:
14 TafNode();
15 virtual ~TafNode();
16
17 private:
18
19 };
20}
21#endif
diff --git a/src/inprogress/tafreader.cpp b/src/inprogress/tafreader.cpp
new file mode 100644
index 0000000..f94fe44
--- /dev/null
+++ b/src/inprogress/tafreader.cpp
@@ -0,0 +1,11 @@
1#include "tafreader.h"
2
3Bu::TafReader::TafReader( Bu::Stream &sIn ) :
4 sIn( sIn )
5{
6}
7
8Bu::TafReader::~TafReader()
9{
10}
11
diff --git a/src/inprogress/tafreader.h b/src/inprogress/tafreader.h
new file mode 100644
index 0000000..2dbb9ea
--- /dev/null
+++ b/src/inprogress/tafreader.h
@@ -0,0 +1,25 @@
1#ifndef BU_TAF_READER_H
2#define BU_TAF_READER_H
3
4#include <stdint.h>
5#include "bu/tafdocument.h"
6#include "bu/stream.h"
7
8namespace Bu
9{
10 /**
11 *
12 */
13 class TafReader : public Bu::TafDocument
14 {
15 public:
16 TafReader( Bu::Stream &sIn );
17 virtual ~TafReader();
18
19 private:
20 Stream &sIn;
21
22 };
23}
24
25#endif
diff --git a/src/inprogress/tafwriter.cpp b/src/inprogress/tafwriter.cpp
new file mode 100644
index 0000000..3e6c025
--- /dev/null
+++ b/src/inprogress/tafwriter.cpp
@@ -0,0 +1,9 @@
1#include "tafwriter.h"
2
3Bu::TafWriter::TafWriter()
4{
5}
6
7Bu::TafWriter::~TafWriter()
8{
9}
diff --git a/src/inprogress/tafwriter.h b/src/inprogress/tafwriter.h
new file mode 100644
index 0000000..7057d62
--- /dev/null
+++ b/src/inprogress/tafwriter.h
@@ -0,0 +1,22 @@
1#ifndef BU_TAF_WRITER_H
2#define BU_TAF_WRITER_H
3
4#include <stdint.h>
5
6namespace Bu
7{
8 /**
9 *
10 */
11 class TafWriter
12 {
13 public:
14 TafWriter();
15 virtual ~TafWriter();
16
17 private:
18
19 };
20}
21
22#endif
diff --git a/src/inprogress/xmldocument.cpp b/src/inprogress/xmldocument.cpp
new file mode 100644
index 0000000..cb21826
--- /dev/null
+++ b/src/inprogress/xmldocument.cpp
@@ -0,0 +1,9 @@
1#include "xmldocument.h"
2
3Bu::XmlDocument::XmlDocument()
4{
5}
6
7Bu::XmlDocument::~XmlDocument()
8{
9}
diff --git a/src/inprogress/xmldocument.h b/src/inprogress/xmldocument.h
new file mode 100644
index 0000000..e16e3ea
--- /dev/null
+++ b/src/inprogress/xmldocument.h
@@ -0,0 +1,22 @@
1#ifndef XML_DOCUMENT_H
2#define XML_DOCUMENT_H
3
4#include <stdint.h>
5
6namespace Bu
7{
8 /**
9 *
10 */
11 class XmlDocument
12 {
13 public:
14 XmlDocument();
15 virtual ~XmlDocument();
16
17 private:
18
19 };
20}
21
22#endif
diff --git a/src/inprogress/xmlnode.cpp b/src/inprogress/xmlnode.cpp
new file mode 100644
index 0000000..58ef5c5
--- /dev/null
+++ b/src/inprogress/xmlnode.cpp
@@ -0,0 +1,9 @@
1#include "xmlnode.h"
2
3Bu::XmlNode::XmlNode()
4{
5}
6
7Bu::XmlNode::~XmlNode()
8{
9}
diff --git a/src/inprogress/xmlnode.h b/src/inprogress/xmlnode.h
new file mode 100644
index 0000000..cd9961a
--- /dev/null
+++ b/src/inprogress/xmlnode.h
@@ -0,0 +1,22 @@
1#ifndef XML_NODE_H
2#define XML_NODE_H
3
4#include <stdint.h>
5
6namespace Bu
7{
8 /**
9 *
10 */
11 class XmlNode
12 {
13 public:
14 XmlNode();
15 virtual ~XmlNode();
16
17 private:
18
19 };
20}
21
22#endif
diff --git a/src/inprogress/xmlreader.cpp b/src/inprogress/xmlreader.cpp
new file mode 100644
index 0000000..bd241cf
--- /dev/null
+++ b/src/inprogress/xmlreader.cpp
@@ -0,0 +1,267 @@
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::XmlReader::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 S();
61 VersionInfo();
62 EncodingDecl();
63 SDDecl();
64 Sq();
65 checkString("?>", 2 );
66}
67
68void Bu::XmlReader::Misc()
69{
70 for(;;)
71 {
72 S();
73 if( !strncmp("<!--", lookahead( 4 ), 4 ) )
74 {
75 Comment();
76 }
77 else if( !strncmp("<?", lookahead( 2 ), 2 ) )
78 {
79 PI();
80 }
81 else
82 {
83 return;
84 }
85 }
86}
87
88void Bu::XmlReader::Comment()
89{
90 checkString("<!--", 4 );
91 for(;;)
92 {
93 unsigned char c = *lookahead(1);
94 if( c == '-' )
95 {
96 if( lookahead(2)[1] == '-' )
97 {
98 checkString("-->", 3 );
99 return;
100 }
101 }
102 burn( 1 );
103 }
104}
105
106void Bu::XmlReader::PI()
107{
108 checkString("<?", 2 );
109 FString sName = Name();
110 printf("PI: %s\n---\n", sName.getStr() );
111 S();
112 for(int j = 0;; j++ )
113 {
114 if( !strncmp( "?>", lookahead(j+2)+j, 2 ) )
115 {
116 burn( j+2 );
117 return;
118 }
119 }
120}
121
122void Bu::XmlReader::S()
123{
124 for( int j = 0;; j++ )
125 {
126 char c = *lookahead( 1 );
127 if( c == 0x20 || c == 0x9 || c == 0xD || c == 0xA )
128 continue;
129 if( j == 0 )
130 throw ExceptionBase("Expected whitespace.");
131 return;
132 }
133}
134
135void Bu::XmlReader::Sq()
136{
137 for(;;)
138 {
139 char c = *lookahead( 1 );
140 if( c == 0x20 || c == 0x9 || c == 0xD || c == 0xA )
141 continue;
142 return;
143 }
144}
145
146void Bu::XmlReader::VersionInfo()
147{
148 try
149 {
150 S();
151 checkString("version", 7 );
152 }
153 catch( ExceptionBase &e )
154 {
155 return;
156 }
157 Eq();
158 Bu::FString ver = AttValue();
159 if( ver != "1.1" )
160 throw ExceptionBase("Currently we only support xml version 1.1\n");
161}
162
163void Bu::XmlReader::Eq()
164{
165 Sq();
166 checkString("=", 1 );
167 Sq();
168}
169
170void Bu::XmlReader::EncodingDecl()
171{
172 S();
173 try
174 {
175 checkString("encoding", 8 );
176 }
177 catch( ExceptionBase &e )
178 {
179 return;
180 }
181
182 Eq();
183 AttValue();
184}
185
186void Bu::XmlReader::SDDecl()
187{
188 S();
189 try
190 {
191 checkString("standalone", 10 );
192 }
193 catch( ExceptionBase &e )
194 {
195 return;
196 }
197
198 Eq();
199 AttValue();
200}
201
202Bu::FString Bu::XmlReader::AttValue()
203{
204 char q = *lookahead(1);
205 if( q == '\"' )
206 {
207 for( int j = 2;; j++ )
208 {
209 if( lookahead(j)[j-1] == '\"' )
210 {
211 Bu::FString ret( lookahead(j)+1, j-2 );
212 burn( j );
213 return ret;
214 }
215 }
216 }
217 else if( q == '\'' )
218 {
219 for( int j = 2;; j++ )
220 {
221 if( lookahead(j)[j-1] == '\'' )
222 {
223 Bu::FString ret( lookahead(j)+1, j-2 );
224 burn( j );
225 return ret;
226 }
227 }
228 }
229
230 throw ExceptionBase("Excpected either \' or \".\n");
231}
232
233Bu::FString Bu::XmlReader::Name()
234{
235 unsigned char c = *lookahead( 1 );
236 if( c != ':' && c != '_' &&
237 (c < 'A' || c > 'Z') &&
238 (c < 'a' || c > 'z') &&
239 (c < 0xC0 || c > 0xD6 ) &&
240 (c < 0xD8 || c > 0xF6 ) &&
241 (c < 0xF8))
242 {
243 throw ExceptionBase("Invalid entity name starting character.");
244 }
245
246 for( int j = 1;; j++ )
247 {
248 unsigned char c = lookahead(j+1)[j];
249 if( isS( c ) )
250 {
251 FString ret( lookahead(j+1), j+1 );
252 burn( j+1 );
253 return ret;
254 }
255 if( c != ':' && c != '_' && c != '-' && c != '.' && c != 0xB7 &&
256 (c < 'A' || c > 'Z') &&
257 (c < 'a' || c > 'z') &&
258 (c < '0' || c > '9') &&
259 (c < 0xC0 || c > 0xD6 ) &&
260 (c < 0xD8 || c > 0xF6 ) &&
261 (c < 0xF8))
262 {
263 throw ExceptionBase("Invalid character in name.");
264 }
265 }
266}
267
diff --git a/src/inprogress/xmlreader.h b/src/inprogress/xmlreader.h
new file mode 100644
index 0000000..708a386
--- /dev/null
+++ b/src/inprogress/xmlreader.h
@@ -0,0 +1,121 @@
1#ifndef XML_READER_H
2#define XML_READER_H
3
4#include <stdint.h>
5#include "bu/stream.h"
6#include "bu/fstring.h"
7#include "bu/xmlnode.h"
8
9namespace Bu
10{
11 /**
12 * An Xml 1.1 reader. I've decided to write this, this time, based on the
13 * official W3C reccomendation, now included with the source code. I've
14 * named the productions in the parser states the same as in that document,
15 * which may make them easier to find, etc, although possibly slightly less
16 * optimized than writing my own reduced grammer.
17 *
18 * Below I will list differences between my parser and the official standard
19 * as I come up with them.
20 * - Encoding and Standalone headings are ignored for the moment. (4.3.3,
21 * 2.9)
22 * - The standalone heading attribute can have any standard whitespace
23 * before it (the specs say only spaces, no newlines). (2.9)
24 * - Since standalone is ignored, it is currently allowed to have any
25 * value (should be restricted to "yes" or "no"). (2.9)
26 * - Currently only UTF-8 / ascii are parsed.
27 * - [optional] The content of comments is thrown away. (2.5)
28 * - The content of processing instruction blocks is parsed properly, but
29 * thrown away. (2.6)
30 */
31 class XmlReader
32 {
33 public:
34 XmlReader( Bu::Stream &sIn );
35 virtual ~XmlReader();
36
37 XmlNode *read();
38
39 private:
40 Bu::Stream &sIn;
41 Bu::FString sBuf;
42
43 private: // Helpers
44 const char *lookahead( int nAmnt );
45 void burn( int nAmnt );
46 void checkString( const char *str, int nLen );
47
48 private: // States
49 /**
50 * The headers, etc.
51 */
52 void prolog();
53
54 /**
55 * The xml decleration (version, encoding, etc).
56 */
57 void XMLDecl();
58
59 /**
60 * Misc things, Includes Comments and PIData (Processing Instructions).
61 */
62 void Misc();
63
64 /**
65 * Comments
66 */
67 void Comment();
68
69 /**
70 * Processing Instructions
71 */
72 void PI();
73
74 /**
75 * Whitespace eater.
76 */
77 void S();
78
79 /**
80 * Optional whitespace eater.
81 */
82 void Sq();
83
84 /**
85 * XML Version spec
86 */
87 void VersionInfo();
88
89 /**
90 * Your basic equals sign with surrounding whitespace.
91 */
92 void Eq();
93
94 /**
95 * Read in an attribute value.
96 */
97 FString AttValue();
98
99 /**
100 * Read in the name of something.
101 */
102 FString Name();
103
104 /**
105 * Encoding decleration in the header
106 */
107 void EncodingDecl();
108
109 /**
110 * Standalone decleration in the header
111 */
112 void SDDecl();
113
114 bool isS( unsigned char c )
115 {
116 return ( c == 0x20 || c == 0x9 || c == 0xD || c == 0xA );
117 }
118 };
119}
120
121#endif
diff --git a/src/inprogress/xmlwriter.cpp b/src/inprogress/xmlwriter.cpp
new file mode 100644
index 0000000..23a5175
--- /dev/null
+++ b/src/inprogress/xmlwriter.cpp
@@ -0,0 +1,9 @@
1#include "xmlwriter.h"
2
3Bu::XmlWriter::XmlWriter()
4{
5}
6
7Bu::XmlWriter::~XmlWriter()
8{
9}
diff --git a/src/inprogress/xmlwriter.h b/src/inprogress/xmlwriter.h
new file mode 100644
index 0000000..796d6fb
--- /dev/null
+++ b/src/inprogress/xmlwriter.h
@@ -0,0 +1,22 @@
1#ifndef XML_WRITER_H
2#define XML_WRITER_H
3
4#include <stdint.h>
5
6namespace Bu
7{
8 /**
9 *
10 */
11 class XmlWriter
12 {
13 public:
14 XmlWriter();
15 virtual ~XmlWriter();
16
17 private:
18
19 };
20}
21
22#endif