summaryrefslogtreecommitdiff
path: root/libs/util/src
diff options
context:
space:
mode:
authorgeronimo <geronimo013@gmx.de>2012-08-04 09:10:44 (GMT)
committergeronimo <geronimo013@gmx.de>2012-08-04 09:10:44 (GMT)
commite8175c7b23047fefd52f85afe05e2864b2a9bba8 (patch)
tree8dab4e287545805d173a6c8e297c1798a1a01599 /libs/util/src
parentc7d67f443bdfe842c2e356d4edbe345338e3e08d (diff)
downloadcmp-e8175c7b23047fefd52f85afe05e2864b2a9bba8.tar.gz
cmp-e8175c7b23047fefd52f85afe05e2864b2a9bba8.tar.bz2
created new icons to enable visual feedback on mediatype selection, changed json-parser and enabled virtual mediatype usage
Diffstat (limited to 'libs/util/src')
-rw-r--r--libs/util/src/JSonWriter.cc5
-rw-r--r--libs/util/src/StringBuilder.cc50
2 files changed, 52 insertions, 3 deletions
diff --git a/libs/util/src/JSonWriter.cc b/libs/util/src/JSonWriter.cc
index ec9b1dc..8fcb140 100644
--- a/libs/util/src/JSonWriter.cc
+++ b/libs/util/src/JSonWriter.cc
@@ -28,6 +28,9 @@
#include <stdio.h>
#define DEBUG 1
+static const char char2Replace[] = { '"', '\0' };
+static const char *replacements[] = { "\\\"", NULL };
+
cJSonWriter::cJSonWriter(cStringBuilder &StringBuilder)
: lastState(JS_Unknown)
, sb(StringBuilder)
@@ -130,7 +133,7 @@ cJSonWriter &cJSonWriter::Value(const char *Text) {
}
else {
PopState();
- sb.Append("\"").Append(Text).Append("\"");
+ sb.Append("\"").Append(Text, char2Replace, replacements).Append("\"");
}
return *this;
}
diff --git a/libs/util/src/StringBuilder.cc b/libs/util/src/StringBuilder.cc
index 28b048e..7da1aac 100644
--- a/libs/util/src/StringBuilder.cc
+++ b/libs/util/src/StringBuilder.cc
@@ -91,6 +91,51 @@ void cStringBuilder::Write(const char *Text)
}
}
+void cStringBuilder::WriteAndReplace(const char *Text, const char char2Replace[], const char *replacements[])
+{
+ if (!Text) {
+ esyslog("ERROR: text to add is a NULL-pointer!");
+ return;
+ }
+ int done;
+ char *curChunk = (char *) pool[pool.size() - 1];
+ char *chunkLast = curChunk + chunkSize;
+ char *pd;
+ const char *ps, *srcLast = Text + strlen(Text), *pChk;
+
+ for (ps = Text, pd = curChunk + writeOffset; ps < srcLast; ++ps) {
+ done = 0;
+ for (pChk = char2Replace; pChk && *pChk; ++pChk) {
+ if (*ps == *pChk) {
+ const char *rps = replacements[pChk - char2Replace];
+ done = 1;
+
+ while (rps && *rps) {
+ if (writeOffset == chunkSize) {
+ curChunk = (char *) malloc(chunkSize);
+ pool.push_back(curChunk);
+ writeOffset = 0;
+ pd = curChunk;
+ chunkLast = curChunk + chunkSize;
+ }
+ *pd++ = *rps++;
+ ++writeOffset;
+ }
+ }
+ }
+ if (done) continue;
+ if (writeOffset == chunkSize) {
+ curChunk = (char *) malloc(chunkSize);
+ pool.push_back(curChunk);
+ writeOffset = 0;
+ pd = curChunk;
+ chunkLast = curChunk + chunkSize;
+ }
+ *pd++ = *ps;
+ ++writeOffset;
+ }
+}
+
size_t cStringBuilder::Size()
{
return (pool.size() - 1) * chunkSize + writeOffset;
@@ -125,10 +170,11 @@ size_t cStringBuilder::Copy(char* Buf, size_t BufSize)
return bytesWritten;
}
-cStringBuilder &cStringBuilder::Append(const char* Text)
+cStringBuilder &cStringBuilder::Append(const char* Text, const char char2Replace[], const char *replacements[])
{
if (!Text) Write("(null)");
- Write(Text);
+ if (char2Replace && replacements) WriteAndReplace(Text, char2Replace, replacements);
+ else Write(Text);
return *this;
}