aboutsummaryrefslogtreecommitdiff
path: root/src/experimental/xmlreader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/experimental/xmlreader.cpp')
-rw-r--r--src/experimental/xmlreader.cpp250
1 files changed, 125 insertions, 125 deletions
diff --git a/src/experimental/xmlreader.cpp b/src/experimental/xmlreader.cpp
index f11ac04..82f4684 100644
--- a/src/experimental/xmlreader.cpp
+++ b/src/experimental/xmlreader.cpp
@@ -11,13 +11,13 @@
11namespace Bu { subExceptionDef( XmlException ) } 11namespace Bu { subExceptionDef( XmlException ) }
12 12
13Bu::XmlReader::XmlReader( Stream &rInput ) : 13Bu::XmlReader::XmlReader( Stream &rInput ) :
14 rInput( rInput ), 14 rInput( rInput ),
15 iCurToken( 0 ), 15 iCurToken( 0 ),
16 iNextToken( 0 ), 16 iNextToken( 0 ),
17 bIgnoreWS( true ) 17 bIgnoreWS( true )
18{ 18{
19 nextToken(); 19 nextToken();
20 stDocument(); 20 stDocument();
21} 21}
22 22
23Bu::XmlReader::~XmlReader() 23Bu::XmlReader::~XmlReader()
@@ -26,148 +26,148 @@ Bu::XmlReader::~XmlReader()
26 26
27void Bu::XmlReader::fillBuffer() 27void Bu::XmlReader::fillBuffer()
28{ 28{
29 if( rInput.isEos() ) 29 if( rInput.isEos() )
30 return; 30 return;
31 char buf[1024]; 31 char buf[1024];
32 int iSize = rInput.read( buf, 1024 ); 32 int iSize = rInput.read( buf, 1024 );
33 sBuf.append( buf, iSize ); 33 sBuf.append( buf, iSize );
34} 34}
35 35
36void Bu::XmlReader::cleanupBuffer( int iUsed ) 36void Bu::XmlReader::cleanupBuffer( int iUsed )
37{ 37{
38 for( int j = 0; j < iUsed; j++ ) 38 for( int j = 0; j < iUsed; j++ )
39 { 39 {
40 if( sBuf[j] == '\n' ) 40 if( sBuf[j] == '\n' )
41 { 41 {
42 spNextToken.iLine++; 42 spNextToken.iLine++;
43 spNextToken.iChar = 1; 43 spNextToken.iChar = 1;
44 } 44 }
45 else 45 else
46 { 46 {
47 spNextToken.iChar++; 47 spNextToken.iChar++;
48 } 48 }
49 } 49 }
50 50
51 printf("--Deleting %d bytes from front of buffer.\n", iUsed ); 51 printf("--Deleting %d bytes from front of buffer.\n", iUsed );
52 sBuf.trimFront( iUsed ); 52 sBuf.trimFront( iUsed );
53} 53}
54 54
55int Bu::XmlReader::nextToken() 55int Bu::XmlReader::nextToken()
56{ 56{
57 fillBuffer(); 57 fillBuffer();
58 58
59 int iUsed = 1; 59 int iUsed = 1;
60 60
61 iCurToken = iNextToken; 61 iCurToken = iNextToken;
62 spCurToken = spNextToken; 62 spCurToken = spNextToken;
63 63
64 switch( sBuf[0] ) 64 switch( sBuf[0] )
65 { 65 {
66 case '<': 66 case '<':
67 if( !strncmp( sBuf.getStr(), "<?xml", 5 ) ) 67 if( !strncmp( sBuf.getStr(), "<?xml", 5 ) )
68 { 68 {
69 iNextToken = tokXmlDeclHead; 69 iNextToken = tokXmlDeclHead;
70 iUsed = 5; 70 iUsed = 5;
71 } 71 }
72 else 72 else
73 { 73 {
74 iNextToken = '<'; 74 iNextToken = '<';
75 } 75 }
76 break; 76 break;
77 77
78 case '?': 78 case '?':
79 if( sBuf[1] == '>' ) 79 if( sBuf[1] == '>' )
80 { 80 {
81 iNextToken = tokXmlDeclEnd; 81 iNextToken = tokXmlDeclEnd;
82 iUsed = 2; 82 iUsed = 2;
83 } 83 }
84 else 84 else
85 { 85 {
86 iNextToken = '?'; 86 iNextToken = '?';
87 } 87 }
88 break; 88 break;
89 89
90 case ' ': 90 case ' ':
91 case '\t': 91 case '\t':
92 case '\n': 92 case '\n':
93 case '\r': 93 case '\r':
94 for( int j = 1;; j++ ) 94 for( int j = 1;; j++ )
95 { 95 {
96 if( j == sBuf.getSize() ) 96 if( j == sBuf.getSize() )
97 { 97 {
98 if( rInput.isEos() ) 98 if( rInput.isEos() )
99 error("Reached end of input while waiting for whitespace to end."); 99 error("Reached end of input while waiting for whitespace to end.");
100 100
101 fillBuffer(); 101 fillBuffer();
102 } 102 }
103 if( sBuf[j] == ' ' || sBuf[j] == '\t' || 103 if( sBuf[j] == ' ' || sBuf[j] == '\t' ||
104 sBuf[j] == '\n' || sBuf[j] == '\r' ) 104 sBuf[j] == '\n' || sBuf[j] == '\r' )
105 iUsed++; 105 iUsed++;
106 else 106 else
107 break; 107 break;
108 } 108 }
109 sStr.clear(); 109 sStr.clear();
110 sStr.append( sBuf, iUsed ); 110 sStr.append( sBuf, iUsed );
111 iNextToken = tokWS; 111 iNextToken = tokWS;
112 break; 112 break;
113 113
114 case '=': 114 case '=':
115 iNextToken = sBuf[0]; 115 iNextToken = sBuf[0];
116 break; 116 break;
117 117
118 default: 118 default:
119 if( (sBuf[0] >= 'a' && sBuf[0] <= 'z') || 119 if( (sBuf[0] >= 'a' && sBuf[0] <= 'z') ||
120 (sBuf[0] >= 'A' && sBuf[0] <= 'Z') ) 120 (sBuf[0] >= 'A' && sBuf[0] <= 'Z') )
121 { 121 {
122 for( int j = 1;; j++ ) 122 for( int j = 1;; j++ )
123 { 123 {
124 if( j == sBuf.getSize() ) 124 if( j == sBuf.getSize() )
125 { 125 {
126 if( rInput.isEos() ) 126 if( rInput.isEos() )
127 error("Reached end of input while waiting for a string to end."); 127 error("Reached end of input while waiting for a string to end.");
128 128
129 fillBuffer(); 129 fillBuffer();
130 } 130 }
131 if( (sBuf[j] >= 'a' && sBuf[j] <= 'z') || 131 if( (sBuf[j] >= 'a' && sBuf[j] <= 'z') ||
132 (sBuf[j] >= 'A' && sBuf[j] <= 'Z') ) 132 (sBuf[j] >= 'A' && sBuf[j] <= 'Z') )
133 iUsed++; 133 iUsed++;
134 else 134 else
135 break; 135 break;
136 } 136 }
137 sStr.clear(); 137 sStr.clear();
138 sStr.append( sBuf, iUsed ); 138 sStr.append( sBuf, iUsed );
139 iNextToken = tokIdent; 139 iNextToken = tokIdent;
140 } 140 }
141 } 141 }
142 142
143 cleanupBuffer( iUsed ); 143 cleanupBuffer( iUsed );
144 144
145 return iCurToken; 145 return iCurToken;
146} 146}
147 147
148void Bu::XmlReader::error( const char *sMessage ) 148void Bu::XmlReader::error( const char *sMessage )
149{ 149{
150 throw Bu::XmlException("%d:%d: %s", 150 throw Bu::XmlException("%d:%d: %s",
151 spCurToken.iLine, spCurToken.iChar, sMessage ); 151 spCurToken.iLine, spCurToken.iChar, sMessage );
152} 152}
153 153
154void Bu::XmlReader::stDocument() 154void Bu::XmlReader::stDocument()
155{ 155{
156 stProlog(); 156 stProlog();
157} 157}
158 158
159void Bu::XmlReader::stProlog() 159void Bu::XmlReader::stProlog()
160{ 160{
161 stXmlDecl(); 161 stXmlDecl();
162} 162}
163 163
164void Bu::XmlReader::stXmlDecl() 164void Bu::XmlReader::stXmlDecl()
165{ 165{
166 if( nextToken() != tokXmlDeclHead ) 166 if( nextToken() != tokXmlDeclHead )
167 error("You must begin your xml file with a declaration: <?xml ... ?>"); 167 error("You must begin your xml file with a declaration: <?xml ... ?>");
168 if( nextToken() != tokIdent ) 168 if( nextToken() != tokIdent )
169 error("A version comes first!"); 169 error("A version comes first!");
170 if( sStr != "version" ) 170 if( sStr != "version" )
171 error("No, a version!"); 171 error("No, a version!");
172} 172}
173 173