Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill another unused function: xbt_str_join.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 28 Oct 2017 13:32:25 +0000 (15:32 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 28 Oct 2017 13:32:51 +0000 (15:32 +0200)
ChangeLog
include/xbt/str.h
src/xbt/xbt_str.cpp

index 3c8d633..be9dcc0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,7 @@ SimGrid (3.18) NOT RELEASED YET (target: December 24 2017)
  - Define class simgrid::xbt::Path to manage file names.
  - Removed unused functions:
    - xbt/file.h: xbt_basename(), xbt_dirname(), xbt_getline()
  - Define class simgrid::xbt::Path to manage file names.
  - Removed unused functions:
    - xbt/file.h: xbt_basename(), xbt_dirname(), xbt_getline()
+   - xbt/str.h: xbt_str_join()
 
 SimGrid (3.17) Released October 8 2017
 
 
 SimGrid (3.17) Released October 8 2017
 
index f9d96e9..8068459 100644 (file)
@@ -30,7 +30,6 @@ XBT_PUBLIC(xbt_dynar_t) xbt_str_split(const char *s, const char *sep);
 XBT_PUBLIC(xbt_dynar_t) xbt_str_split_quoted(const char *s);
 XBT_PUBLIC(xbt_dynar_t) xbt_str_split_quoted_in_place(char *s);
 
 XBT_PUBLIC(xbt_dynar_t) xbt_str_split_quoted(const char *s);
 XBT_PUBLIC(xbt_dynar_t) xbt_str_split_quoted_in_place(char *s);
 
-XBT_PUBLIC(char *) xbt_str_join(xbt_dynar_t dynar, const char *sep);
 XBT_PUBLIC(char *) xbt_str_join_array(const char *const *strs, const char *sep);
 
 XBT_PUBLIC(long int) xbt_str_parse_int(const char* str, const char* error_msg);
 XBT_PUBLIC(char *) xbt_str_join_array(const char *const *strs, const char *sep);
 
 XBT_PUBLIC(long int) xbt_str_parse_int(const char* str, const char* error_msg);
index b7da378..9a1a893 100644 (file)
@@ -194,34 +194,6 @@ xbt_dynar_t xbt_str_split_quoted(const char *s)
   return res;
 }
 
   return res;
 }
 
-/** @brief Join a set of strings as a single string */
-char *xbt_str_join(xbt_dynar_t dyn, const char *sep)
-{
-  int len     = 1;
-  int dyn_len = xbt_dynar_length(dyn);
-  unsigned int cpt;
-  char* cursor;
-
-  if (not dyn_len)
-    return xbt_strdup("");
-
-  /* compute the length */
-  xbt_dynar_foreach(dyn, cpt, cursor) {
-    len += strlen(cursor);
-  }
-  len += strlen(sep) * dyn_len;
-  /* Do the job */
-  char* res = (char*)xbt_malloc(len);
-  char* p   = res;
-  xbt_dynar_foreach(dyn, cpt, cursor) {
-    if ((int) cpt < dyn_len - 1)
-      p += snprintf(p,len, "%s%s", cursor, sep);
-    else
-      p += snprintf(p,len, "%s", cursor);
-  }
-  return res;
-}
-
 /** @brief Join a set of strings as a single string
  *
  * The parameter must be a nullptr-terminated array of chars,
 /** @brief Join a set of strings as a single string
  *
  * The parameter must be a nullptr-terminated array of chars,
@@ -299,14 +271,16 @@ XBT_TEST_SUITE("xbt_str", "String Handling");
 
 #define mytest(name, input, expected)                                                                                  \
   xbt_test_add(name);                                                                                                  \
 
 #define mytest(name, input, expected)                                                                                  \
   xbt_test_add(name);                                                                                                  \
-  d = xbt_str_split_quoted(input);                                                                                     \
-  s = xbt_str_join(d, "XXX");                                                                                          \
+  a = static_cast<char**>(xbt_dynar_to_array(xbt_str_split_quoted(input)));                                            \
+  s = xbt_str_join_array(a, "XXX");                                                                                    \
   xbt_test_assert(not strcmp(s, expected), "Input (%s) leads to (%s) instead of (%s)", input, s, expected);            \
   xbt_test_assert(not strcmp(s, expected), "Input (%s) leads to (%s) instead of (%s)", input, s, expected);            \
-  free(s);                                                                                                             \
-  xbt_dynar_free(&d);
-XBT_TEST_UNIT("xbt_str_split_quoted", test_split_quoted, "test the function xbt_str_split_quoted")
+  xbt_free(s);                                                                                                         \
+  for (int i = 0; a[i] != nullptr; i++)                                                                                \
+    xbt_free(a[i]);                                                                                                    \
+  xbt_free(a);
+XBT_TEST_UNIT("xbt_str_split_quoted", test_split_quoted, "Test the function xbt_str_split_quoted")
 {
 {
-  xbt_dynar_t d;
+  char** a;
   char *s;
 
   mytest("Empty", "", "");
   char *s;
 
   mytest("Empty", "", "");