summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmitesh Singh <amitesh.sh@samsung.com>2017-11-28 17:05:31 +0900
committerAmitesh Singh <amitesh.sh@samsung.com>2017-11-28 17:05:31 +0900
commite8ae4178d846136e9993828c3523002c24cdf015 (patch)
tree60a8847a4063c8db85625411c4e11bbc9ddd59a9
parente97d00d5983bf9514c88097fe85e745f0019fe9b (diff)
Efl.Ui.Format: do format check once only.
-rw-r--r--src/lib/efl/interfaces/efl_ui_format.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/lib/efl/interfaces/efl_ui_format.c b/src/lib/efl/interfaces/efl_ui_format.c
index 7fdbc49..15212f1 100644
--- a/src/lib/efl/interfaces/efl_ui_format.c
+++ b/src/lib/efl/interfaces/efl_ui_format.c
@@ -3,11 +3,6 @@
3 3
4#define ERR(...) EINA_LOG_DOM_ERR(EINA_LOG_DOMAIN_DEFAULT, __VA_ARGS__) 4#define ERR(...) EINA_LOG_DOM_ERR(EINA_LOG_DOMAIN_DEFAULT, __VA_ARGS__)
5 5
6typedef struct
7{
8 const char *template;
9} Efl_Ui_Format_Data;
10
11typedef enum _Format_Type 6typedef enum _Format_Type
12{ 7{
13 FORMAT_TYPE_INVALID, 8 FORMAT_TYPE_INVALID,
@@ -15,6 +10,12 @@ typedef enum _Format_Type
15 FORMAT_TYPE_INT 10 FORMAT_TYPE_INT
16} Format_Type; 11} Format_Type;
17 12
13typedef struct
14{
15 const char *template;
16 Format_Type format_type;
17} Efl_Ui_Format_Data;
18
18static Eina_Bool 19static Eina_Bool
19_is_valid_digit(char x) 20_is_valid_digit(char x)
20{ 21{
@@ -78,7 +79,6 @@ _default_format_cb(void *data, Eina_Strbuf *str, const Eina_Value value)
78{ 79{
79 const Eina_Value_Type *type = eina_value_type_get(&value); 80 const Eina_Value_Type *type = eina_value_type_get(&value);
80 Efl_Ui_Format_Data *sd = data; 81 Efl_Ui_Format_Data *sd = data;
81 int format_check_result;
82 82
83 if (type == EINA_VALUE_TYPE_TM) 83 if (type == EINA_VALUE_TYPE_TM)
84 { 84 {
@@ -89,29 +89,27 @@ _default_format_cb(void *data, Eina_Strbuf *str, const Eina_Value value)
89 return; 89 return;
90 } 90 }
91 91
92 format_check_result = _format_string_check(sd->template); 92 if (sd->format_type == FORMAT_TYPE_INVALID)
93
94 if (format_check_result == FORMAT_TYPE_INVALID)
95 { 93 {
96 ERR("Wrong String Format: %s", sd->template); 94 ERR("Wrong String Format: %s", sd->template);
97 return; 95 return;
98 } 96 }
99 97
100 if ((format_check_result == FORMAT_TYPE_DOUBLE) 98 if ((sd->format_type == FORMAT_TYPE_DOUBLE)
101 && (type == EINA_VALUE_TYPE_DOUBLE)) 99 && (type == EINA_VALUE_TYPE_DOUBLE))
102 { 100 {
103 double v; 101 double v;
104 eina_value_get(&value, &v); 102 eina_value_get(&value, &v);
105 eina_strbuf_append_printf(str, sd->template, v); 103 eina_strbuf_append_printf(str, sd->template, v);
106 } 104 }
107 else if ((format_check_result == FORMAT_TYPE_INT) 105 else if ((sd->format_type == FORMAT_TYPE_INT)
108 && (type == EINA_VALUE_TYPE_INT)) 106 && (type == EINA_VALUE_TYPE_INT))
109 { 107 {
110 int v; 108 int v;
111 eina_value_get(&value, &v); 109 eina_value_get(&value, &v);
112 eina_strbuf_append_printf(str, sd->template, v); 110 eina_strbuf_append_printf(str, sd->template, v);
113 } 111 }
114 else if ((format_check_result == FORMAT_TYPE_DOUBLE) 112 else if ((sd->format_type == FORMAT_TYPE_DOUBLE)
115 && (type == EINA_VALUE_TYPE_INT)) 113 && (type == EINA_VALUE_TYPE_INT))
116 { 114 {
117 int v; 115 int v;
@@ -122,7 +120,7 @@ _default_format_cb(void *data, Eina_Strbuf *str, const Eina_Value value)
122 d_v = v; 120 d_v = v;
123 eina_strbuf_append_printf(str, sd->template, d_v); 121 eina_strbuf_append_printf(str, sd->template, d_v);
124 } 122 }
125 else if ((format_check_result == FORMAT_TYPE_INT) 123 else if ((sd->format_type == FORMAT_TYPE_INT)
126 && (type == EINA_VALUE_TYPE_DOUBLE)) 124 && (type == EINA_VALUE_TYPE_DOUBLE))
127 { 125 {
128 double v; 126 double v;
@@ -157,7 +155,10 @@ EOLIAN static void
157_efl_ui_format_format_string_set(Eo *obj, Efl_Ui_Format_Data *sd, const char *template) 155_efl_ui_format_format_string_set(Eo *obj, Efl_Ui_Format_Data *sd, const char *template)
158{ 156{
159 if (!template) return; 157 if (!template) return;
158
160 eina_stringshare_replace(&sd->template, template); 159 eina_stringshare_replace(&sd->template, template);
160 sd->format_type = _format_string_check(sd->template);
161
161 efl_ui_format_cb_set(obj, sd, _default_format_cb, _default_format_free_cb); 162 efl_ui_format_cb_set(obj, sd, _default_format_cb, _default_format_free_cb);
162} 163}
163 164