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 */
};
/**
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);
* @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 *
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;
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;
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;
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;
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;
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);
}
}
}