summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShilpa Singh <shilpa.singh@samsung.com>2016-02-19 15:56:31 -0800
committerCedric BAIL <cedric@osg.samsung.com>2016-02-29 15:40:06 -0800
commit4d489ee5360b5781a0f572ba0dfb69f7af23e52b (patch)
tree2b4a18bcf6bc1502e21b73d0d41418fb01af45e6
parentc0363a2979ba37d4c2e8c525ef6388a003a79a06 (diff)
downloadelementary-4d489ee5360b5781a0f572ba0dfb69f7af23e52b.tar.gz
spinner: add label format validator
Summary: Check for all error conditions case in elm_spinner_label_format_set and set label format only if its valid. Signed-off-by: Shilpa Singh <shilpa.singh@samsung.com> @feature Test Plan: 1. Launch elementary test spinner 2. Set invalid formats e.g. formats with out %, formats with more than one format specifier "%d %s" etc:- Reviewers: jpeg, cedric Reviewed By: cedric Subscribers: govi, buds, subodh6129 Differential Revision: https://phab.enlightenment.org/D3720 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
-rw-r--r--src/lib/elm_spinner.c81
1 files changed, 66 insertions, 15 deletions
diff --git a/src/lib/elm_spinner.c b/src/lib/elm_spinner.c
index 8eb3c03ae..75deea1ad 100644
--- a/src/lib/elm_spinner.c
+++ b/src/lib/elm_spinner.c
@@ -66,22 +66,67 @@ EO_CALLBACKS_ARRAY_DEFINE(_inc_dec_button_cb,
static void _access_increment_decrement_info_say(Evas_Object *obj,
Eina_Bool is_incremented);
+typedef enum _Elm_Spinner_Format_Type
+{
+ SPINNER_FORMAT_FLOAT,
+ SPINNER_FORMAT_INT,
+ SPINNER_FORMAT_INVALID
+} Elm_Spinner_Format_Type;
+
static Eina_Bool
+_is_valid_digit(char x)
+{
+ return ((x >= '0' && x <= '9') || (x == '.')) ? EINA_TRUE : EINA_FALSE;
+}
+
+static Elm_Spinner_Format_Type
_is_label_format_integer(const char *fmt)
{
- const char *start = strchr(fmt, '%');
- const char *itr;
+ const char *itr = NULL;
+ const char *start = NULL;
+ Eina_Bool found = EINA_FALSE;
+ Elm_Spinner_Format_Type ret_type = SPINNER_FORMAT_INVALID;
- for (itr = start + 1; *itr != '\0'; itr++)
+ start = strchr(fmt, '%');
+ if (!start) return SPINNER_FORMAT_INVALID;
+
+ while (start)
{
- if ((*itr == 'd') || (*itr == 'u') || (*itr == 'i') ||
- (*itr == 'o') || (*itr == 'x') || (*itr == 'X'))
- return EINA_TRUE;
- else if ((*itr == 'f') || (*itr == 'F'))
- return EINA_FALSE;
+ if (found && start[1] != '%')
+ {
+ return SPINNER_FORMAT_INVALID;
+ }
+
+ if (start[1] != '%' && !found)
+ {
+ found = EINA_TRUE;
+ for (itr = start + 1; *itr != '\0'; itr++)
+ {
+ if ((*itr == 'd') || (*itr == 'u') || (*itr == 'i') ||
+ (*itr == 'o') || (*itr == 'x') || (*itr == 'X'))
+ {
+ ret_type = SPINNER_FORMAT_INT;
+ break;
+ }
+ else if ((*itr == 'f') || (*itr == 'F'))
+ {
+ ret_type = SPINNER_FORMAT_FLOAT;
+ break;
+ }
+ else if (_is_valid_digit(*itr))
+ {
+ continue;
+ }
+ else
+ {
+ return SPINNER_FORMAT_INVALID;
+ }
+ }
+ }
+ start = strchr(start + 2, '%');
}
- return EINA_FALSE;
+ return ret_type;
}
static void
@@ -1382,17 +1427,23 @@ _elm_spinner_eo_base_constructor(Eo *obj, Elm_Spinner_Data *_pd EINA_UNUSED)
EOLIAN static void
_elm_spinner_label_format_set(Eo *obj, Elm_Spinner_Data *sd, const char *fmt)
{
- if (fmt && !strchr(fmt, '%'))
+ Elm_Spinner_Format_Type type;
+ if (fmt)
{
- WRN("Warning: %s is an Illegal format, cannot be set", fmt);
- return;
+ type = _is_label_format_integer(fmt);
+ if (type == SPINNER_FORMAT_INVALID)
+ {
+ ERR("format:\"%s\" is Invalid, cannot be set", fmt);
+ return;
+ }
+ else if (type == SPINNER_FORMAT_FLOAT)
+ {
+ sd->decimal_points = _decimal_points_get(fmt);
+ }
}
eina_stringshare_replace(&sd->label, fmt);
- if (fmt && !(_is_label_format_integer(sd->label)))
- sd->decimal_points = _decimal_points_get(sd->label);
-
_label_write(obj);
elm_layout_sizing_eval(obj);
_entry_accept_filter_add(obj);