-
Notifications
You must be signed in to change notification settings - Fork 2
Usage
This page shows how you can use cjson and its internal libraries in your project.
The instance instantiated through this structure allows you to stream data of any type to itself. This functionality is useful for parsing data which JSON
parsing requires a lot.
-
Using
StringStream
to allocate empty string.#include <stdio.h> #include <cjson/data/sstream/sstream.h> int main(void) { // Returns a (null) terminated string that is allocated dynamically. StringStream sstream = StringStreamAlloc(); // Print a (null) terminated string. PrintSstream(sstream, FALSE); return 0; }
-
Using
StringStream
to allocateconst char*
.#include <stdio.h> #include <cjson/data/sstream/sstream.h> int main(void) { StringStream sstream = StringStreamStrAlloc("foo"); // Print "foo". PrintSstream(sstream, FALSE); return 0; }
-
Using
StringStream
to allocate exactlyN
bytes of aconst char*
.#include <stdio.h> #include <cjson/data/sstream/sstream.h> int main(void) { StringStream sstream = StringStreamStrNAlloc("foobar", 3); // Print "foo". PrintSstream(sstream, FALSE); return 0; }
-
Concatenating string on the existing
StringStream
instance usingStringStreamConcat
.#include <stdio.h> #include <cjson/data/sstream/sstream.h> int main(void) { StringStream sstream = StringStreamStrAlloc("foo"); // Concatenating "bar", "fuzz", 101. StringStreamConcat(&sstream, " %s %s %d", "bar", "fuzz", 101); // Prints "foo bar fuzz 101". PrintSstream(sstream, FALSE); return 0; }
const char* StringStreamBegin(const StringStream* const sstream)
Returns a
const char*
to the beginning of thedata
instance of theStringStream
instance.
const char* StringStreamEnd(const StringStream *sstream)
Returns a iterator to the end of the
data
instance of theStringStream
instance.
_GET_STRING_STREAM_AVAILABLE_SPACE(sstream)
Calculates the number of memory blocks available in the data instance of the
StringStream
instance. The terminating\0
byte is not counted in available blocks.