aboutsummaryrefslogtreecommitdiff
path: root/src/unstable/minimacro.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
committerMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
commitec05778d5718a7912e506764d443a78d6a6179e3 (patch)
tree78a9a01532180030c095acefc45763f07c14edb8 /src/unstable/minimacro.cpp
parentb20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff)
downloadlibbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip
Converted tabs to spaces with tabconv.
Diffstat (limited to 'src/unstable/minimacro.cpp')
-rw-r--r--src/unstable/minimacro.cpp252
1 files changed, 126 insertions, 126 deletions
diff --git a/src/unstable/minimacro.cpp b/src/unstable/minimacro.cpp
index ff12267..72178ad 100644
--- a/src/unstable/minimacro.cpp
+++ b/src/unstable/minimacro.cpp
@@ -9,16 +9,16 @@
9 9
10Bu::MiniMacro::MiniMacro() 10Bu::MiniMacro::MiniMacro()
11{ 11{
12 hFuncs.insert("toupper", new FuncToUpper() ); 12 hFuncs.insert("toupper", new FuncToUpper() );
13 hFuncs.insert("tolower", new FuncToLower() ); 13 hFuncs.insert("tolower", new FuncToLower() );
14} 14}
15 15
16Bu::MiniMacro::MiniMacro( const StrHash &sVarSrc ) 16Bu::MiniMacro::MiniMacro( const StrHash &sVarSrc )
17{ 17{
18 for( StrHash::const_iterator i = sVarSrc.begin(); i != sVarSrc.end(); i++ ) 18 for( StrHash::const_iterator i = sVarSrc.begin(); i != sVarSrc.end(); i++ )
19 { 19 {
20 addVar( i.getKey(), i.getValue() ); 20 addVar( i.getKey(), i.getValue() );
21 } 21 }
22} 22}
23 23
24Bu::MiniMacro::~MiniMacro() 24Bu::MiniMacro::~MiniMacro()
@@ -27,161 +27,161 @@ Bu::MiniMacro::~MiniMacro()
27 27
28Bu::String Bu::MiniMacro::parse( const Bu::String &sIn ) 28Bu::String Bu::MiniMacro::parse( const Bu::String &sIn )
29{ 29{
30 bContinue = true; 30 bContinue = true;
31 Bu::String sOut; 31 Bu::String sOut;
32 for( sCur = sIn.getStr(); *sCur && bContinue; sCur++ ) 32 for( sCur = sIn.getStr(); *sCur && bContinue; sCur++ )
33 { 33 {
34 if( *sCur == '{' ) 34 if( *sCur == '{' )
35 { 35 {
36 switch( sCur[1] ) 36 switch( sCur[1] )
37 { 37 {
38 case '=': 38 case '=':
39 sCur += 2; 39 sCur += 2;
40 sOut += parseRepl(); 40 sOut += parseRepl();
41 break; 41 break;
42 42
43 case '?': 43 case '?':
44 sCur += 2; 44 sCur += 2;
45 sOut += parseCond(); 45 sOut += parseCond();
46 break; 46 break;
47 47
48 case ':': 48 case ':':
49 sCur += 2; 49 sCur += 2;
50 sOut += parseCmd(); 50 sOut += parseCmd();
51 break; 51 break;
52 52
53 default: 53 default:
54 sOut += *sCur; 54 sOut += *sCur;
55 continue; 55 continue;
56 } 56 }
57 } 57 }
58 else 58 else
59 { 59 {
60 sOut += *sCur; 60 sOut += *sCur;
61 } 61 }
62 } 62 }
63 63
64 iLastPos = (ptrdiff_t)sCur - (ptrdiff_t)sIn.getStr(); 64 iLastPos = (ptrdiff_t)sCur - (ptrdiff_t)sIn.getStr();
65 65
66 return sOut; 66 return sOut;
67} 67}
68 68
69Bu::String Bu::MiniMacro::parseRepl() 69Bu::String Bu::MiniMacro::parseRepl()
70{ 70{
71 Bu::String sOut; 71 Bu::String sOut;
72 bool bIsFirst = true; 72 bool bIsFirst = true;
73 for( const char *sNext = sCur;;) 73 for( const char *sNext = sCur;;)
74 { 74 {
75 for(; *sNext != ':' && *sNext != '}' && *sNext != '\0'; sNext++ ) { } 75 for(; *sNext != ':' && *sNext != '}' && *sNext != '\0'; sNext++ ) { }
76 if( *sNext == '\0' ) 76 if( *sNext == '\0' )
77 break; 77 break;
78 Bu::String sName( sCur, (ptrdiff_t)sNext-(ptrdiff_t)sCur ); 78 Bu::String sName( sCur, (ptrdiff_t)sNext-(ptrdiff_t)sCur );
79 if( bIsFirst ) 79 if( bIsFirst )
80 { 80 {
81 sOut = hVars[sName]; 81 sOut = hVars[sName];
82 bIsFirst = false; 82 bIsFirst = false;
83 //printf("Variable: \"%s\"\n", sName.getStr() ); 83 //printf("Variable: \"%s\"\n", sName.getStr() );
84 } 84 }
85 else 85 else
86 { 86 {
87 sOut = callFunc( sOut, sName ); 87 sOut = callFunc( sOut, sName );
88 //printf("Filter: \"%s\"\n", sName.getStr() ); 88 //printf("Filter: \"%s\"\n", sName.getStr() );
89 } 89 }
90 if( *sNext == '}' ) 90 if( *sNext == '}' )
91 { 91 {
92 sCur = sNext; 92 sCur = sNext;
93 break; 93 break;
94 } 94 }
95 else if( *sNext == ':' ) 95 else if( *sNext == ':' )
96 { 96 {
97 } 97 }
98 sNext++; 98 sNext++;
99 sCur = sNext; 99 sCur = sNext;
100 } 100 }
101 return sOut; 101 return sOut;
102} 102}
103 103
104Bu::String Bu::MiniMacro::parseCond() 104Bu::String Bu::MiniMacro::parseCond()
105{ 105{
106 Bu::String sOut; 106 Bu::String sOut;
107 //printf("%20s\n", sCur ); 107 //printf("%20s\n", sCur );
108 return sOut; 108 return sOut;
109} 109}
110 110
111Bu::String Bu::MiniMacro::parseCmd() 111Bu::String Bu::MiniMacro::parseCmd()
112{ 112{
113 Bu::String sOut; 113 Bu::String sOut;
114 const char *sNext = sCur; 114 const char *sNext = sCur;
115 for(; *sNext != ':' && *sNext != '}' && *sNext != '\0'; sNext++ ) { } 115 for(; *sNext != ':' && *sNext != '}' && *sNext != '\0'; sNext++ ) { }
116 if( *sNext != '\0' ) 116 if( *sNext != '\0' )
117 { 117 {
118 Bu::String sName( sCur, (ptrdiff_t)sNext-(ptrdiff_t)sCur ); 118 Bu::String sName( sCur, (ptrdiff_t)sNext-(ptrdiff_t)sCur );
119 if( sName == "end" ) 119 if( sName == "end" )
120 { 120 {
121 sCur = sNext; 121 sCur = sNext;
122 bContinue = false; 122 bContinue = false;
123 return sOut; 123 return sOut;
124 } 124 }
125 else 125 else
126 { 126 {
127 throw Bu::ExceptionBase("Unknown command '%s'.", 127 throw Bu::ExceptionBase("Unknown command '%s'.",
128 sName.getStr() 128 sName.getStr()
129 ); 129 );
130 } 130 }
131 } 131 }
132 else 132 else
133 { 133 {
134 //printf("Uh...?\n"); 134 //printf("Uh...?\n");
135 } 135 }
136 136
137 //printf("%20s\n", sCur ); 137 //printf("%20s\n", sCur );
138 return sOut; 138 return sOut;
139} 139}
140 140
141Bu::String Bu::MiniMacro::callFunc( 141Bu::String Bu::MiniMacro::callFunc(
142 const Bu::String &sIn, const Bu::String &sFunc ) 142 const Bu::String &sIn, const Bu::String &sFunc )
143{ 143{
144 int i = sFunc.findIdx('('); 144 int i = sFunc.findIdx('(');
145 if( i < 0 ) 145 if( i < 0 )
146 throw Bu::ExceptionBase("That doesn't look like a function call"); 146 throw Bu::ExceptionBase("That doesn't look like a function call");
147 Bu::String sName( sFunc.getStr(), i ); 147 Bu::String sName( sFunc.getStr(), i );
148 StrList lsParams; 148 StrList lsParams;
149 for( const char *s = sFunc.getStr()+i+1; *s && *s != ')'; s++ ) 149 for( const char *s = sFunc.getStr()+i+1; *s && *s != ')'; s++ )
150 { 150 {
151 for(; *s == ' ' || *s == '\t' || *s == '\r' || *s == '\n'; s++ ) { } 151 for(; *s == ' ' || *s == '\t' || *s == '\r' || *s == '\n'; s++ ) { }
152 const char *sNext; 152 const char *sNext;
153 for( sNext = s; *sNext && *sNext != ')' && *sNext != ','; sNext++ ) { } 153 for( sNext = s; *sNext && *sNext != ')' && *sNext != ','; sNext++ ) { }
154 Bu::String p( s, (ptrdiff_t)sNext-(ptrdiff_t)s ); 154 Bu::String p( s, (ptrdiff_t)sNext-(ptrdiff_t)s );
155 lsParams.append( p ); 155 lsParams.append( p );
156 sNext++; 156 sNext++;
157 s = sNext; 157 s = sNext;
158 } 158 }
159 return hFuncs.get( sName )->call( sIn, lsParams ); 159 return hFuncs.get( sName )->call( sIn, lsParams );
160} 160}
161 161
162void Bu::MiniMacro::addVar( 162void Bu::MiniMacro::addVar(
163 const Bu::String &sName, const Bu::String &sValue ) 163 const Bu::String &sName, const Bu::String &sValue )
164{ 164{
165 hVars.insert( sName, sValue ); 165 hVars.insert( sName, sValue );
166} 166}
167 167
168bool Bu::MiniMacro::hasVar( const Bu::String &sName ) 168bool Bu::MiniMacro::hasVar( const Bu::String &sName )
169{ 169{
170 return hVars.has( sName ); 170 return hVars.has( sName );
171} 171}
172 172
173const Bu::String &Bu::MiniMacro::getVar( const Bu::String &sName ) 173const Bu::String &Bu::MiniMacro::getVar( const Bu::String &sName )
174{ 174{
175 return hVars.get( sName ); 175 return hVars.get( sName );
176} 176}
177 177
178const Bu::StrHash &Bu::MiniMacro::getVars() 178const Bu::StrHash &Bu::MiniMacro::getVars()
179{ 179{
180 return hVars; 180 return hVars;
181} 181}
182 182
183int Bu::MiniMacro::getPosition() 183int Bu::MiniMacro::getPosition()
184{ 184{
185 return iLastPos; 185 return iLastPos;
186} 186}
187 187