diff options
author | Carsten Haitzler (Rasterman) <raster@rasterman.com> | 2018-02-10 16:26:15 +0900 |
---|---|---|
committer | Carsten Haitzler (Rasterman) <raster@rasterman.com> | 2018-02-10 16:44:38 +0900 |
commit | e96532f65c13ffe11b25f7d9b384daa197d928e8 (patch) | |
tree | fdafb1c71a90bd1a9f3e3b972e4927a0f7237c81 | |
parent | d26f2237f18cf9408265a867bbba4027fc6e94a1 (diff) | |
download | efl-e96532f65c13ffe11b25f7d9b384daa197d928e8.tar.gz |
efl ui format - fix format checking to be correct
the format string checking was just ... wrong. it didnt' handle %%. it
didn't handle constant strings with no format in them... now it does.
fixes T6697
@fix
-rw-r--r-- | src/lib/efl/interfaces/efl_ui_format.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/src/lib/efl/interfaces/efl_ui_format.c b/src/lib/efl/interfaces/efl_ui_format.c index bb40c340a8..4ee5a63590 100644 --- a/src/lib/efl/interfaces/efl_ui_format.c +++ b/src/lib/efl/interfaces/efl_ui_format.c @@ -10,6 +10,7 @@ typedef enum _Format_Type FORMAT_TYPE_DOUBLE, FORMAT_TYPE_INT, FORMAT_TYPE_STRING, + FORMAT_TYPE_STATIC } Format_Type; typedef struct @@ -27,26 +28,23 @@ _is_valid_digit(char x) static Format_Type _format_string_check(const char *fmt) { - const char *itr = NULL; - const char *start = NULL; + const char *itr; Eina_Bool found = EINA_FALSE; - Format_Type ret_type = FORMAT_TYPE_INVALID; + Format_Type ret_type = FORMAT_TYPE_STATIC; - start = strchr(fmt, '%'); - if (!start) return 0; - - while (start) + for (itr = fmt; *itr; itr++) { - if (found && start[1] != '%') + if (itr[0] != '%') continue; + if (itr[1] == '%') { - ret_type = FORMAT_TYPE_INVALID; - break; + itr++; + continue; } - if (start[1] != '%' && !found) + if (!found) { found = EINA_TRUE; - for (itr = start + 1; *itr != '\0'; itr++) + for (itr++; *itr; itr++) { // FIXME: This does not properly support int64 or unsigned. if ((*itr == 'd') || (*itr == 'u') || (*itr == 'i') || @@ -75,10 +73,19 @@ _format_string_check(const char *fmt) break; } } + if (!(*itr)) break; + } + else + { + ret_type = FORMAT_TYPE_INVALID; + break; } - start = strchr(start + 2, '%'); } + if (ret_type == FORMAT_TYPE_INVALID) + { + ERR("Format string '%s' is invalid. It must have one and only one format element of type 's', 'f', 'F', 'd', 'u', 'i', 'o', 'x' or 'X'", fmt); + } return ret_type; } @@ -121,6 +128,10 @@ _default_format_cb(void *data, Eina_Strbuf *str, const Eina_Value value) eina_strbuf_append_printf(str, sd->template, v); free(v); } + else if (sd->format_type == FORMAT_TYPE_STATIC) + { + eina_strbuf_append_printf(str, sd->template); + } else { // Error: Discard format string and just print value. |