From fee715d7d966aa78e78e0754f546594f672069d8 Mon Sep 17 00:00:00 2001 From: "[CST] Focus" Date: Wed, 23 Apr 2014 17:21:50 +0400 Subject: [PATCH] system/helpers.cpp: add split_config_string helper Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/bef1b79bed5f68462ac28e452330d7c2bf2841f1 Author: [CST] Focus Date: 2014-04-23 (Wed, 23 Apr 2014) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- src/system/helpers.cpp | 17 +++++++++++++++++ src/system/helpers.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index 4e1152323..85a369ff6 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -740,3 +740,20 @@ void hdd_flush(const char * fname) close(fd); } } + +/* split string like PARAM1=value1 PARAM2=value2 into map */ +bool split_config_string(const std::string &str, std::map &smap) +{ + smap.clear(); + std::string::size_type start = 0; + std::string::size_type end = 0; + while ((end = str.find(" ", start)) != std::string::npos) { + std::string param = str.substr(start, end - start); + std::string::size_type i = param.find("="); + if (i != std::string::npos) { + smap[param.substr(0,i).c_str()] = param.substr(i+1).c_str(); + } + start = end + 1; + } + return !smap.empty(); +} diff --git a/src/system/helpers.h b/src/system/helpers.h index 480c43f03..de994141a 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -26,6 +26,7 @@ #include #include #include +#include int my_system(const char * cmd); int my_system(int argc, const char *arg, ...); /* argc is number of arguments including command */ @@ -85,4 +86,5 @@ template std::string to_string(C i) inline void cstrncpy(char *dest, const char * const src, size_t n) { n--; strncpy(dest, src, n); dest[n] = 0; } inline void cstrncpy(char *dest, const std::string &src, size_t n) { n--; strncpy(dest, src.c_str(), n); dest[n] = 0; } +bool split_config_string(const std::string &str, std::map &smap); #endif