Hash :
ca82f1ca
Author :
Thomas de Grivel
Date :
2024-08-14T13:40:51
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
/* kc3
* Copyright 2022,2023,2024 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software granted the above
* copyright notice and this permission paragraph are included in all
* copies and substantial portions of this software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
#include <libkc3/kc3.h>
#include "json.h"
/*s_tag * json_buf_parse_null (const s_buf *buf, s_tag *dest) {
character c;
sw r;
s_buf_save save;
assert(buf);
assert(dest);
buf_save_init(buf, &save);
if ((r = buf_read_1(buf, "void")) <= 0)
goto clean;
if (buf_peek_character_utf8(buf, &c) > 0 &&
! ident_character_is_reserved(c)) {
r = 0;
goto restore;
}
goto clean;
restore:
buf_save_restore_rpos(buf, &save);
clean:
buf_save_clean(buf, &save);
return r;
}*/
s_tag * json_buf_parse_numbers (s_buf *buf, s_tag *dest)
{
s_buf_save save;
assert(buf);
assert(dest);
buf_save_init(buf, &save);
if (! buf_parse_tag_number(buf, dest)) {
buf_save_restore_rpos(buf, &save);
return NULL;
}
return dest;
}
s_tag * json_buf_parse (s_buf *buf, s_tag *dest)
{
character c;
sw r;
s_buf_save save;
s_tag tmp;
assert(buf);
assert(dest);
buf_save_init(buf, &save);
if ((r =buf_peek_character_utf8(buf, &c)) < 0)
return NULL;
switch (c) {
case '"':
buf_parse_tag_str(buf, &tmp);
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '-':
json_buf_parse_numbers(buf, &tmp);
break;
case 't':
case 'f':
buf_parse_tag_bool(buf, &tmp);
break;
default:
return NULL;
}
*dest = tmp;
return dest;
}
s_tag * json_from_str (const s_str *src, s_tag *dest)
{
s_buf buf;
buf_init_str_const(&buf, src);
return json_buf_parse(&buf, dest);
}