summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0817b50)
raw | patch | inline | side by side (parent: 0817b50)
author | Sebastian Harl <sh@tokkee.org> | |
Tue, 21 Oct 2014 08:02:07 +0000 (10:02 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Tue, 21 Oct 2014 08:02:07 +0000 (10:02 +0200) |
The idea, previously, was to make NULL values easily identifiable in all
messages but the focus really is on the JSON output which supports a real null
value.
messages but the focus really is on the JSON output which supports a real null
value.
src/core/data.c | patch | blob | history | |
t/unit/core/data_test.c | patch | blob | history |
diff --git a/src/core/data.c b/src/core/data.c
index 1f3aa82a42a641fad531c6b682363c51813af168..2994b5f50d3e18348dd183a553c719322e48002c 100644 (file)
--- a/src/core/data.c
+++ b/src/core/data.c
}
else if (datum->type == SDB_TYPE_STRING) {
if (! datum->data.string)
- return 8; /* "<NULL>" */
+ return 6; /* NULL */
/* in the worst case, each character needs to be escaped */
return 2 * strlen(datum->data.string) + 2;
}
}
else if (datum->type == SDB_TYPE_BINARY) {
if (! datum->data.binary.datum)
- return 8; /* "<NULL>" */
+ return 6; /* NULL */
/* "\xNN" */
return 4 * datum->data.binary.length + 2;
}
else if (datum->type == SDB_TYPE_REGEX) {
if (! datum->data.re.raw)
- return 8; /* "<NULL>" */
+ return 6; /* NULL */
/* "/.../" */
return strlen(datum->data.re.raw) + 4;
}
{
char tmp[sdb_data_strlen(datum) + 1];
char *data = NULL;
+ _Bool is_null = 0;
int ret = -1;
size_t i, pos;
}
else if (datum->type == SDB_TYPE_STRING) {
if (! datum->data.string)
- data = "<NULL>";
+ is_null = 1;
else {
pos = 0;
for (i = 0; i < strlen(datum->data.string); ++i) {
@@ -735,11 +736,11 @@ sdb_data_format(const sdb_data_t *datum, char *buf, size_t buflen, int quoted)
data = tmp;
}
else
- data = "<NULL>";
+ is_null = 1;
}
else if (datum->type == SDB_TYPE_REGEX) {
if (! datum->data.re.raw)
- data = "<NULL>";
+ is_null = 1;
else {
snprintf(tmp, sizeof(tmp), "/%s/", datum->data.re.raw);
data = tmp;
return -1;
}
- if (data) {
+ if (is_null) {
+ /* never quote NULL */
+ strncpy(buf, "NULL", buflen);
+ ret = (int)SDB_MIN(buflen, 4);
+ }
+ else if (data) {
if (quoted == SDB_UNQUOTED)
ret = snprintf(buf, buflen, "%s", data);
else if (quoted == SDB_SINGLE_QUOTED)
index 5c10c59f7693c465b49db2ae5544568f8566634b..e8567b1ad61c1f2cb2c1a3cf0f72874a93cdfcc9 100644 (file)
--- a/t/unit/core/data_test.c
+++ b/t/unit/core/data_test.c
},
{
{ SDB_TYPE_STRING, { .string = NULL } },
- "\"<NULL>\"",
+ "NULL",
},
{
{ SDB_TYPE_STRING, { .string = "this is a test" } },
},
{
{ SDB_TYPE_BINARY, { .binary = { 0, NULL } } },
- "\"<NULL>\"",
+ "NULL",
},
{
{