diff --git a/CMakeLists.txt b/CMakeLists.txt index 015e568..f072533 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 2.8) project(semver) set(VERSION_MAJOR "0") set(VERSION_MINOR "1") @@ -19,7 +19,7 @@ endif() if(UNIX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -pedantic") - add_definitions(-std=c++14) + add_definitions(-std=c++11) endif() if(WIN32) diff --git a/include/version.h b/include/version.h index b664250..3f6d66c 100644 --- a/include/version.h +++ b/include/version.h @@ -24,7 +24,7 @@ SOFTWARE. #pragma once -#include +#include #include #include @@ -86,7 +86,7 @@ namespace version { public: /// Construct Basic_version object using Parser to parse version string and Comparator for comparison. Basic_version(const std::string& v, Parser p, Comparator c) - : parser_{ p }, comparator_{ c }, ver_{ parser_.parse(v) } {}; + : parser_(p), comparator_(c), ver_(parser_.parse(v)) {}; /// Compare if left version object is less than the right. friend bool operator<(const Basic_version& l, const Basic_version& r) { @@ -101,14 +101,14 @@ namespace version { os << v.ver_.major << "." << v.ver_.minor << "." << v.ver_.patch; if (!v.ver_.prerelease_ids.empty()) { os << "-"; - for (auto& it = v.ver_.prerelease_ids.cbegin(); it < v.ver_.prerelease_ids.cend() - 1; ++it) { + for (auto it = v.ver_.prerelease_ids.cbegin(); it < v.ver_.prerelease_ids.cend() - 1; ++it) { os << it->first << "."; } os << v.ver_.prerelease_ids.crbegin()->first; } if (!v.ver_.build_ids.empty()) { os << "+"; - for (auto& it = v.ver_.build_ids.cbegin(); it < v.ver_.build_ids.cend() - 1; ++it) { + for (auto it = v.ver_.build_ids.cbegin(); it < v.ver_.build_ids.cend() - 1; ++it) { os << *it << "."; } os << *v.ver_.build_ids.crbegin(); diff --git a/src/Semver200_comparator.cpp b/src/Semver200_comparator.cpp index afc6820..a43da2d 100644 --- a/src/Semver200_comparator.cpp +++ b/src/Semver200_comparator.cpp @@ -43,7 +43,9 @@ namespace { int compare_prerel_identifiers(const Prerelease_identifier& l, const Prerelease_identifier& r) { if (l.second == Identifier_type::alnum && r.second == Identifier_type::alnum) { - return l.first.compare(r.first); + auto cmp = l.first.compare(r.first); + if (cmp == 0) return cmp; + return cmp > 0 ? 1 : -1; } else if (l.second == Identifier_type::alnum && r.second == Identifier_type::num) { return 1; } else if (l.second == Identifier_type::num && r.second == Identifier_type::alnum) { diff --git a/src/Semver200_parser.cpp b/src/Semver200_parser.cpp index 8b538d6..cee6d72 100644 --- a/src/Semver200_parser.cpp +++ b/src/Semver200_parser.cpp @@ -75,7 +75,7 @@ namespace { } /// Validate prerelease and build version components. - inline void prerelease_version_validator(const string& tgt, const char c) { + inline void prerelease_version_validator(const string&, const char c) { if ((c < '0' || c > '9') && (c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && c != '.' && c != '-') throw version::Parse_error("invalid character encountered: " + string(1, c)); } @@ -101,7 +101,7 @@ namespace { } prerelease.push_back(Prerelease_identifier(id, t)); id.clear(); - }; + } /// Validate every individual build identifier and add it to collection. void build_hook_impl(string& id, Parser_state& pstate, version::Build_identifiers& build, @@ -111,7 +111,7 @@ namespace { if (id.empty()) throw version::Parse_error("version identifier cannot be empty"); build.push_back(id); id.clear(); - }; + } } diff --git a/test/semver200_parser_tests.cpp b/test/semver200_parser_tests.cpp index 0396666..fcd2ec4 100644 --- a/test/semver200_parser_tests.cpp +++ b/test/semver200_parser_tests.cpp @@ -71,8 +71,8 @@ BOOST_AUTO_TEST_CASE(parse_prerel_ids_types) { BOOST_AUTO_TEST_CASE(parse_prerel_legal_chars) { CHECK_PREREL("1.2.3-test-1-2-3-CAP", 1, 2, 3, Prerelease_identifiers({ { "test-1-2-3-CAP", A } })); CHECK_PARSE_ERROR("1.2.3-test#1"); - CHECK_PARSE_ERROR("1.2.3-test.©2015"); - CHECK_PARSE_ERROR("1.2.3-????-????-1"); + CHECK_PARSE_ERROR("1.2.3-test.Β©2015"); + CHECK_PARSE_ERROR("1.2.3-Ρ›ΠΈΡ€ΠΈΠ»ΠΈΡ†Π°-1"); } // prerel ids may not be empty @@ -107,8 +107,8 @@ BOOST_AUTO_TEST_CASE(parse_build_ids) { BOOST_AUTO_TEST_CASE(parse_build_legal_chars) { CHECK_BUILD("1.2.3+test-1-2-3-CAP", 1, 2, 3, Build_identifiers({ "test-1-2-3-CAP" })); CHECK_PARSE_ERROR("1.2.3+test#1"); - CHECK_PARSE_ERROR("1.2.3+test.©2015"); - CHECK_PARSE_ERROR("1.2.3+????-????-1"); + CHECK_PARSE_ERROR("1.2.3+test.Β©2015"); + CHECK_PARSE_ERROR("1.2.3+Ρ›ΠΈΡ€ΠΈΠ»ΠΈΡ†Π°-1"); } // build ids may not be empty diff --git a/test/semver200_parser_util.h b/test/semver200_parser_util.h index 25f4e32..c32e612 100644 --- a/test/semver200_parser_util.h +++ b/test/semver200_parser_util.h @@ -35,9 +35,14 @@ const version::Build_identifiers no_build_ids; #define N Identifier_type::num #define A Identifier_type::alnum +#define BOOST_PATCH BOOST_VERSION % 100 +#define BOOST_MINOR BOOST_VERSION / 100 % 1000 +#define BOOST_MAJOR BOOST_VERSION / 100000 + namespace boost { namespace test_tools { namespace tt_detail { +#if BOOST_MAJOR == 1 && BOOST_MINOR < 56 template<> void print_log_value::operator()(std::ostream& os, const version::Build_identifiers& ids) { @@ -53,6 +58,24 @@ namespace boost { os << id.first << "|" << static_cast(id.second) << "|" << ","; } } +#else + + template<> + inline std::ostream& operator<<(std::ostream& os, const print_helper_t& ph) { + for (const auto& id: ph.m_t) { + os << id << ","; + } + return os; + } + + template<> + inline std::ostream& operator<<(std::ostream& os, const print_helper_t& ph) { + for (const auto& id : ph.m_t) { + os << id.first << "|" << static_cast(id.second) << "|" << ","; + } + return os; + } +#endif } } }