diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2007-05-09 15:01:03 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2007-05-09 15:01:03 +0000 |
| commit | 2e035fee36768e3c765b7f5dc10bf0a3b7d2448b (patch) | |
| tree | fde606c514a9321cd4bf0d8c075b3b1c22d3a960 /src/xmlreader.cpp | |
| parent | 6e7e30b5fd87766566620d48e785072e0b5c52cd (diff) | |
| download | libbu++-2e035fee36768e3c765b7f5dc10bf0a3b7d2448b.tar.gz libbu++-2e035fee36768e3c765b7f5dc10bf0a3b7d2448b.tar.bz2 libbu++-2e035fee36768e3c765b7f5dc10bf0a3b7d2448b.tar.xz libbu++-2e035fee36768e3c765b7f5dc10bf0a3b7d2448b.zip | |
Minor changes to both the taf and xml readers. I'm thinking I'm going to
archive these for now and resurect/fix the old xml reader, just to have
something working.
Diffstat (limited to 'src/xmlreader.cpp')
| -rw-r--r-- | src/xmlreader.cpp | 175 |
1 files changed, 167 insertions, 8 deletions
diff --git a/src/xmlreader.cpp b/src/xmlreader.cpp index 432ecc1..bd241cf 100644 --- a/src/xmlreader.cpp +++ b/src/xmlreader.cpp | |||
| @@ -29,10 +29,10 @@ void Bu::XmlReader::burn( int nAmnt ) | |||
| 29 | lookahead( nAmnt ); | 29 | lookahead( nAmnt ); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | sBuf.remove( nAmnt ); | 32 | //sBuf.remove( nAmnt ); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | void Bu::XmlNode::checkString( const char *str, int nLen ) | 35 | void Bu::XmlReader::checkString( const char *str, int nLen ) |
| 36 | { | 36 | { |
| 37 | if( !strncmp( str, lookahead( nLen ), nLen ) ) | 37 | if( !strncmp( str, lookahead( nLen ), nLen ) ) |
| 38 | { | 38 | { |
| @@ -57,14 +57,66 @@ void Bu::XmlReader::prolog() | |||
| 57 | void Bu::XmlReader::XMLDecl() | 57 | void Bu::XmlReader::XMLDecl() |
| 58 | { | 58 | { |
| 59 | checkString("<?xml", 5 ); | 59 | checkString("<?xml", 5 ); |
| 60 | S(); | ||
| 60 | VersionInfo(); | 61 | VersionInfo(); |
| 61 | EncodingDecl(); | 62 | EncodingDecl(); |
| 62 | SDDecl(); | 63 | SDDecl(); |
| 63 | S(); | 64 | Sq(); |
| 65 | checkString("?>", 2 ); | ||
| 64 | } | 66 | } |
| 65 | 67 | ||
| 66 | void Bu::XmlReader::Misc() | 68 | void Bu::XmlReader::Misc() |
| 67 | { | 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 | |||
| 88 | void 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 | |||
| 106 | void 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 | } | ||
| 68 | } | 120 | } |
| 69 | 121 | ||
| 70 | void Bu::XmlReader::S() | 122 | void Bu::XmlReader::S() |
| @@ -75,12 +127,12 @@ void Bu::XmlReader::S() | |||
| 75 | if( c == 0x20 || c == 0x9 || c == 0xD || c == 0xA ) | 127 | if( c == 0x20 || c == 0x9 || c == 0xD || c == 0xA ) |
| 76 | continue; | 128 | continue; |
| 77 | if( j == 0 ) | 129 | if( j == 0 ) |
| 78 | printf("Error, expected whitespace!\n"); | 130 | throw ExceptionBase("Expected whitespace."); |
| 79 | return; | 131 | return; |
| 80 | } | 132 | } |
| 81 | } | 133 | } |
| 82 | 134 | ||
| 83 | void Bu::XmlReader::S() | 135 | void Bu::XmlReader::Sq() |
| 84 | { | 136 | { |
| 85 | for(;;) | 137 | for(;;) |
| 86 | { | 138 | { |
| @@ -93,9 +145,19 @@ void Bu::XmlReader::S() | |||
| 93 | 145 | ||
| 94 | void Bu::XmlReader::VersionInfo() | 146 | void Bu::XmlReader::VersionInfo() |
| 95 | { | 147 | { |
| 96 | S(); | 148 | try |
| 97 | checkString("version", 7 ); | 149 | { |
| 98 | 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"); | ||
| 99 | } | 161 | } |
| 100 | 162 | ||
| 101 | void Bu::XmlReader::Eq() | 163 | void Bu::XmlReader::Eq() |
| @@ -105,4 +167,101 @@ void Bu::XmlReader::Eq() | |||
| 105 | Sq(); | 167 | Sq(); |
| 106 | } | 168 | } |
| 107 | 169 | ||
| 170 | void 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 | |||
| 186 | void 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 | |||
| 202 | Bu::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 | |||
| 233 | Bu::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 | } | ||
| 108 | 267 | ||
