reapack

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

commit 84f56a613e1cdd241d8fcd33765974c531b03cae
parent 3c8d8a8a0d02ed81dde55162697db97fb9ddd3dd
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Mon, 18 Jan 2016 14:46:54 -0500

fix absolute paths on Unix-based systems

Diffstat:
Msrc/config.cpp | 5++---
Msrc/path.cpp | 17++++++++++-------
Mtest/path.cpp | 18++++++++++++++++++
3 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/src/config.cpp b/src/config.cpp @@ -58,10 +58,9 @@ void Config::read(const Path &path) if(!file_exists(m_path.c_str())) { fillDefaults(); write(); - return; } - - readRemotes(); + else + readRemotes(); restoreSelfRemote(); } diff --git a/src/path.cpp b/src/path.cpp @@ -31,19 +31,22 @@ static vector<string> Split(const string &input) { vector<string> list; - size_t last = 0; + size_t last = 0, size = input.size(); - while(true) { - const size_t pos = input.find_first_of("\\/", last); + while(last < size) { + const size_t pos = input.find_first_of("\\/", last + 1); 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 @@ -129,4 +129,22 @@ TEST_CASE("split input", M) { REQUIRE(a.size() == 2); } + + SECTION("skip empty parts") { + Path a; + a.append("hello//world/"); + + REQUIRE(a.size() == 2); + } } + +#ifndef _WIN32 +TEST_CASE("absolute path (unix)", M) { + Path a; + a.append("/usr/bin/zsh"); + + REQUIRE(a.size() == 3); + REQUIRE(a[0] == "/usr"); + REQUIRE(a.join() == "/usr/bin/zsh"); +} +#endif