summaryrefslogtreecommitdiff
path: root/src/string.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-10-19 16:27:36 +0100
committerMaxime Coste <frrrwww@gmail.com>2014-10-19 16:27:36 +0100
commit69113e2711e59da42df5658ab18c7d1847d6db12 (patch)
tree964a5541d5484d7221b10e880d8350ba3d7ab250 /src/string.cc
parent2e0b4d02b7ee6140e509d1434cba1879520fcb23 (diff)
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.
Diffstat (limited to 'src/string.cc')
-rw-r--r--src/string.cc16
1 files changed, 16 insertions, 0 deletions
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<String> split(StringView str, char separator, char escape)
return res;
}
+std::vector<StringView> split(StringView str, char separator)
+{
+ std::vector<StringView> 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;