From 3144bd7deb950de0cb80e2215c1545bdf8fc81e9 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 6 Jun 2007 18:48:07 +0000 Subject: 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. --- src/tafreader.cpp | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 128 insertions(+), 1 deletion(-) (limited to 'src/tafreader.cpp') 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 @@ -#include "tafreader.h" +#include "bu/tafreader.h" +#include "bu/exceptions.h" +#include "bu/fstring.h" Bu::TafReader::TafReader( Bu::Stream &sIn ) : sIn( sIn ) { + next(); + node(); } Bu::TafReader::~TafReader() { } +void Bu::TafReader::node() +{ + ws(); + if( c != '{' ) + throw Bu::TafException("Expected '{'"); + next(); + ws(); + Bu::FString sName; + for(;;) + { + if( c == ':' ) + break; + else + sName += c; + next(); + } + next(); + printf("Node[%s]:\n", sName.getStr() ); + + nodeContent(); + + if( c != '}' ) + throw TafException("Expected '}'"); + + next(); +} + +void Bu::TafReader::nodeContent() +{ + for(;;) + { + ws(); + if( c == '{' ) + node(); + else if( c == '}' ) + return; + else + nodeProperty(); + } +} + +void Bu::TafReader::nodeProperty() +{ + Bu::FString sName; + for(;;) + { + if( isws() || c == '=' ) + break; + else + sName += c; + next(); + } + ws(); + if( c != '=' ) + { + printf(" %s (true)\n", sName.getStr() ); + return; + } + next(); + ws(); + Bu::FString sValue; + if( c == '"' ) + { + next(); + for(;;) + { + if( c == '\\' ) + { + next(); + if( c == 'x' ) + { + char code[3]={'\0','\0','\0'}; + next(); + code[0] = c; + next(); + code[1] = c; + c = (unsigned char)strtol( code, NULL, 16 ); + } + else if( c == '"' ) + c = '"'; + else + throw TafException("Invalid escape sequence."); + } + else if( c == '"' ) + break; + sValue += c; + next(); + } + next(); + } + else + { + for(;;) + { + if( isws() || c == '}' || c == '{' ) + break; + sValue += c; + next(); + } + } + printf(" %s = %s\n", sName.getStr(), sValue.getStr() ); +} + +FString Bu::TafReader::readStr() +{ +} + +void Bu::TafReader::ws() +{ + for(;;) + { + if( !isws() ) + return; + + next(); + } +} + +bool Bu::TafReader::isws() +{ + return (c == ' ' || c == '\t' || c == '\n' || c == '\r'); +} + void Bu::TafReader::next() { sIn.read( &c, 1 ); -- cgit v1.2.3