| 1196 | } |
| 1197 | |
| 1198 | void Templateiser::processLoop(std::string& code, std::string::const_iterator& inItr, const std::string& str) { |
| 1199 | std::string key, loopSection, emptySection, param; |
| 1200 | |
| 1201 | // read the rest of the key |
| 1202 | std::string::const_iterator itr = readKey(key, inItr, str); |
| 1203 | |
| 1204 | std::vector<std::string> commandParts = tokenize(key, std::string(" "), 0, 0); |
| 1205 | if (commandParts.size() < 2) { |
| 1206 | inItr = itr; |
| 1207 | return; |
| 1208 | } |
| 1209 | |
| 1210 | // check the params |
| 1211 | makelower(commandParts[0]); |
| 1212 | makelower(commandParts[1]); |
| 1213 | |
| 1214 | if (commandParts.size() > 2) { |
| 1215 | param = commandParts[2]; |
| 1216 | } |
| 1217 | |
| 1218 | if (commandParts[0] != "start") { |
| 1219 | inItr = itr; |
| 1220 | return; |
| 1221 | } |
| 1222 | |
| 1223 | std::vector<std::string> checkKeys; |
| 1224 | checkKeys.push_back(format("*end %s", commandParts[1].c_str())); |
| 1225 | |
| 1226 | std::string keyFound; |
| 1227 | itr = findNextTag(checkKeys, keyFound, loopSection, itr, str); |
| 1228 | |
| 1229 | if (itr == str.end()) { |
| 1230 | inItr = itr; |
| 1231 | return; |
| 1232 | } |
| 1233 | |
| 1234 | // do the empty section |
| 1235 | // loops have to have both |
| 1236 | checkKeys.clear(); |
| 1237 | checkKeys.push_back(format("*empty %s", commandParts[1].c_str())); |
| 1238 | itr = findNextTag(checkKeys, keyFound, emptySection, itr, str); |
| 1239 | |
| 1240 | if (callLoop(commandParts[1], param)) { |
| 1241 | std::string newCode; |
| 1242 | processTemplate(newCode, loopSection); |
| 1243 | code += newCode; |
| 1244 | |
| 1245 | while (callLoop(commandParts[1], param)) { |
| 1246 | newCode = ""; |
| 1247 | processTemplate(newCode, loopSection); |
| 1248 | code += newCode; |
| 1249 | } |
| 1250 | } |
| 1251 | else { |
| 1252 | std::string newCode; |
| 1253 | processTemplate(newCode, emptySection); |
| 1254 | code += newCode; |
| 1255 | } |