summaryrefslogtreecommitdiff
path: root/libs/util/src
diff options
context:
space:
mode:
Diffstat (limited to 'libs/util/src')
-rw-r--r--libs/util/src/AbstractListAssembler.cc2
-rw-r--r--libs/util/src/Codec.cc2
-rw-r--r--libs/util/src/JSonWriter.cc39
-rw-r--r--libs/util/src/MD5Calculator.cc2
-rw-r--r--libs/util/src/ManagedMap.cc2
-rw-r--r--libs/util/src/ManagedVector.cc2
-rw-r--r--libs/util/src/NamedValue.cc2
-rw-r--r--libs/util/src/StringBuilder.cc31
-rw-r--r--libs/util/src/util.cc2
9 files changed, 62 insertions, 22 deletions
diff --git a/libs/util/src/AbstractListAssembler.cc b/libs/util/src/AbstractListAssembler.cc
index e83f965..a32826e 100644
--- a/libs/util/src/AbstractListAssembler.cc
+++ b/libs/util/src/AbstractListAssembler.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: AbstractListAssembler.cc
- * Created: 6. Juli 2012, 09:38
+ * Created: 6. Juli 2012, 09
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libutil - base classes used by other libraries
*
diff --git a/libs/util/src/Codec.cc b/libs/util/src/Codec.cc
index bf6acf3..4a1899d 100644
--- a/libs/util/src/Codec.cc
+++ b/libs/util/src/Codec.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: Codec.cc
- * Created: 21. Mai 2012, 14:00
+ * Created: 21. Mai 2012, 14
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libutil - base classes used by other libraries
*
diff --git a/libs/util/src/JSonWriter.cc b/libs/util/src/JSonWriter.cc
index cde994c..ec9b1dc 100644
--- a/libs/util/src/JSonWriter.cc
+++ b/libs/util/src/JSonWriter.cc
@@ -1,31 +1,32 @@
/**
* ======================== legal notice ======================
- *
+ *
* File: JSonWriter.cc
- * Created: 6. Juli 2012, 12:47
+ * Created: 6. Juli 2012, 12
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libutil - base classes used by other libraries
- *
+ *
* CMP - compound media player
- *
+ *
* is a client/server mediaplayer intended to play any media from any workstation
* without the need to export or mount shares. cmps is an easy to use backend
* with a (ready to use) HTML-interface. Additionally the backend supports
* authentication via HTTP-digest authorization.
* cmpc is a client with vdr-like osd-menues.
- *
+ *
* Copyright (c) 2012 Reinhard Mantey, some rights reserved!
* published under Creative Commons by-sa
* For details see http://creativecommons.org/licenses/by-sa/3.0/
- *
+ *
* The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
- *
+ *
* --------------------------------------------------------------
*/
#include <JSonWriter.h>
#include <StringBuilder.h>
#include <Logging.h>
#include <stdio.h>
+#define DEBUG 1
cJSonWriter::cJSonWriter(cStringBuilder &StringBuilder)
: lastState(JS_Unknown)
@@ -57,8 +58,14 @@ cJSonWriter::JSonState cJSonWriter::PopState(void)
}
cJSonWriter &cJSonWriter::Object(void) {
- if (lastState == JS_Object) sb.Append(",");
- sb.Append("{");
+ if (lastState == JS_Object) {
+#ifdef DEBUG
+ sb.Append(",\n");
+#else
+ sb.Append(", ");
+#endif
+ }
+ sb.Append("{ ");
PushState(JS_Object);
lastState = JS_Unknown;
return *this;
@@ -70,7 +77,7 @@ cJSonWriter &cJSonWriter::EndObject(void) {
}
else {
PopState();
- sb.Append("}");
+ sb.Append(" }");
}
return *this;
}
@@ -80,7 +87,7 @@ cJSonWriter &cJSonWriter::Array(void) {
esyslog("JSonWriter::Array(): invalid status %d - should be %d", State(), JS_Key);
}
else {
- sb.Append("[");
+ sb.Append("[ ");
PushState(JS_Array);
lastState = JS_Unknown;
}
@@ -92,7 +99,7 @@ cJSonWriter &cJSonWriter::EndArray(void) {
esyslog("JSonWriter::EndArray(): invalid status %d - should be %d", State(), JS_Array);
}
else {
- sb.Append("]");
+ sb.Append(" ]");
PopState();
if (State() == JS_Key) PopState(); // array is a value, so pop the key
}
@@ -104,7 +111,13 @@ cJSonWriter &cJSonWriter::Key(const char *Name) {
esyslog("JSonWriter::Key(): invalid status %d - should be %d", State(), JS_Object);
}
else {
- if (lastState == JS_Key) sb.Append(", ");
+ if (lastState == JS_Key) {
+#ifdef DEBUG
+ sb.Append(",\n");
+#else
+ sb.Append(", ");
+#endif
+ }
sb.Append("\"").Append(Name).Append("\": ");
PushState(JS_Key);
}
diff --git a/libs/util/src/MD5Calculator.cc b/libs/util/src/MD5Calculator.cc
index 7f2aea4..bc5e243 100644
--- a/libs/util/src/MD5Calculator.cc
+++ b/libs/util/src/MD5Calculator.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: MD5Calculator.cc
- * Created: 3. Juli 2012, 13:15
+ * Created: 3. Juli 2012, 13
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libutil - base classes used by other libraries
*
diff --git a/libs/util/src/ManagedMap.cc b/libs/util/src/ManagedMap.cc
index e0dd528..ad3410d 100644
--- a/libs/util/src/ManagedMap.cc
+++ b/libs/util/src/ManagedMap.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: ManagedMap.cc
- * Created: 7. Juli 2012, 08:48
+ * Created: 7. Juli 2012, 08
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libutil - base classes used by other libraries
*
diff --git a/libs/util/src/ManagedVector.cc b/libs/util/src/ManagedVector.cc
index 7a67bfb..c91f3d0 100644
--- a/libs/util/src/ManagedVector.cc
+++ b/libs/util/src/ManagedVector.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: ManagedVector.cc
- * Created: 7. Juli 2012, 08:30
+ * Created: 7. Juli 2012, 08
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libutil - base classes used by other libraries
*
diff --git a/libs/util/src/NamedValue.cc b/libs/util/src/NamedValue.cc
index f807cb6..56a8abd 100644
--- a/libs/util/src/NamedValue.cc
+++ b/libs/util/src/NamedValue.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: NamedValue.cc
- * Created: 3. Juli 2012, 17:43
+ * Created: 3. Juli 2012, 17
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libutil - base classes used by other libraries
*
diff --git a/libs/util/src/StringBuilder.cc b/libs/util/src/StringBuilder.cc
index 8e90151..28b048e 100644
--- a/libs/util/src/StringBuilder.cc
+++ b/libs/util/src/StringBuilder.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: StringBuilder.cc
- * Created: 6. Juli 2012, 10:54
+ * Created: 6. Juli 2012, 10
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libutil - base classes used by other libraries
*
@@ -37,6 +37,7 @@ cStringBuilder::cStringBuilder(const char *First)
: chunkSize(127)
, readOffset(0)
, writeOffset(0)
+ , firstChunk(NULL)
, pool(freeStringCallback)
{
init();
@@ -47,6 +48,7 @@ cStringBuilder::cStringBuilder(int ChunkSize)
: chunkSize(ChunkSize)
, readOffset(0)
, writeOffset(0)
+ , firstChunk(NULL)
, pool(freeStringCallback)
{
init();
@@ -61,12 +63,13 @@ void cStringBuilder::init(void)
char *first = (char *) malloc(chunkSize);
pool.push_back(first);
+ firstChunk = first;
}
void cStringBuilder::Write(const char *Text)
{
if (!Text) {
- esyslog("ERROR: text to add is a NULL-ponter!");
+ esyslog("ERROR: text to add is a NULL-pointer!");
return;
}
uint chunkFree = chunkSize - writeOffset;
@@ -130,6 +133,18 @@ cStringBuilder &cStringBuilder::Append(const char* Text)
return *this;
}
+cStringBuilder &cStringBuilder::Append(char c)
+{
+ char buf[2];
+
+ *buf = c;
+ buf[1] = 0;
+
+ Write(buf);
+
+ return *this;
+}
+
cStringBuilder &cStringBuilder::Append(bool v, const char *TrueValue, const char *FalseValue)
{
if (v) Write(TrueValue);
@@ -176,3 +191,15 @@ cStringBuilder &cStringBuilder::Append(size_t v)
return *this;
}
+
+char *cStringBuilder::toString(void)
+{
+ char *rv = (char *) malloc(Size() + 1);
+
+ if (rv) {
+ readOffset = 0;
+ Copy(rv, Size() + 1);
+ *(rv + Size()) = 0;
+ }
+ return rv;
+}
diff --git a/libs/util/src/util.cc b/libs/util/src/util.cc
index 8caac91..61027a1 100644
--- a/libs/util/src/util.cc
+++ b/libs/util/src/util.cc
@@ -2,7 +2,7 @@
* ======================== legal notice ======================
*
* File: util.cc
- * Created: 4. Juli 2012, 05:56
+ * Created: 4. Juli 2012, 05
* Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
* Project: libutil - base classes used by other libraries
*