diff --git a/kernel/src/path.cpp b/kernel/src/path.cpp index cd0731cd..18e301dc 100644 --- a/kernel/src/path.cpp +++ b/kernel/src/path.cpp @@ -18,10 +18,7 @@ path::path(const std::string& path){ names.push_back("/"); } - auto parts = std::split(path, '/'); - names.reserve(names.size() + parts.size()); - - std::copy(parts.begin(), parts.end(), std::back_inserter(names)); + std::split_append(path, names, '/'); } path::path(const path& base_path, const std::string& p){ diff --git a/tstl/include/string.hpp b/tstl/include/string.hpp index d5bfab29..76f99398 100644 --- a/tstl/include/string.hpp +++ b/tstl/include/string.hpp @@ -658,6 +658,26 @@ std::vector> split(const std::basic_string& s, cha return std::move(parts); } +template +void split_append(const std::basic_string& s, std::vector>& container, char sep = ' '){ + std::basic_string current(s.size()); + + for(char c : s){ + if(c == sep && !current.empty()){ + container.push_back(current); + current.clear(); + } else if(c == sep){ + continue; + } else { + current += c; + } + } + + if(!current.empty()){ + container.push_back(current); + } +} + template std::string to_string(const T& value);