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)
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,
66static void _access_increment_decrement_info_say(Evas_Object *obj, 66static void _access_increment_decrement_info_say(Evas_Object *obj,
67 Eina_Bool is_incremented); 67 Eina_Bool is_incremented);
68 68
69typedef enum _Elm_Spinner_Format_Type
70{
71 SPINNER_FORMAT_FLOAT,
72 SPINNER_FORMAT_INT,
73 SPINNER_FORMAT_INVALID
74} Elm_Spinner_Format_Type;
75
69static Eina_Bool 76static Eina_Bool
77_is_valid_digit(char x)
78{
79 return ((x >= '0' && x <= '9') || (x == '.')) ? EINA_TRUE : EINA_FALSE;
80}
81
82static Elm_Spinner_Format_Type
70_is_label_format_integer(const char *fmt) 83_is_label_format_integer(const char *fmt)
71{ 84{
72 const char *start = strchr(fmt, '%'); 85 const char *itr = NULL;
73 const char *itr; 86 const char *start = NULL;
87 Eina_Bool found = EINA_FALSE;
88 Elm_Spinner_Format_Type ret_type = SPINNER_FORMAT_INVALID;
74 89
75 for (itr = start + 1; *itr != '\0'; itr++) 90 start = strchr(fmt, '%');
91 if (!start) return SPINNER_FORMAT_INVALID;
92
93 while (start)
76 { 94 {
77 if ((*itr == 'd') || (*itr == 'u') || (*itr == 'i') || 95 if (found && start[1] != '%')
78 (*itr == 'o') || (*itr == 'x') || (*itr == 'X')) 96 {
79 return EINA_TRUE; 97 return SPINNER_FORMAT_INVALID;
80 else if ((*itr == 'f') || (*itr == 'F')) 98 }
81 return EINA_FALSE; 99
100 if (start[1] != '%' && !found)
101 {
102 found = EINA_TRUE;
103 for (itr = start + 1; *itr != '\0'; itr++)
104 {
105 if ((*itr == 'd') || (*itr == 'u') || (*itr == 'i') ||
106 (*itr == 'o') || (*itr == 'x') || (*itr == 'X'))
107 {
108 ret_type = SPINNER_FORMAT_INT;
109 break;
110 }
111 else if ((*itr == 'f') || (*itr == 'F'))
112 {
113 ret_type = SPINNER_FORMAT_FLOAT;
114 break;
115 }
116 else if (_is_valid_digit(*itr))
117 {
118 continue;
119 }
120 else
121 {
122 return SPINNER_FORMAT_INVALID;
123 }
124 }
125 }
126 start = strchr(start + 2, '%');
82 } 127 }
83 128
84 return EINA_FALSE; 129 return ret_type;
85} 130}
86 131
87static void 132static void
@@ -1382,17 +1427,23 @@ _elm_spinner_eo_base_constructor(Eo *obj, Elm_Spinner_Data *_pd EINA_UNUSED)
1382EOLIAN static void 1427EOLIAN static void
1383_elm_spinner_label_format_set(Eo *obj, Elm_Spinner_Data *sd, const char *fmt) 1428_elm_spinner_label_format_set(Eo *obj, Elm_Spinner_Data *sd, const char *fmt)
1384{ 1429{
1385 if (fmt && !strchr(fmt, '%')) 1430 Elm_Spinner_Format_Type type;
1431 if (fmt)
1386 { 1432 {
1387 WRN("Warning: %s is an Illegal format, cannot be set", fmt); 1433 type = _is_label_format_integer(fmt);
1388 return; 1434 if (type == SPINNER_FORMAT_INVALID)
1435 {
1436 ERR("format:\"%s\" is Invalid, cannot be set", fmt);
1437 return;
1438 }
1439 else if (type == SPINNER_FORMAT_FLOAT)
1440 {
1441 sd->decimal_points = _decimal_points_get(fmt);
1442 }
1389 } 1443 }
1390 1444
1391 eina_stringshare_replace(&sd->label, fmt); 1445 eina_stringshare_replace(&sd->label, fmt);
1392 1446
1393 if (fmt && !(_is_label_format_integer(sd->label)))
1394 sd->decimal_points = _decimal_points_get(sd->label);
1395
1396 _label_write(obj); 1447 _label_write(obj);
1397 elm_layout_sizing_eval(obj); 1448 elm_layout_sizing_eval(obj);
1398 _entry_accept_filter_add(obj); 1449 _entry_accept_filter_add(obj);