From c2433f1728704e794e729ac1e3518596218d368e Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 15 Nov 2013 14:07:48 +0000 Subject: [PATCH] Sync with libucl. --- src/ucl/include/ucl.h | 3 ++- src/ucl/src/ucl_emitter.c | 2 +- src/ucl/src/ucl_internal.h | 2 +- src/ucl/src/ucl_parser.c | 12 ++++++------ src/ucl/src/ucl_util.c | 6 ++++-- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/ucl/include/ucl.h b/src/ucl/include/ucl.h index 7647ff3b1..52429c0a2 100644 --- a/src/ucl/include/ucl.h +++ b/src/ucl/include/ucl.h @@ -136,8 +136,9 @@ enum ucl_string_flags { UCL_STRING_PARSE_DOUBLE = 0x10, /**< UCL_STRING_PARSE_DOUBLE parse passed string and detect integer or float number */ UCL_STRING_PARSE_NUMBER = UCL_STRING_PARSE_INT|UCL_STRING_PARSE_DOUBLE , /**< UCL_STRING_PARSE_NUMBER parse passed string and detect number */ - UCL_STRING_PARSE = UCL_STRING_PARSE_BOOLEAN|UCL_STRING_PARSE_NUMBER /**< + UCL_STRING_PARSE = UCL_STRING_PARSE_BOOLEAN|UCL_STRING_PARSE_NUMBER, /**< UCL_STRING_PARSE parse passed string (and detect booleans and numbers) */ + UCL_STRING_PARSE_BYTES = 0x20 /**< Treat numbers as bytes */ }; /** diff --git a/src/ucl/src/ucl_emitter.c b/src/ucl/src/ucl_emitter.c index 2973f1da2..c7d14dc8a 100644 --- a/src/ucl/src/ucl_emitter.c +++ b/src/ucl/src/ucl_emitter.c @@ -537,7 +537,7 @@ ucl_elt_array_write_yaml (ucl_object_t *obj, UT_string *buf, unsigned int tabs, ucl_add_tabs (buf, tabs, false); } - utstring_append_len (buf, ": [\n", 4); + utstring_append_len (buf, "[\n", 2); while (cur) { ucl_elt_write_yaml (cur, buf, tabs + 1, true, false, false); utstring_append_len (buf, ",\n", 2); diff --git a/src/ucl/src/ucl_internal.h b/src/ucl/src/ucl_internal.h index a6d8e096b..6fbd4bf82 100644 --- a/src/ucl/src/ucl_internal.h +++ b/src/ucl/src/ucl_internal.h @@ -250,7 +250,7 @@ ucl_maybe_parse_boolean (ucl_object_t *obj, const unsigned char *start, size_t l * @return 0 if string is numeric and error code (EINVAL or ERANGE) in case of conversion error */ int ucl_maybe_parse_number (ucl_object_t *obj, - const char *start, const char *end, const char **pos, bool allow_double); + const char *start, const char *end, const char **pos, bool allow_double, bool number_bytes); static inline ucl_object_t * diff --git a/src/ucl/src/ucl_parser.c b/src/ucl/src/ucl_parser.c index 450a41877..07fe1a3c5 100644 --- a/src/ucl/src/ucl_parser.c +++ b/src/ucl/src/ucl_parser.c @@ -270,7 +270,7 @@ ucl_copy_or_store_ptr (struct ucl_parser *parser, int ucl_maybe_parse_number (ucl_object_t *obj, - const char *start, const char *end, const char **pos, bool allow_double) + const char *start, const char *end, const char **pos, bool allow_double, bool number_bytes) { const char *p = start, *c = start; char *endptr; @@ -387,8 +387,8 @@ ucl_maybe_parse_number (ucl_object_t *obj, p += 2; goto set_obj; } - else if (p[1] == 'b' || p[1] == 'B') { - /* Megabytes */ + else if (number_bytes || (p[1] == 'b' || p[1] == 'B')) { + /* Bytes */ if (need_double) { need_double = false; lv = dv; @@ -402,7 +402,7 @@ ucl_maybe_parse_number (ucl_object_t *obj, dv *= ucl_lex_num_multiplier (*p, false); } else { - lv *= ucl_lex_num_multiplier (*p, false); + lv *= ucl_lex_num_multiplier (*p, number_bytes); } p ++; goto set_obj; @@ -428,7 +428,7 @@ ucl_maybe_parse_number (ucl_object_t *obj, dv *= ucl_lex_num_multiplier (*p, false); } else { - lv *= ucl_lex_num_multiplier (*p, false); + lv *= ucl_lex_num_multiplier (*p, number_bytes); } p ++; goto set_obj; @@ -502,7 +502,7 @@ ucl_lex_number (struct ucl_parser *parser, const unsigned char *pos; int ret; - ret = ucl_maybe_parse_number (obj, chunk->pos, chunk->end, (const char **)&pos, true); + ret = ucl_maybe_parse_number (obj, chunk->pos, chunk->end, (const char **)&pos, true, false); if (ret == 0) { chunk->remain -= pos - chunk->pos; diff --git a/src/ucl/src/ucl_util.c b/src/ucl/src/ucl_util.c index 422b2ea75..b8c779c9a 100644 --- a/src/ucl/src/ucl_util.c +++ b/src/ucl/src/ucl_util.c @@ -845,12 +845,14 @@ ucl_object_fromstring_common (const char *str, size_t len, enum ucl_string_flags if (flags & UCL_STRING_PARSE_BOOLEAN) { if (!ucl_maybe_parse_boolean (obj, dst, obj->len) && (flags & UCL_STRING_PARSE_NUMBER)) { ucl_maybe_parse_number (obj, dst, dst + obj->len, &pos, - flags & UCL_STRING_PARSE_DOUBLE); + flags & UCL_STRING_PARSE_DOUBLE, + flags & UCL_STRING_PARSE_BYTES); } } else { ucl_maybe_parse_number (obj, dst, dst + obj->len, &pos, - flags & UCL_STRING_PARSE_DOUBLE); + flags & UCL_STRING_PARSE_DOUBLE, + flags & UCL_STRING_PARSE_BYTES); } } } -- 2.39.5