aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-06-06 12:23:41 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-06-06 17:14:29 +0100
commit300e20ba7ad2d795ba1d36c6cdd034f6a46ae5ed (patch)
treeb614b56bdbbf50b5da903d3361125bdbb35c2c67
parent850cd4d6491d4405c24b03309f15a96aa12b71b6 (diff)
downloadpaludis-300e20ba7ad2d795ba1d36c6cdd034f6a46ae5ed.tar.gz
paludis-300e20ba7ad2d795ba1d36c6cdd034f6a46ae5ed.tar.xz
Implement vso_flexible_dots
-rw-r--r--paludis/version_spec.cc20
-rw-r--r--paludis/version_spec_TEST.cc21
2 files changed, 38 insertions, 3 deletions
diff --git a/paludis/version_spec.cc b/paludis/version_spec.cc
index e6b24f6..53b1893 100644
--- a/paludis/version_spec.cc
+++ b/paludis/version_spec.cc
@@ -131,6 +131,7 @@ VersionSpec::VersionSpec(const std::string & text, const VersionSpecOptions & op
{
/* numbers... */
bool first_number(true);
+ std::string number_prefix;
while (true)
{
std::string number_part;
@@ -140,17 +141,30 @@ VersionSpec::VersionSpec(const std::string & text, const VersionSpecOptions & op
if (first_number || '0' != number_part[0])
_imp->parts.push_back(make_named_values<VersionSpecComponent>(
n::number_value() = strip_leading(number_part, "0"),
- n::text() = first_number ? number_part : "." + number_part,
+ n::text() = first_number ? number_part : number_prefix + number_part,
n::type() = vsct_number
));
else
_imp->parts.push_back(make_named_values<VersionSpecComponent>(
n::number_value() = number_part,
- n::text() = "." + number_part,
+ n::text() = number_prefix + number_part,
n::type() = vsct_floatlike
));
- if (! parser.consume(simple_parser::exact(".")))
+ number_prefix.clear();
+ if (parser.consume(simple_parser::exact(".")))
+ number_prefix = ".";
+ else if (options[vso_flexible_dots])
+ {
+ std::string allowed_dot_replacements("-");
+ if (options[vso_flexible_dashes])
+ allowed_dot_replacements.append("_");
+ if (parser.lookahead(simple_parser::any_of(allowed_dot_replacements) & simple_parser::any_of("0123456789")))
+ if (! parser.consume(simple_parser::any_of(allowed_dot_replacements) >> number_prefix))
+ throw InternalError(PALUDIS_HERE, "lookahead worked, parse failed. huh?");
+ }
+
+ if (number_prefix.empty())
break;
first_number = false;
}
diff --git a/paludis/version_spec_TEST.cc b/paludis/version_spec_TEST.cc
index 25f4601..f44e1b9 100644
--- a/paludis/version_spec_TEST.cc
+++ b/paludis/version_spec_TEST.cc
@@ -705,6 +705,27 @@ namespace test_cases
}
} test_version_spec_flexible_dashes;
+ struct VersionSpecFlexibleDotsTest : TestCase
+ {
+ VersionSpecFlexibleDotsTest() : TestCase("flexible dots") { }
+
+ void run()
+ {
+ TEST_CHECK_THROWS(VersionSpec("1.2-3_alpha4", VersionSpecOptions()), BadVersionSpecError);
+ VersionSpec v1("1.2-3_alpha4", VersionSpecOptions() + vso_flexible_dots);
+ VersionSpec v2("1.2.3_alpha4", VersionSpecOptions());
+ TEST_CHECK(v1 == v2);
+ TEST_CHECK(v1.hash() == v2.hash());
+
+ TEST_CHECK_THROWS(VersionSpec("1_2-3-4.5", VersionSpecOptions() + vso_flexible_dots), BadVersionSpecError);
+ VersionSpec v3("1_2-3-4.5", VersionSpecOptions() + vso_flexible_dots + vso_flexible_dashes);
+ VersionSpec v4("1.2.3.4.5", VersionSpecOptions());
+ TEST_CHECK(v3 == v4);
+ TEST_CHECK(v3.hash() == v4.hash());
+
+ }
+ } test_version_spec_flexible_dots;
+
struct VersionSpecLeadingVTest : TestCase
{
VersionSpecLeadingVTest() : TestCase("leading v") { }