aboutsummaryrefslogtreecommitdiff
path: root/src/minimacro.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/minimacro.h')
-rw-r--r--src/minimacro.h68
1 files changed, 66 insertions, 2 deletions
diff --git a/src/minimacro.h b/src/minimacro.h
index e136015..105a117 100644
--- a/src/minimacro.h
+++ b/src/minimacro.h
@@ -8,6 +8,9 @@
8#ifndef BU_MINI_MACRO_H 8#ifndef BU_MINI_MACRO_H
9#define BU_MINI_MACRO_H 9#define BU_MINI_MACRO_H
10 10
11#include "bu/hash.h"
12#include "bu/fstring.h"
13
11namespace Bu 14namespace Bu
12{ 15{
13 /** 16 /**
@@ -32,14 +35,20 @@ namespace Bu
32 * and a string to compare to. This is then followed by a text segment 35 * and a string to compare to. This is then followed by a text segment
33 * that will be used if the test is true, and an optional text segment 36 * that will be used if the test is true, and an optional text segment
34 * to be used if the test is false. 37 * to be used if the test is false.
38 * - ':': command. The ':' is immediately followed by a command string,
39 * of which there's only one right now, but that's ok. These are not
40 * put into the output stream, but instead mark something for the
41 * parser. Currently supported:
42 * - {:end}: end of parsing, stop here, also make note of how many input
43 * characters were used.
35 * - Segments: 44 * - Segments:
36 * - Each segment is seperated by a colon. 45 * - Each segment is seperated by a colon.
37 * - Filter segments give the name of the filter, followed by 46 * - Filter segments give the name of the filter, followed by
38 * parenthesies. Parameters may be provided within the parenthesies. 47 * parenthesies. Parameters may be provided within the parenthesies.
39 * - Text segments should always be quoted, but may contain any characters 48 * - Text segments should always be quoted, but may contain any characters
40 * within the quotes, backslash is used as per C/ANSI/ISO standard. 49 * within the quotes, backslash is used as per C/ANSI/ISO standard.
41 * You can also quote any text using [" "] instead of quotes, which 50 * You can also quote any text using [' '] instead of quotes, which
42 * allows for nested strings. The [" token is only recognised within 51 * allows for nested strings. The [' token is only recognised within
43 * a macro. 52 * a macro.
44 * 53 *
45 *@verbatim 54 *@verbatim
@@ -50,13 +59,68 @@ namespace Bu
50 {?name="bob":"You're named bob!":"Who are you? I only know bob..."} 59 {?name="bob":"You're named bob!":"Who are you? I only know bob..."}
51 @endverbatim 60 @endverbatim
52 */ 61 */
62 typedef Bu::Hash<Bu::FString, Bu::FString> StrHash;
53 class MiniMacro 63 class MiniMacro
54 { 64 {
55 public: 65 public:
56 MiniMacro(); 66 MiniMacro();
57 virtual ~MiniMacro(); 67 virtual ~MiniMacro();
58 68
69 Bu::FString parse( const Bu::FString &sIn );
70 void addVar( const Bu::FString &sName, const Bu::FString &sValue );
71
72 private:
73 const char *sCur;
74 Bu::FString parseRepl();
75 Bu::FString parseCond();
76 Bu::FString parseCmd();
77 Bu::FString callFunc(
78 const Bu::FString &sIn, const Bu::FString &sFunc );
79
80 StrHash hVars;
81
82 public:
83 typedef Bu::List<Bu::FString> StrList;
84 class Func
85 {
86 public:
87 Func(){}
88 virtual ~Func(){}
89 virtual Bu::FString call(
90 const Bu::FString &sIn, StrList &lsParam )=0;
91 };
92
93 class FuncToUpper : public Func
94 {
95 public:
96 FuncToUpper(){}
97 virtual ~FuncToUpper(){}
98 virtual Bu::FString call(
99 const Bu::FString &sIn, StrList &lsParam )
100 {
101 Bu::FString sOut( sIn );
102 sOut.toUpper();
103 return sOut;
104 }
105 };
106
107 class FuncToLower : public Func
108 {
109 public:
110 FuncToLower(){}
111 virtual ~FuncToLower(){}
112 virtual Bu::FString call(
113 const Bu::FString &sIn, StrList &lsParam )
114 {
115 Bu::FString sOut( sIn );
116 sOut.toLower();
117 return sOut;
118 }
119 };
120
59 private: 121 private:
122 typedef Bu::Hash<Bu::FString,class Func *> FuncHash;
123 FuncHash hFuncs;
60 }; 124 };
61}; 125};
62 126