Browse Source

Provide a way to dump json when it is known there is no utf8 in it

master
Con Kolivas 10 years ago
parent
commit
1dfc48698b
  1. 20
      src/jansson-2.6/src/dump.c
  2. 1
      src/jansson-2.6/src/jansson.h

20
src/jansson-2.6/src/dump.c

@ -65,6 +65,21 @@ static int dump_indent(size_t flags, int depth, int space, json_dump_callback_t
return 0;
}
static const char *noutf8_iterate(const char *buffer, int32_t *codepoint)
{
int32_t value;
if(!*buffer)
return buffer;
value = (unsigned char)buffer[0];
if(codepoint)
*codepoint = value;
return buffer + 1;
}
static int dump_string(const char *str, json_dump_callback_t dump, void *data, size_t flags)
{
const char *pos, *end;
@ -82,7 +97,10 @@ static int dump_string(const char *str, json_dump_callback_t dump, void *data, s
while(*end)
{
end = utf8_iterate(pos, &codepoint);
if(flags & JSON_NO_UTF8)
end = noutf8_iterate(pos, &codepoint);
else
end = utf8_iterate(pos, &codepoint);
if(!end)
return -1;

1
src/jansson-2.6/src/jansson.h

@ -260,6 +260,7 @@ json_t *json_load_callback(json_load_callback_t callback, void *data, size_t fla
#define JSON_PRESERVE_ORDER 0x100
#define JSON_ENCODE_ANY 0x200
#define JSON_ESCAPE_SLASH 0x400
#define JSON_NO_UTF8 0x800
typedef int (*json_dump_callback_t)(const char *buffer, size_t size, void *data);

Loading…
Cancel
Save