diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-12-06 17:18:44 +0800 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-12-06 17:18:44 +0800 |
| commit | 99636c6230f9a3f6a818db5a301137114bf79617 (patch) | |
| tree | 9db923cdab521029dba8299d7b98ed057043c0ae /src/string_utils.cc | |
| parent | 1b44056fce951cb5b853202d26148ffa5d45a119 (diff) | |
Remove Vector returning split functions, use range adaptor
Do not allocate temporary vectors to store splitted data, use the
'split' range adaptor along with transform(unescape) to provide the
same feature with less allocations.
Diffstat (limited to 'src/string_utils.cc')
| -rw-r--r-- | src/string_utils.cc | 70 |
1 files changed, 0 insertions, 70 deletions
diff --git a/src/string_utils.cc b/src/string_utils.cc index 06e0eb7c..55c7562e 100644 --- a/src/string_utils.cc +++ b/src/string_utils.cc @@ -7,60 +7,6 @@ namespace Kakoune { -Vector<String> split(StringView str, char separator, char escape) -{ - Vector<String> res; - auto it = str.begin(); - auto start = it; - while (it != str.end()) - { - res.emplace_back(); - String& element = res.back(); - while (it != str.end()) - { - auto c = *it; - if (c == escape and it + 1 != str.end() and *(it+1) == separator) - { - element += StringView{start, it+1}; - element.back() = separator; - it += 2; - start = it; - } - else if (c == separator) - { - element += StringView{start, it}; - ++it; - start = it; - break; - } - else - ++it; - } - } - if (start != str.end()) - res.back() += StringView{start, str.end()}; - return res; -} - -Vector<StringView> split(StringView str, char separator) -{ - Vector<StringView> res; - if (str.empty()) - return 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; -} - StringView trim_whitespaces(StringView str) { auto beg = str.begin(), end = str.end(); @@ -390,22 +336,6 @@ UnitTest test_string{[]() { kak_assert(String("youpi ") + "matin" == "youpi matin"); - Vector<String> splited = split("youpi:matin::tchou\\:kanaky:hihi\\:", ':', '\\'); - kak_assert(splited[0] == "youpi"); - kak_assert(splited[1] == "matin"); - kak_assert(splited[2] == ""); - kak_assert(splited[3] == "tchou:kanaky"); - kak_assert(splited[4] == "hihi:"); - - Vector<StringView> splitedview = split("youpi:matin::tchou\\:kanaky:hihi\\:", ':'); - kak_assert(splitedview[0] == "youpi"); - kak_assert(splitedview[1] == "matin"); - kak_assert(splitedview[2] == ""); - kak_assert(splitedview[3] == "tchou\\"); - kak_assert(splitedview[4] == "kanaky"); - kak_assert(splitedview[5] == "hihi\\"); - kak_assert(splitedview[6] == ""); - Vector<StringView> wrapped = wrap_lines("wrap this paragraph\n respecting whitespaces and much_too_long_words", 16); kak_assert(wrapped.size() == 6); kak_assert(wrapped[0] == "wrap this"); |
