summaryrefslogtreecommitdiffstats
path: root/src/uscxml/Factory.cpp
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-07-22 12:38:43 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-07-22 12:38:43 (GMT)
commitf2d8c967076e5d8ebd3ca718e14edef8acb5f87c (patch)
tree0bed80b7ff8081a6108e7c847a4489de272679c8 /src/uscxml/Factory.cpp
parent7bd0256239f247ed01ee6c673e31283c794bb3d0 (diff)
downloaduscxml-f2d8c967076e5d8ebd3ca718e14edef8acb5f87c.zip
uscxml-f2d8c967076e5d8ebd3ca718e14edef8acb5f87c.tar.gz
uscxml-f2d8c967076e5d8ebd3ca718e14edef8acb5f87c.tar.bz2
Removed iOS project again
Diffstat (limited to 'src/uscxml/Factory.cpp')
-rw-r--r--src/uscxml/Factory.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/uscxml/Factory.cpp b/src/uscxml/Factory.cpp
index b3ad09e..7ac3b98 100644
--- a/src/uscxml/Factory.cpp
+++ b/src/uscxml/Factory.cpp
@@ -392,6 +392,62 @@ boost::shared_ptr<ExecutableContentImpl> Factory::createExecutableContent(const
}
+size_t DataModelImpl::replaceExpressions(std::string& content) {
+ std::stringstream ss;
+ size_t replacements = 0;
+ size_t indent = 0;
+ size_t pos = 0;
+ size_t start = std::string::npos;
+ size_t end = 0;
+ while (true) {
+ // find any of ${}
+ pos = content.find_first_of("${}", pos);
+ if (pos == std::string::npos) {
+ ss << content.substr(end, content.length() - end);
+ break;
+ }
+ if (content[pos] == '$') {
+ if (content.size() > pos && content[pos+1] == '{') {
+ pos++;
+ start = pos + 1;
+ // copy everything in between
+ ss << content.substr(end, (start - 2) - end);
+ }
+ } else if (content[pos] == '{' && start != std::string::npos) {
+ indent++;
+ } else if (content[pos] == '}' && start != std::string::npos) {
+ if (!indent) {
+ end = pos;
+ // we found a token to substitute
+ std::string expr = content.substr(start, end - start);
+ end++;
+ try {
+ Data data = getStringAsData(expr);
+// if (data.type == Data::VERBATIM) {
+// ss << "\"" << data.atom << "\"";
+// } else {
+// ss << data.atom;
+// }
+ ss << Data::toJSON(data);
+ replacements++;
+ } catch (Event e) {
+ // insert unsubstituted
+ start -= 2;
+ ss << content.substr(start, end - start);
+ }
+ start = std::string::npos;
+ } else {
+ indent--;
+ }
+ }
+ pos++;
+ }
+ if (replacements)
+ content = ss.str();
+
+ return replacements;
+}
+
Factory* Factory::getInstance() {
if (_instance == NULL) {