From: Frederic Suter Date: Mon, 13 Mar 2017 09:39:30 +0000 (+0100) Subject: xbt_str_split -- X-Git-Tag: v3_15~130 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/d89593eda3b667f2819209d6da0d7459d7338208 xbt_str_split -- --- diff --git a/src/surf/trace_mgr.cpp b/src/surf/trace_mgr.cpp index ddd0708951..5455bdbb3a 100644 --- a/src/surf/trace_mgr.cpp +++ b/src/surf/trace_mgr.cpp @@ -5,16 +5,19 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "xbt/sysdep.h" +#include "xbt/dict.h" #include "xbt/log.h" #include "xbt/str.h" -#include "xbt/dict.h" + #include "src/surf/trace_mgr.hpp" #include "src/surf/surf_interface.hpp" #include "surf_private.h" #include "xbt/RngStream.h" +#include +#include +#include #include #include -#include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_trace, surf, "Surf trace management"); @@ -33,26 +36,24 @@ tmgr_trace_t tmgr_trace_new_from_string(const char *name, const char *input, dou { int linecount = 0; tmgr_event_t last_event = nullptr; - unsigned int cpt; - char *val; xbt_assert(trace_list.find(name) == trace_list.end(), "Refusing to define trace %s twice", name); xbt_assert(periodicity >= 0, "Invalid periodicity %g (must be positive)", periodicity); tmgr_trace_t trace = new simgrid::trace_mgr::trace(); - xbt_dynar_t list = xbt_str_split(input, "\n\r"); - xbt_dynar_foreach(list, cpt, val) { + std::vector list; + boost::split(list, input, boost::is_any_of("\n\r")); + for (auto val : list) { s_tmgr_event_t event; linecount++; - xbt_str_trim(val, " \t\n\r\x0B"); + boost::trim(val); if (val[0] == '#' || val[0] == '\0' || val[0] == '%') // pass comments continue; - - if (sscanf(val, "PERIODICITY " "%lg" "\n", &periodicity) == 1) + if (sscanf(val.c_str(), "PERIODICITY " "%lg" "\n", &periodicity) == 1) continue; - xbt_assert(sscanf(val, "%lg" " " "%lg" "\n", &event.delta, &event.value) == 2, + xbt_assert(sscanf(val.c_str(), "%lg" " " "%lg" "\n", &event.delta, &event.value) == 2, "%s:%d: Syntax error in trace\n%s", name, linecount, input); if (last_event) { @@ -77,7 +78,6 @@ tmgr_trace_t tmgr_trace_new_from_string(const char *name, const char *input, dou trace_list.insert({xbt_strdup(name), trace}); - xbt_dynar_free(&list); return trace; }