reapack

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

commit 821f28a96a4cb7060341cdbc34aea4b62d1f5663
parent 6a0bad30f5c64fb4a9817dd80b749baabf6d9ed1
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Thu, 27 Oct 2016 23:27:07 -0400

remote: remove unused code from the times of the .ReaPackRemote files

Diffstat:
Msrc/remote.cpp | 33++++++++++++++-------------------
Msrc/remote.hpp | 9+--------
Mtest/remote.cpp | 19++++++-------------
3 files changed, 21 insertions(+), 40 deletions(-)

diff --git a/src/remote.cpp b/src/remote.cpp @@ -17,9 +17,9 @@ #include "remote.hpp" -#include "encoding.hpp" #include "errors.hpp" +#include <boost/lexical_cast.hpp> #include <regex> #include <sstream> @@ -27,7 +27,7 @@ using namespace std; static char DATA_DELIMITER = '|'; -static bool ValidateName(const string &name) +static bool validateName(const string &name) { static const regex validPattern("[^~#%&*{}\\\\:<>?/+|\"]+"); static const regex invalidPattern("\\.+"); @@ -39,7 +39,7 @@ static bool ValidateName(const string &name) return !match.empty() && invalid.empty(); } -static bool ValidateUrl(const string &url) +static bool validateUrl(const string &url) { using namespace std::regex_constants; @@ -53,7 +53,7 @@ static bool ValidateUrl(const string &url) return !match.empty(); } -Remote Remote::fromString(const string &data, ReadCode *code) +Remote Remote::fromString(const string &data) { istringstream stream(data); @@ -66,22 +66,17 @@ Remote Remote::fromString(const string &data, ReadCode *code) string enabled; getline(stream, enabled, DATA_DELIMITER); - if(!ValidateName(name)) { - if(code) - *code = InvalidName; - } - else if(!ValidateUrl(url)) { - if(code) - *code = InvalidUrl; - } - else { - if(code) - *code = Success; + if(!validateName(name) || !validateUrl(url)) + return {}; + + Remote remote(name, url); - return {name, url, enabled == "1"}; + try { + remote.setEnabled(boost::lexical_cast<bool>(enabled)); } + catch(const boost::bad_lexical_cast &) {} - return {}; + return remote; } Remote::Remote() @@ -98,7 +93,7 @@ Remote::Remote(const string &name, const string &url, const bool enabled) void Remote::setName(const string &name) { - if(!ValidateName(name)) + if(!validateName(name)) throw reapack_error("invalid name"); else m_name = name; @@ -106,7 +101,7 @@ void Remote::setName(const string &name) void Remote::setUrl(const string &url) { - if(!ValidateUrl(url)) + if(!validateUrl(url)) throw reapack_error("invalid url"); else m_url = url; diff --git a/src/remote.hpp b/src/remote.hpp @@ -24,14 +24,7 @@ class Remote { public: - enum ReadCode { - Success, - ReadFailure, - InvalidName, - InvalidUrl, - }; - - static Remote fromString(const std::string &data, ReadCode *code = nullptr); + static Remote fromString(const std::string &data); Remote(); Remote(const std::string &name, const std::string &url, bool enabled = true); diff --git a/test/remote.cpp b/test/remote.cpp @@ -186,22 +186,15 @@ TEST_CASE("get remote by name", M) { } TEST_CASE("unserialize remote", M) { - SECTION("invalid name") { - Remote::ReadCode code; - REQUIRE(Remote::fromString("&", &code).isNull()); - REQUIRE(code == Remote::InvalidName); - } + SECTION("invalid name") + REQUIRE_FALSE(Remote::fromString("&")); - SECTION("invalid name") { - Remote::ReadCode code; - REQUIRE(Remote::fromString("name||false", &code).isNull()); - REQUIRE(code == Remote::InvalidUrl); - } + SECTION("invalid name") + REQUIRE_FALSE(Remote::fromString("name||false")); SECTION("valid enabled") { - Remote::ReadCode code; - Remote remote = Remote::fromString("name|url|1", &code); - REQUIRE(code == Remote::Success); + Remote remote = Remote::fromString("name|url|1"); + REQUIRE(remote); REQUIRE(remote.name() == "name"); REQUIRE(remote.url() == "url");