From 879eefb39ec9cb22a5825825f0fa0bc143eb9fb4 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Fri, 28 Jan 2022 09:40:18 +0100 Subject: [PATCH] Simplified regex split Instead of building the result vector with push_back, I now use the vector c'tor with iterators directly. --- src/string_utils.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/string_utils.cpp b/src/string_utils.cpp index ce3bd10..1de289d 100644 --- a/src/string_utils.cpp +++ b/src/string_utils.cpp @@ -32,12 +32,7 @@ vector sc::split(const string& str, const string& sep) } vector sc::split(const string& str, const regex& sep) { - vector components; - sregex_token_iterator end {}; - for (sregex_token_iterator p {str.begin(), str.end(), sep, -1}; p != end; ++p) { - components.push_back(*p); - } - return components; + return {sregex_token_iterator {str.begin(), str.end(), sep, -1}, sregex_token_iterator {}}; } string sc::join(const vector& components, const string& join)