elm_datetime: Parses the format recursively. 23/145723/2
authorWoochan Lee <wc0917.lee@samsung.com>
Wed, 23 Aug 2017 11:02:38 +0000 (20:02 +0900)
committerwoochan lee <wc0917.lee@samsung.com>
Wed, 23 Aug 2017 11:40:59 +0000 (11:40 +0000)
Summary:
Some of locale formats convert as extension format.
For example,
             uk_UA d_t_fmt is "%a, %d-%b-%Y %X %z".
             The %X will convert as %T.
             The %T format has to convert one more time to convert as %H:%M:%S.

ref : https://lh.2xlibre.net/locale/uk_UA/

We need to parse the format recursively to support that kind of case.

@fix

Test Plan:
Change the locale as uk_UA.
Run elementary_test -> datetime
See the time field is not appear.

Reviewers: jpeg, cedric

Subscribers: cedric, jpeg

Differential Revision: https://phab.enlightenment.org/D5021

Change-Id: Ie088a4558d3688542e9bcf43dacd1a9a339b433e

src/lib/elm_datetime.c

index ea31054..84dc2c5 100644 (file)
@@ -187,33 +187,39 @@ static void
 _expand_format(char *dt_fmt)
 {
    char *ptr, *expanded_fmt, ch;
-   unsigned int idx = 0, len = 0;
+   unsigned int idx, len = 0;
    char buf[ELM_DATETIME_MAX_FORMAT_LEN] = {0, };
-   Eina_Bool fmt_char = EINA_FALSE;
-
-   ptr = dt_fmt;
-   while ((ch = *ptr))
-     {
-        if ((fmt_char) && (strchr(multifield_formats, ch)))
-          {
-             /* replace the multi-field format characters with
-              * corresponding expanded format */
-             expanded_fmt = _expanded_fmt_str_get(ch);
-             len = strlen(expanded_fmt);
-             buf[--idx] = 0;
-             strncat(buf, expanded_fmt, len);
-             idx += len;
-          }
-        else buf[idx++] = ch;
-
-        if (ch == '%') fmt_char = EINA_TRUE;
-        else fmt_char = EINA_FALSE;
-
-        ptr++;
-     }
-
-   buf[idx] = 0;
-   strncpy(dt_fmt, buf, ELM_DATETIME_MAX_FORMAT_LEN);
+   Eina_Bool fmt_char, fmt_expanded;
+
+   do {
+     idx = 0;
+     fmt_char = EINA_FALSE;
+     fmt_expanded = EINA_FALSE;
+     ptr = dt_fmt;
+     while ((ch = *ptr))
+       {
+          if ((fmt_char) && (strchr(multifield_formats, ch)))
+            {
+               /* replace the multi-field format characters with
+                * corresponding expanded format */
+               expanded_fmt = _expanded_fmt_str_get(ch);
+               len = strlen(expanded_fmt);
+               if (len > 0) fmt_expanded = EINA_TRUE;
+               buf[--idx] = 0;
+               strncat(buf, expanded_fmt, len);
+               idx += len;
+            }
+          else buf[idx++] = ch;
+
+          if (ch == '%') fmt_char = EINA_TRUE;
+          else fmt_char = EINA_FALSE;
+
+          ptr++;
+       }
+
+     buf[idx] = 0;
+     strncpy(dt_fmt, buf, ELM_DATETIME_MAX_FORMAT_LEN);
+   } while (fmt_expanded);
 }
 
 static void