aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/tests/xml.cpp15
-rw-r--r--src/tsfdocument.cpp9
-rw-r--r--src/tsfdocument.h22
-rw-r--r--src/tsfnode.cpp9
-rw-r--r--src/tsfnode.h21
-rw-r--r--src/tsfreader.cpp9
-rw-r--r--src/tsfreader.h22
-rw-r--r--src/tsfwriter.cpp9
-rw-r--r--src/tsfwriter.h22
-rw-r--r--src/xmldocument.cpp9
-rw-r--r--src/xmldocument.h22
-rw-r--r--src/xmlnode.cpp9
-rw-r--r--src/xmlnode.h22
-rw-r--r--src/xmlreader.cpp108
-rw-r--r--src/xmlreader.h70
-rw-r--r--src/xmlwriter.cpp9
-rw-r--r--src/xmlwriter.h22
17 files changed, 409 insertions, 0 deletions
diff --git a/src/tests/xml.cpp b/src/tests/xml.cpp
new file mode 100644
index 0000000..9ef6a7e
--- /dev/null
+++ b/src/tests/xml.cpp
@@ -0,0 +1,15 @@
1#include "bu/xmlreader.h"
2#include "bu/xmlnode.h"
3#include "bu/xmldocument.h"
4#include "bu/file.h"
5
6int main()
7{
8 Bu::File f("test.xml", "r");
9 Bu::XmlReader xr( f );
10
11 xr.read();
12
13 return 0;
14}
15
diff --git a/src/tsfdocument.cpp b/src/tsfdocument.cpp
new file mode 100644
index 0000000..582f1b1
--- /dev/null
+++ b/src/tsfdocument.cpp
@@ -0,0 +1,9 @@
1#include "tsfdocument.h"
2
3Bu::TsfDocument::TsfDocument()
4{
5}
6
7Bu::TsfDocument::~TsfDocument()
8{
9}
diff --git a/src/tsfdocument.h b/src/tsfdocument.h
new file mode 100644
index 0000000..e324459
--- /dev/null
+++ b/src/tsfdocument.h
@@ -0,0 +1,22 @@
1#ifndef TSF_DOCUMENT_H
2#define TSF_DOCUMENT_H
3
4#include <stdint.h>
5
6namespace Bu
7{
8 /**
9 *
10 */
11 class TsfDocument
12 {
13 public:
14 TsfDocument();
15 virtual ~TsfDocument();
16
17 private:
18
19 };
20}
21
22#endif
diff --git a/src/tsfnode.cpp b/src/tsfnode.cpp
new file mode 100644
index 0000000..19df4ed
--- /dev/null
+++ b/src/tsfnode.cpp
@@ -0,0 +1,9 @@
1#include "tsfnode.h"
2
3Bu::TsfNode::TsfNode()
4{
5}
6
7Bu::TsfNode::~TsfNode()
8{
9}
diff --git a/src/tsfnode.h b/src/tsfnode.h
new file mode 100644
index 0000000..f58b825
--- /dev/null
+++ b/src/tsfnode.h
@@ -0,0 +1,21 @@
1#ifndef TSF_NODE_H
2#define TSF_NODE_H
3
4#include <stdint.h>
5
6namespace Bu
7{
8 /**
9 *
10 */
11 class TsfNode
12 {
13 public:
14 TsfNode();
15 virtual ~TsfNode();
16
17 private:
18
19 };
20}
21#endif
diff --git a/src/tsfreader.cpp b/src/tsfreader.cpp
new file mode 100644
index 0000000..58f4f78
--- /dev/null
+++ b/src/tsfreader.cpp
@@ -0,0 +1,9 @@
1#include "tsfreader.h"
2
3Bu::TsfReader::TsfReader()
4{
5}
6
7Bu::TsfReader::~TsfReader()
8{
9}
diff --git a/src/tsfreader.h b/src/tsfreader.h
new file mode 100644
index 0000000..cc8400a
--- /dev/null
+++ b/src/tsfreader.h
@@ -0,0 +1,22 @@
1#ifndef TSF_READER_H
2#define TSF_READER_H
3
4#include <stdint.h>
5
6namespace Bu
7{
8 /**
9 *
10 */
11 class TsfReader
12 {
13 public:
14 TsfReader();
15 virtual ~TsfReader();
16
17 private:
18
19 };
20}
21
22#endif
diff --git a/src/tsfwriter.cpp b/src/tsfwriter.cpp
new file mode 100644
index 0000000..6592996
--- /dev/null
+++ b/src/tsfwriter.cpp
@@ -0,0 +1,9 @@
1#include "tsfwriter.h"
2
3Bu::TsfWriter::TsfWriter()
4{
5}
6
7Bu::TsfWriter::~TsfWriter()
8{
9}
diff --git a/src/tsfwriter.h b/src/tsfwriter.h
new file mode 100644
index 0000000..18f19d6
--- /dev/null
+++ b/src/tsfwriter.h
@@ -0,0 +1,22 @@
1#ifndef TSF_WRITER_H
2#define TSF_WRITER_H
3
4#include <stdint.h>
5
6namespace Bu
7{
8 /**
9 *
10 */
11 class TsfWriter
12 {
13 public:
14 TsfWriter();
15 virtual ~TsfWriter();
16
17 private:
18
19 };
20}
21
22#endif
diff --git a/src/xmldocument.cpp b/src/xmldocument.cpp
new file mode 100644
index 0000000..cb21826
--- /dev/null
+++ b/src/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/xmldocument.h b/src/xmldocument.h
new file mode 100644
index 0000000..e16e3ea
--- /dev/null
+++ b/src/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/xmlnode.cpp b/src/xmlnode.cpp
new file mode 100644
index 0000000..58ef5c5
--- /dev/null
+++ b/src/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/xmlnode.h b/src/xmlnode.h
new file mode 100644
index 0000000..cd9961a
--- /dev/null
+++ b/src/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/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
diff --git a/src/xmlreader.h b/src/xmlreader.h
new file mode 100644
index 0000000..19791c4
--- /dev/null
+++ b/src/xmlreader.h
@@ -0,0 +1,70 @@
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 *
13 */
14 class XmlReader
15 {
16 public:
17 XmlReader( Bu::Stream &sIn );
18 virtual ~XmlReader();
19
20 XmlNode *read();
21
22 private:
23 Bu::Stream &sIn;
24 Bu::FString sBuf;
25
26 private: // Helpers
27 const char *lookahead( int nAmnt );
28 void burn( int nAmnt );
29 void checkString( const char *str, int nLen );
30
31 private: // States
32 /**
33 * The headers, etc.
34 */
35 void prolog();
36
37 /**
38 * The xml decleration (version, encoding, etc).
39 */
40 void XMLDecl();
41
42 /**
43 * Misc things...?
44 */
45 void Misc();
46
47 /**
48 * Whitespace eater.
49 */
50 void S();
51
52 /**
53 * Optional whitespace eater.
54 */
55 void Sq();
56
57 /**
58 * XML Version spec
59 */
60 void VersionInfo();
61
62 /**
63 * Your basic equals sign with surrounding whitespace.
64 */
65 void Eq();
66
67 };
68}
69
70#endif
diff --git a/src/xmlwriter.cpp b/src/xmlwriter.cpp
new file mode 100644
index 0000000..23a5175
--- /dev/null
+++ b/src/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/xmlwriter.h b/src/xmlwriter.h
new file mode 100644
index 0000000..796d6fb
--- /dev/null
+++ b/src/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