reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit ddc5a55845720817977ca553915ce889dd363892
parent bc3b89f64d04692a0d79e046213d977107f8f6e3
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Mon, 18 Jan 2016 15:10:58 -0500

fix handling of empty path components

Diffstat:
Msrc/path.cpp | 14+++++++++-----
Mtest/path.cpp | 2++
2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/path.cpp b/src/path.cpp @@ -17,6 +17,7 @@ #include "path.hpp" +#include <algorithm> #include <vector> using namespace std; @@ -34,16 +35,19 @@ static vector<string> Split(const string &input) size_t last = 0, size = input.size(); while(last < size) { - const size_t pos = input.find_first_of("\\/", last + 1); + const size_t pos = input.find_first_of("\\/", max((size_t)1, last)); if(pos == string::npos) { list.push_back(input.substr(last)); break; } - else { - list.push_back(input.substr(last, pos - last)); - last = pos + 1; - } + + const string part = input.substr(last, pos - last); + + if(!part.empty()) + list.push_back(part); + + last = pos + 1; } return list; diff --git a/test/path.cpp b/test/path.cpp @@ -135,6 +135,8 @@ TEST_CASE("split input", M) { a.append("hello//world/"); REQUIRE(a.size() == 2); + REQUIRE(a[0] == "hello"); + REQUIRE(a[1] == "world"); } }