aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-06-06 18:48:07 +0000
committerMike Buland <eichlan@xagasoft.com>2007-06-06 18:48:07 +0000
commit3144bd7deb950de0cb80e2215c1545bdf8fc81e9 (patch)
treeddd78879963a3e80c3ccc4aacc6cdf8c5fda79d4
parentcdca5e17e1ecb9f212353dce55c5df2930e34e9d (diff)
downloadlibbu++-3144bd7deb950de0cb80e2215c1545bdf8fc81e9.tar.gz
libbu++-3144bd7deb950de0cb80e2215c1545bdf8fc81e9.tar.bz2
libbu++-3144bd7deb950de0cb80e2215c1545bdf8fc81e9.tar.xz
libbu++-3144bd7deb950de0cb80e2215c1545bdf8fc81e9.zip
Except for storing the data somewhere, the TafReader is more or less done.
Some more generalizations are in order, then we'll stuff the data somewhere.
-rw-r--r--misc/taf4
-rw-r--r--src/exceptions.cpp1
-rw-r--r--src/exceptions.h1
-rw-r--r--src/tafreader.cpp129
-rw-r--r--src/tafreader.h6
-rw-r--r--src/tests/taf.cpp9
6 files changed, 147 insertions, 3 deletions
diff --git a/misc/taf b/misc/taf
index 5ffcdcf..045b042 100644
--- a/misc/taf
+++ b/misc/taf
@@ -20,7 +20,7 @@
20 {: key="," value="yell"} 20 {: key="," value="yell"}
21 {: key="li" value="lightning"} 21 {: key="li" value="lightning"}
22 } 22 }
23 description = """They appear to be rather average looking, not particularly 23 description = "They appear to be rather average looking, not particularly
24 tall or short, with facial features that are difficult to remember even 24 tall or short, with facial features that are difficult to remember even
25 seconds after witnessing them.""" 25 seconds after witnessing them."
26} 26}
diff --git a/src/exceptions.cpp b/src/exceptions.cpp
index d9f4e70..50b95c3 100644
--- a/src/exceptions.cpp
+++ b/src/exceptions.cpp
@@ -4,6 +4,7 @@
4namespace Bu 4namespace Bu
5{ 5{
6 subExceptionDef( XmlException ) 6 subExceptionDef( XmlException )
7 subExceptionDef( TafException )
7 subExceptionDef( FileException ) 8 subExceptionDef( FileException )
8 subExceptionDef( SocketException ) 9 subExceptionDef( SocketException )
9 subExceptionDef( ConnectionException ) 10 subExceptionDef( ConnectionException )
diff --git a/src/exceptions.h b/src/exceptions.h
index f146b73..d5a9d39 100644
--- a/src/exceptions.h
+++ b/src/exceptions.h
@@ -7,6 +7,7 @@
7namespace Bu 7namespace Bu
8{ 8{
9 subExceptionDecl( XmlException ) 9 subExceptionDecl( XmlException )
10 subExceptionDecl( TafException )
10 subExceptionDecl( FileException ) 11 subExceptionDecl( FileException )
11 subExceptionDecl( SocketException ) 12 subExceptionDecl( SocketException )
12 subExceptionDecl( ConnectionException ) 13 subExceptionDecl( ConnectionException )
diff --git a/src/tafreader.cpp b/src/tafreader.cpp
index 4d10b8d..91aa9f2 100644
--- a/src/tafreader.cpp
+++ b/src/tafreader.cpp
@@ -1,14 +1,141 @@
1#include "tafreader.h" 1#include "bu/tafreader.h"
2#include "bu/exceptions.h"
3#include "bu/fstring.h"
2 4
3Bu::TafReader::TafReader( Bu::Stream &sIn ) : 5Bu::TafReader::TafReader( Bu::Stream &sIn ) :
4 sIn( sIn ) 6 sIn( sIn )
5{ 7{
8 next();
9 node();
6} 10}
7 11
8Bu::TafReader::~TafReader() 12Bu::TafReader::~TafReader()
9{ 13{
10} 14}
11 15
16void Bu::TafReader::node()
17{
18 ws();
19 if( c != '{' )
20 throw Bu::TafException("Expected '{'");
21 next();
22 ws();
23 Bu::FString sName;
24 for(;;)
25 {
26 if( c == ':' )
27 break;
28 else
29 sName += c;
30 next();
31 }
32 next();
33 printf("Node[%s]:\n", sName.getStr() );
34
35 nodeContent();
36
37 if( c != '}' )
38 throw TafException("Expected '}'");
39
40 next();
41}
42
43void Bu::TafReader::nodeContent()
44{
45 for(;;)
46 {
47 ws();
48 if( c == '{' )
49 node();
50 else if( c == '}' )
51 return;
52 else
53 nodeProperty();
54 }
55}
56
57void Bu::TafReader::nodeProperty()
58{
59 Bu::FString sName;
60 for(;;)
61 {
62 if( isws() || c == '=' )
63 break;
64 else
65 sName += c;
66 next();
67 }
68 ws();
69 if( c != '=' )
70 {
71 printf(" %s (true)\n", sName.getStr() );
72 return;
73 }
74 next();
75 ws();
76 Bu::FString sValue;
77 if( c == '"' )
78 {
79 next();
80 for(;;)
81 {
82 if( c == '\\' )
83 {
84 next();
85 if( c == 'x' )
86 {
87 char code[3]={'\0','\0','\0'};
88 next();
89 code[0] = c;
90 next();
91 code[1] = c;
92 c = (unsigned char)strtol( code, NULL, 16 );
93 }
94 else if( c == '"' )
95 c = '"';
96 else
97 throw TafException("Invalid escape sequence.");
98 }
99 else if( c == '"' )
100 break;
101 sValue += c;
102 next();
103 }
104 next();
105 }
106 else
107 {
108 for(;;)
109 {
110 if( isws() || c == '}' || c == '{' )
111 break;
112 sValue += c;
113 next();
114 }
115 }
116 printf(" %s = %s\n", sName.getStr(), sValue.getStr() );
117}
118
119FString Bu::TafReader::readStr()
120{
121}
122
123void Bu::TafReader::ws()
124{
125 for(;;)
126 {
127 if( !isws() )
128 return;
129
130 next();
131 }
132}
133
134bool Bu::TafReader::isws()
135{
136 return (c == ' ' || c == '\t' || c == '\n' || c == '\r');
137}
138
12void Bu::TafReader::next() 139void Bu::TafReader::next()
13{ 140{
14 sIn.read( &c, 1 ); 141 sIn.read( &c, 1 );
diff --git a/src/tafreader.h b/src/tafreader.h
index b552f5d..127b571 100644
--- a/src/tafreader.h
+++ b/src/tafreader.h
@@ -17,7 +17,13 @@ namespace Bu
17 virtual ~TafReader(); 17 virtual ~TafReader();
18 18
19 private: 19 private:
20 void node();
21 void nodeContent();
22 void nodeProperty();
23 void ws();
24 bool isws();
20 void next(); 25 void next();
26 FString readStr();
21 char c; 27 char c;
22 Stream &sIn; 28 Stream &sIn;
23 29
diff --git a/src/tests/taf.cpp b/src/tests/taf.cpp
new file mode 100644
index 0000000..12c653e
--- /dev/null
+++ b/src/tests/taf.cpp
@@ -0,0 +1,9 @@
1#include "bu/tafreader.h"
2#include "bu/file.h"
3
4int main()
5{
6 Bu::File f("test.taf", "rb");
7 Bu::TafReader tr( f );
8}
9