summaryrefslogtreecommitdiff
path: root/tools/stringhelpers.c
diff options
context:
space:
mode:
authorhorchi <vdr@jwendel.de>2017-03-05 16:39:28 +0100
committerhorchi <vdr@jwendel.de>2017-03-05 16:39:28 +0100
commite2a48d8701f91b8e24fbe9e99e91eb72a87bb749 (patch)
tree726f70554b4ca985a09ef6e30a7fdc8df089993c /tools/stringhelpers.c
downloadvdr-epg-daemon-e2a48d8701f91b8e24fbe9e99e91eb72a87bb749.tar.gz
vdr-epg-daemon-e2a48d8701f91b8e24fbe9e99e91eb72a87bb749.tar.bz2
git init1.1.103
Diffstat (limited to 'tools/stringhelpers.c')
-rw-r--r--tools/stringhelpers.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/tools/stringhelpers.c b/tools/stringhelpers.c
new file mode 100644
index 0000000..d70c493
--- /dev/null
+++ b/tools/stringhelpers.c
@@ -0,0 +1,53 @@
+
+#include "stringhelpers.h"
+
+cJsonLoader::cJsonLoader(const char* name)
+{
+ err = new json_error_t;
+ obj = json_loads(name, 0, err);
+
+}
+
+cJsonLoader::~cJsonLoader()
+{
+ if (obj)
+ json_decref(obj);
+
+ if (err)
+ delete(err);
+}
+
+json_t* cJsonLoader::objectByName(const char* name)
+{
+ return json_object_get(obj, name);
+}
+
+int cJsonLoader::isObject()
+{
+ return obj && json_is_object(obj);
+}
+
+//replace all "search" with "replace" in "subject"
+string str_replace(const string& search, const string& replace, const string& subject) {
+ string str = subject;
+ size_t pos = 0;
+ while((pos = str.find(search, pos)) != string::npos) {
+ str.replace(pos, search.length(), replace);
+ pos += replace.length();
+ }
+ return str;
+}
+//cut string after first "search"
+string str_cut(const string& search, const string& subject) {
+ string str = subject;
+ string strCutted = "";
+ size_t found = str.find_first_of(search);
+ if (found != string::npos) {
+ strCutted = str.substr(0, found);
+ size_t foundSpace = strCutted.find_last_of(" ");
+ if ((foundSpace != string::npos) && (foundSpace == (strCutted.size()-1))) {
+ strCutted = strCutted.substr(0, strCutted.size()-1);
+ }
+ }
+ return strCutted;
+}