2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-27 15:18:06 +00:00

Implement JSON parsing and serialization.

This will be used by the upcoming Open vSwitch configuration database.
This commit is contained in:
Ben Pfaff
2009-11-04 14:55:53 -08:00
parent e7f1bf58e4
commit f38b84ea2b
15 changed files with 2337 additions and 0 deletions

View File

@@ -71,6 +71,31 @@ ds_put_char(struct ds *ds, char c)
*ds_put_uninit(ds, 1) = c;
}
/* Appends unicode code point 'uc' to 'ds' in UTF-8 encoding. */
void
ds_put_utf8(struct ds *ds, int uc)
{
if (uc <= 0x7f) {
ds_put_char(ds, uc);
} else if (uc <= 0x7ff) {
ds_put_char(ds, 0xc0 | (uc >> 6));
ds_put_char(ds, 0x80 | (uc & 0x3f));
} else if (uc <= 0xffff) {
ds_put_char(ds, 0xe0 | (uc >> 12));
ds_put_char(ds, 0x80 | ((uc >> 6) & 0x3f));
ds_put_char(ds, 0x80 | (uc & 0x3f));
} else if (uc <= 0x10ffff) {
ds_put_char(ds, 0xf0 | (uc >> 18));
ds_put_char(ds, 0x80 | ((uc >> 12) & 0x3f));
ds_put_char(ds, 0x80 | ((uc >> 6) & 0x3f));
ds_put_char(ds, 0x80 | (uc & 0x3f));
} else {
/* Invalid code point. Insert the Unicode general substitute
* REPLACEMENT CHARACTER. */
ds_put_utf8(ds, 0xfffd);
}
}
void
ds_put_char_multiple(struct ds *ds, char c, size_t n)
{