summaryrefslogtreecommitdiff
path: root/src/tafreader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tafreader.cpp')
-rw-r--r--src/tafreader.cpp129
1 files changed, 128 insertions, 1 deletions
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 );