From: russ Date: Fri, 15 Jul 2022 15:48:22 +0000 (-0400) Subject: parameter: simplify multi validation X-Git-Tag: 3.1.40.0~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b8d4148160f8a096a2bfb254de0989262e8acb5;p=thirdparty%2Fsnort3.git parameter: simplify multi validation --- diff --git a/src/framework/parameter.cc b/src/framework/parameter.cc index d9816c2bd..8cee32450 100644 --- a/src/framework/parameter.cc +++ b/src/framework/parameter.cc @@ -75,26 +75,13 @@ static unsigned get_index(const char* r, const char* t) return idx; } -#define delim " \t\n" - -static size_t split(const string& txt, vector& strs) +static size_t split(const string& s, vector& strs) { - size_t last = txt.find_first_not_of(delim); - size_t pos = txt.find_first_of(delim, last); - strs.clear(); - - while ( pos != string::npos ) - { - if ( last != pos ) - strs.emplace_back(txt.substr(last, pos - last)); - - last = txt.find_first_not_of(delim, pos + 1); - pos = txt.find_first_of(delim, last); - } + stringstream ss(s); + string tok; - // add the last one - if ( last != string::npos ) - strs.emplace_back(txt.substr(last, min(pos, txt.size()) - last)); + while ( ss >> tok ) + strs.push_back(tok); return strs.size(); } @@ -286,9 +273,9 @@ static bool valid_multi(Value& v, const char* r) if ( !r ) return false; - string s = v.get_string(); + const string str = v.get_string(); vector list; - split(s, list); + split(str, list); uint64_t mask = 0;