[EGIT] [core/efl] master 01/03: eina: refactor and simplify vpath.

2019-05-11 Thread Cedric BAIL
cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=9c992c05d5494764df209faf1a36c04972814628

commit 9c992c05d5494764df209faf1a36c04972814628
Author: Cedric BAIL 
Date:   Fri May 10 14:28:49 2019 -0700

eina: refactor and simplify vpath.

Reviewed-by: Marcel Hollerbach 
Differential Revision: https://phab.enlightenment.org/D8882
---
 src/lib/eina/eina_vpath.c | 12 ++--
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/src/lib/eina/eina_vpath.c b/src/lib/eina/eina_vpath.c
index aa7b46bddb..87b85662d9 100644
--- a/src/lib/eina/eina_vpath.c
+++ b/src/lib/eina/eina_vpath.c
@@ -258,18 +258,10 @@ _eina_vpath_resolve(const char *path, char *str, size_t 
size)
  {
 const char *p, *end, *meta;
 char *name;
-int max_len = strlen(path);
 Eina_Bool found = EINA_FALSE;
 
-for (p = path + 2; p <= path + max_len - 2; p++)
-  {
- if ((p[0] ==':') && (p[1] == ')'))
-   {
-  end = p;
-  found = EINA_TRUE;
-  break;
-   }
-  }
+end = p = strstr(path + 2, ":)");
+if (p) found = EINA_TRUE;
 p += 2;
 
 if (!found)

-- 




[EGIT] [core/efl] master 03/03: eina: add tests for the new Vpath syntax.

2019-05-11 Thread Cedric BAIL
cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=c75415ae369f5988975bc6e40378d9de5e2ccef0

commit c75415ae369f5988975bc6e40378d9de5e2ccef0
Author: Cedric BAIL 
Date:   Fri May 10 14:42:57 2019 -0700

eina: add tests for the new Vpath syntax.

Reviewed-by: Marcel Hollerbach 
Differential Revision: https://phab.enlightenment.org/D8884
---
 src/tests/eina/eina_test_vpath.c | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/tests/eina/eina_test_vpath.c b/src/tests/eina/eina_test_vpath.c
index 851c47ee2b..cad61bd831 100644
--- a/src/tests/eina/eina_test_vpath.c
+++ b/src/tests/eina/eina_test_vpath.c
@@ -21,8 +21,8 @@ EFL_START_TEST(eina_test_vpath_valid)
 
snprintf(test, sizeof(test), "%s/bla", eina_environment_home_get());
ck_assert_str_eq(eina_vpath_resolve("(:home:)/bla"), test);
+   ck_assert_str_eq(eina_vpath_resolve("${home}/bla"), test);
ck_assert_str_eq(eina_vpath_resolve("/test/for/the/last/case"), 
"/test/for/the/last/case");
-
 }
 EFL_END_TEST
 
@@ -33,6 +33,13 @@ EFL_START_TEST(eina_test_vpath_invalid)
ck_assert_ptr_eq(eina_vpath_resolve("(:"), NULL);
ck_assert_ptr_eq(eina_vpath_resolve("(:home:)"), NULL);
ck_assert_ptr_eq(eina_vpath_resolve("(:wrong_meta_key:)/"), NULL);
+   ck_assert_ptr_eq(eina_vpath_resolve("${asdfasdfafasdf"), NULL);
+   ck_assert_ptr_eq(eina_vpath_resolve("${missing_slash}"), NULL);
+   ck_assert_ptr_eq(eina_vpath_resolve("${"), NULL);
+   ck_assert_ptr_eq(eina_vpath_resolve("${home}"), NULL);
+   ck_assert_ptr_eq(eina_vpath_resolve("${wrong_meta_key}/"), NULL);
+   ck_assert_ptr_eq(eina_vpath_resolve("${home:)"), NULL);
+   ck_assert_ptr_eq(eina_vpath_resolve("${wrong_meta_key:)/"), NULL);
 }
 EFL_END_TEST
 
@@ -47,6 +54,10 @@ EFL_START_TEST(eina_test_vpath_snprintf)
eina_vpath_resolve_snprintf(buf, sizeof(buf), "(:home:)/%s/%d/", string, x);
snprintf(cmp, sizeof(cmp), "%s/%s/%d/", eina_environment_home_get(), 
string, x);
ck_assert_str_eq(buf, cmp);
+
+   eina_vpath_resolve_snprintf(buf, sizeof(buf), "${home}/%s/%d/", string, x);
+   snprintf(cmp, sizeof(cmp), "%s/%s/%d/", eina_environment_home_get(), 
string, x);
+   ck_assert_str_eq(buf, cmp);
 }
 EFL_END_TEST
 

-- 




[EGIT] [core/efl] master 02/03: eina: update vpath to also support a more classic syntax for variable.

2019-05-11 Thread Cedric BAIL
cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=370917751f83bcaf65b56fde8d1a2b0d47b1d676

commit 370917751f83bcaf65b56fde8d1a2b0d47b1d676
Author: Cedric BAIL 
Date:   Fri May 10 14:37:24 2019 -0700

eina: update vpath to also support a more classic syntax for variable.

This enable vpath to recognize also ${} as a variable. It does mimic
what Efl.ViewModel provide with Efl.ViewModel.PropertyText and various
other language.

Reviewed-by: Marcel Hollerbach 
Differential Revision: https://phab.enlightenment.org/D8883
---
 src/lib/eina/eina_vpath.c | 30 +++---
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/src/lib/eina/eina_vpath.c b/src/lib/eina/eina_vpath.c
index 87b85662d9..0717e928e0 100644
--- a/src/lib/eina/eina_vpath.c
+++ b/src/lib/eina/eina_vpath.c
@@ -254,37 +254,53 @@ _eina_vpath_resolve(const char *path, char *str, size_t 
size)
}
  }
// (:xxx:)/* ... <- meta hash table
-   else if ((path[0] == '(') && (path[1] == ':'))
+   else if (((path[0] == '(') && (path[1] == ':')) ||
+((path[0] == '$') && (path[1] == '{')))
  {
 const char *p, *end, *meta;
+const char *msg_start, *msg_end;
 char *name;
+int offset;
 Eina_Bool found = EINA_FALSE;
 
-end = p = strstr(path + 2, ":)");
+if (path[0] == '(')
+  {
+ end = p = strstr(path + 2, ":)");
+ offset = 2;
+ msg_start = "(:";
+ msg_end = ":)";
+  }
+else
+  {
+ end = p = strchr(path + 2, '}');
+ offset = 1;
+ msg_start = "${";
+ msg_end = "}";
+  }
 if (p) found = EINA_TRUE;
-p += 2;
+p += offset;
 
 if (!found)
   {
- ERR("(: Needs to have a matching ':)'\nThe string was: %s", path);
+ ERR("'%s' Needs to have a matching '%s'\nThe string was: %s", 
msg_start, msg_end, path);
  return 0;
   }
 
 if (*p != '/')
   {
- ERR("A / is expected after :)\nThe string was: %s", path);
+ ERR("A / is expected after '%s'\nThe string was: %s", msg_end, 
path);
  return 0;
   }
 
 if (found)
   {
  name = alloca(end - path);
- strncpy(name, path + 2, end - path - 2);
+ strncpy(name, path + 2, end - path - offset);
  name[end - path - 2] = 0;
  meta = _eina_vpath_data_get(name);
  if (meta)
{
-  return snprintf(str, size, "%s%s", meta, end + 2);
+  return snprintf(str, size, "%s%s", meta, end + offset);
}
  else
{

--