summaryrefslogtreecommitdiff
path: root/src/lib/efl/interfaces
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-12-12 11:30:13 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-12-12 11:38:35 +0900
commit832e12e8c4ca9d1550618839dbd3a58df59a8ff7 (patch)
tree3864e774b1053b52d0433e1a2ced73ae97383e7d /src/lib/efl/interfaces
parent0de20aeafa894e5302b873550fa8cab58f345eec (diff)
format: Fixup the string format implementation
Use eina value convert and to_string. Do not fail. This removes unreachable code by making it active (to_string). Fixes T6204
Diffstat (limited to 'src/lib/efl/interfaces')
-rw-r--r--src/lib/efl/interfaces/efl_ui_format.c66
1 files changed, 29 insertions, 37 deletions
diff --git a/src/lib/efl/interfaces/efl_ui_format.c b/src/lib/efl/interfaces/efl_ui_format.c
index 15212f168f..bb40c340a8 100644
--- a/src/lib/efl/interfaces/efl_ui_format.c
+++ b/src/lib/efl/interfaces/efl_ui_format.c
@@ -2,12 +2,14 @@
2#include "Efl.h" 2#include "Efl.h"
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#define DBG(...) EINA_LOG_DOM_DBG(EINA_LOG_DOMAIN_DEFAULT, __VA_ARGS__)
5 6
6typedef enum _Format_Type 7typedef enum _Format_Type
7{ 8{
8 FORMAT_TYPE_INVALID, 9 FORMAT_TYPE_INVALID,
9 FORMAT_TYPE_DOUBLE, 10 FORMAT_TYPE_DOUBLE,
10 FORMAT_TYPE_INT 11 FORMAT_TYPE_INT,
12 FORMAT_TYPE_STRING,
11} Format_Type; 13} Format_Type;
12 14
13typedef struct 15typedef struct
@@ -46,6 +48,7 @@ _format_string_check(const char *fmt)
46 found = EINA_TRUE; 48 found = EINA_TRUE;
47 for (itr = start + 1; *itr != '\0'; itr++) 49 for (itr = start + 1; *itr != '\0'; itr++)
48 { 50 {
51 // FIXME: This does not properly support int64 or unsigned.
49 if ((*itr == 'd') || (*itr == 'u') || (*itr == 'i') || 52 if ((*itr == 'd') || (*itr == 'u') || (*itr == 'i') ||
50 (*itr == 'o') || (*itr == 'x') || (*itr == 'X')) 53 (*itr == 'o') || (*itr == 'x') || (*itr == 'X'))
51 { 54 {
@@ -57,6 +60,11 @@ _format_string_check(const char *fmt)
57 ret_type = FORMAT_TYPE_DOUBLE; 60 ret_type = FORMAT_TYPE_DOUBLE;
58 break; 61 break;
59 } 62 }
63 else if (*itr == 's')
64 {
65 ret_type = FORMAT_TYPE_STRING;
66 break;
67 }
60 else if (_is_valid_digit(*itr)) 68 else if (_is_valid_digit(*itr))
61 { 69 {
62 continue; 70 continue;
@@ -79,62 +87,46 @@ _default_format_cb(void *data, Eina_Strbuf *str, const Eina_Value value)
79{ 87{
80 const Eina_Value_Type *type = eina_value_type_get(&value); 88 const Eina_Value_Type *type = eina_value_type_get(&value);
81 Efl_Ui_Format_Data *sd = data; 89 Efl_Ui_Format_Data *sd = data;
90 Eina_Value copy;
82 91
83 if (type == EINA_VALUE_TYPE_TM) 92 if (type == EINA_VALUE_TYPE_TM)
84 { 93 {
85 struct tm v; 94 struct tm v;
86 eina_value_get(&value, &v); 95 eina_value_get(&value, &v);
87 eina_strbuf_append_strftime(str, sd->template, &v); 96 eina_strbuf_append_strftime(str, sd->template, &v);
88
89 return; 97 return;
90 } 98 }
91 99
92 if (sd->format_type == FORMAT_TYPE_INVALID) 100 if (sd->format_type == FORMAT_TYPE_DOUBLE)
93 { 101 {
94 ERR("Wrong String Format: %s", sd->template); 102 double v = 0.0;
95 return; 103 eina_value_setup(&copy, EINA_VALUE_TYPE_DOUBLE);
96 } 104 eina_value_convert(&value, &copy);
97 105 eina_value_get(&copy, &v);
98 if ((sd->format_type == FORMAT_TYPE_DOUBLE)
99 && (type == EINA_VALUE_TYPE_DOUBLE))
100 {
101 double v;
102 eina_value_get(&value, &v);
103 eina_strbuf_append_printf(str, sd->template, v); 106 eina_strbuf_append_printf(str, sd->template, v);
107 eina_value_flush(&copy);
104 } 108 }
105 else if ((sd->format_type == FORMAT_TYPE_INT) 109 else if (sd->format_type == FORMAT_TYPE_INT)
106 && (type == EINA_VALUE_TYPE_INT))
107 { 110 {
108 int v; 111 int v = 0;
109 eina_value_get(&value, &v); 112 eina_value_setup(&copy, EINA_VALUE_TYPE_INT);
113 eina_value_convert(&value, &copy);
114 eina_value_get(&copy, &v);
110 eina_strbuf_append_printf(str, sd->template, v); 115 eina_strbuf_append_printf(str, sd->template, v);
116 eina_value_flush(&copy);
111 } 117 }
112 else if ((sd->format_type == FORMAT_TYPE_DOUBLE) 118 else if (sd->format_type == FORMAT_TYPE_STRING)
113 && (type == EINA_VALUE_TYPE_INT))
114 { 119 {
115 int v; 120 char *v = eina_value_to_string(&value);
116 double d_v; 121 eina_strbuf_append_printf(str, sd->template, v);
117 122 free(v);
118 eina_value_get(&value, &v);
119
120 d_v = v;
121 eina_strbuf_append_printf(str, sd->template, d_v);
122 }
123 else if ((sd->format_type == FORMAT_TYPE_INT)
124 && (type == EINA_VALUE_TYPE_DOUBLE))
125 {
126 double v;
127 int i_v;
128
129 eina_value_get(&value, &v);
130
131 i_v = v;
132 eina_strbuf_append_printf(str, sd->template, i_v);
133 } 123 }
134 else 124 else
135 { 125 {
126 // Error: Discard format string and just print value.
127 DBG("Could not guess value type in format string: '%s'", sd->template);
136 char *v = eina_value_to_string(&value); 128 char *v = eina_value_to_string(&value);
137 eina_strbuf_append_printf(str, "%s", v); 129 eina_strbuf_append(str, v);
138 free(v); 130 free(v);
139 } 131 }
140} 132}