Improve compatibility with older compilers (GCC 4.8); Fix bug with string comparison; Improve compatibility with different Boost versions (testing).

This commit is contained in:
Marko Zivanovic
2015-10-09 11:28:55 +02:00
parent 2e39070287
commit 65832925b8
6 changed files with 39 additions and 14 deletions
+2 -2
View File
@@ -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)
+4 -4
View File
@@ -24,7 +24,7 @@ SOFTWARE.
#pragma once
#include <iosfwd>
#include <ostream>
#include <string>
#include <vector>
@@ -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();
+3 -1
View File
@@ -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) {
+3 -3
View File
@@ -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();
};
}
}
+4 -4
View File
@@ -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
+23
View File
@@ -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<version::Build_identifiers>::operator()(std::ostream& os,
const version::Build_identifiers& ids) {
@@ -53,6 +58,24 @@ namespace boost {
os << id.first << "|" << static_cast<int>(id.second) << "|" << ",";
}
}
#else
template<>
inline std::ostream& operator<<(std::ostream& os, const print_helper_t<version::Build_identifiers>& ph) {
for (const auto& id: ph.m_t) {
os << id << ",";
}
return os;
}
template<>
inline std::ostream& operator<<(std::ostream& os, const print_helper_t<version::Prerelease_identifiers>& ph) {
for (const auto& id : ph.m_t) {
os << id.first << "|" << static_cast<int>(id.second) << "|" << ",";
}
return os;
}
#endif
}
}
}