From 69113e2711e59da42df5658ab18c7d1847d6db12 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 19 Oct 2014 16:27:36 +0100 Subject: Add a split function that does not take an escape and returns StringViews When an escape character is not present, split can just return sub strings of the parameter, so we can avoid duplicating the original string data. --- src/string.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/string.cc') diff --git a/src/string.cc b/src/string.cc index f31ed83f..79da055b 100644 --- a/src/string.cc +++ b/src/string.cc @@ -46,6 +46,22 @@ std::vector split(StringView str, char separator, char escape) return res; } +std::vector split(StringView str, char separator) +{ + std::vector res; + auto beg = str.begin(); + for (auto it = beg; it != str.end(); ++it) + { + if (*it == separator) + { + res.emplace_back(beg, it); + beg = it + 1; + } + } + res.emplace_back(beg, str.end()); + return res; +} + String escape(StringView str, char character, char escape) { String res; -- cgit v1.2.3