From 0ff3fdfaa52ee4b71632f201d6bfabb0ffbc36d7 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 30 Nov 2007 19:24:40 +0000 Subject: Fixed the overshoot in the Bu::TafReader, it was reading the lookahead character from the stream even when it should have known it was at the end, and then it was reading an extra character after that anyway :-P It is now fixed, and the stream is positioned at the character immediately after the closing } of the root taf group, great for things like the svtools. --- src/minimacro.cpp | 17 +++++++++++++++ src/minimacro.h | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/tafreader.cpp | 16 +++++++++++--- 3 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 src/minimacro.cpp create mode 100644 src/minimacro.h diff --git a/src/minimacro.cpp b/src/minimacro.cpp new file mode 100644 index 0000000..274c13b --- /dev/null +++ b/src/minimacro.cpp @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2007 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/minimacro.h" + +Bu::MiniMacro::MiniMacro() +{ +} + +Bu::MiniMacro::~MiniMacro() +{ +} + diff --git a/src/minimacro.h b/src/minimacro.h new file mode 100644 index 0000000..e136015 --- /dev/null +++ b/src/minimacro.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2007 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#ifndef BU_MINI_MACRO_H +#define BU_MINI_MACRO_H + +namespace Bu +{ + /** + * A processor for Libbu++ brand Mini Macros. These are really simple, but + * still fairly flexible. It's mainly text replacement, but with a few + * extras like filter functions and conditional text segments. So far we + * don't support loops or anything, I'm not sure we ever will. + * + * Anatomy of a mini macro: + * - Every macro begins with a two character code, the first character is + * always '{', the second character determines the operation to perform. + * - If the '{' is followed by a character that is not valid it is not + * considered for expansion and the characters are copied to the output. + * - Every macro ends with a closing '}' + * - Macro types: + * - '=': variable replacement. The '=' is immediatley followed by the + * name of the variable to replace, then any number of optional filter + * segments. + * - '?': conditional text. The '?' is immediately followed by the + * variable to test. This works two ways, the variable can be alone, in + * which case it's existance is tested, or it can be followed by a "=" + * and a string to compare to. This is then followed by a text segment + * that will be used if the test is true, and an optional text segment + * to be used if the test is false. + * - Segments: + * - Each segment is seperated by a colon. + * - Filter segments give the name of the filter, followed by + * parenthesies. Parameters may be provided within the parenthesies. + * - Text segments should always be quoted, but may contain any characters + * within the quotes, backslash is used as per C/ANSI/ISO standard. + * You can also quote any text using [" "] instead of quotes, which + * allows for nested strings. The [" token is only recognised within + * a macro. + * + *@verbatim + {=name:tolower()} + {=name:ccsplit("_"):toupper()} + {?name:"name exists and is {=name}"} + {?name:"{=name}":"no name!"} + {?name="bob":"You're named bob!":"Who are you? I only know bob..."} + @endverbatim + */ + class MiniMacro + { + public: + MiniMacro(); + virtual ~MiniMacro(); + + private: + }; +}; + +#endif diff --git a/src/tafreader.cpp b/src/tafreader.cpp index aaac8d7..7054581 100644 --- a/src/tafreader.cpp +++ b/src/tafreader.cpp @@ -40,7 +40,7 @@ Bu::TafGroup *Bu::TafReader::readGroup() if( c != '}' ) throw TafException("Expected '}'"); - next(); + //next(); return pGroup; } @@ -184,7 +184,17 @@ bool Bu::TafReader::isws() void Bu::TafReader::next() { - c = la; - sIn.read( &la, 1 ); + if( c == '}' ) + { + sIn.read( &c, 1 ); + if( c != '}' ) + sIn.read( &la, 1 ); + } + else + { + c = la; + if( c != '}' ) + sIn.read( &la, 1 ); + } } -- cgit v1.2.3