aboutsummaryrefslogtreecommitdiff
path: root/MemDriverWeb/minitmpl.h
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2019-07-04 00:03:51 +0200
committerToni Uhlig <matzeton@googlemail.com>2019-07-04 00:03:51 +0200
commit1890024e57f623ceec744bb3a6922d89d2d47640 (patch)
tree736b4cd28fb14fce546acbc93b2499f3c34586e3 /MemDriverWeb/minitmpl.h
parentcaf93747fb255f7e5750618216c560440d3fa42f (diff)
very basic templating engine
Diffstat (limited to 'MemDriverWeb/minitmpl.h')
-rw-r--r--MemDriverWeb/minitmpl.h17
1 files changed, 9 insertions, 8 deletions
diff --git a/MemDriverWeb/minitmpl.h b/MemDriverWeb/minitmpl.h
index 446930a..426579c 100644
--- a/MemDriverWeb/minitmpl.h
+++ b/MemDriverWeb/minitmpl.h
@@ -1,17 +1,18 @@
#pragma once
+#include <map>
#include <sstream>
+typedef std::function<std::string&(std::string&)> template_cb;
+
class TemplateString : public std::stringstream
{
public:
- std::string& doTemplateStr(const std::string& search, const std::string& replace) {
- size_t pos = 0;
- std::string s = this->str();
- while ((pos = s.find(search, pos)) != std::string::npos) {
- s.replace(pos, search.length(), replace);
- pos += replace.length();
- }
- return s;
+ static void registerTemplateCallback(const char *variable, template_cb cb) {
+ TemplateString::template_callbacks[std::string(variable)] = cb;
}
+ std::string doTemplateStr();
+private:
+ std::string in_cache, out_cache;
+ static std::map<std::string, template_cb> template_callbacks;
}; \ No newline at end of file