aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-04-17 23:26:23 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-04-17 23:26:23 +0000
commitf9faabe4149eadc20308f3e3ae6f69dff61fc772 (patch)
tree9d7c7ef2a4e27b618c1af1892be5d99f10b4caf9
parent8d2ca8c97e7782e4a12fc09a099606ee5e6c320a (diff)
downloadpaludis-f9faabe4149eadc20308f3e3ae6f69dff61fc772.tar.gz
paludis-f9faabe4149eadc20308f3e3ae6f69dff61fc772.tar.xz
Another go at sane leading zero handling
-rw-r--r--paludis/version_spec.cc57
-rw-r--r--paludis/version_spec.sr2
-rw-r--r--paludis/version_spec_TEST.cc1
3 files changed, 39 insertions, 21 deletions
diff --git a/paludis/version_spec.cc b/paludis/version_spec.cc
index e9fdb49..2ed2e76 100644
--- a/paludis/version_spec.cc
+++ b/paludis/version_spec.cc
@@ -349,21 +349,29 @@ VersionSpec::compare(const VersionSpec & other) const
if (p2 == &end_part && p1->kind == revision && p1->value == 0)
continue;
- unsigned long m1(1), m2(1);
- for (unsigned long x(0) ; x < p2->multiplier ; ++x)
- m1 *= 10;
- for (unsigned long x(0) ; x < p1->multiplier ; ++x)
- m2 *= 10;
-
if (p1->kind < p2->kind)
return -1;
if (p1->kind > p2->kind)
return 1;
- if (p1->value * m1 < p2->value * m2)
- return -1;
- if (p1->value * m1 > p2->value * m2)
- return 1;
+ if ((0 != p1->leading_zeroes) || (0 != p2->leading_zeroes))
+ {
+ std::string p1s(std::string(p1->leading_zeroes, '0') + stringify(p1->value));
+ std::string p2s(std::string(p2->leading_zeroes, '0') + stringify(p2->value));
+ int c(p1s.compare(p2s));
+
+ if (c < 0)
+ return -1;
+ if (c > 0)
+ return 1;
+ }
+ else
+ {
+ if (p1->value < p2->value)
+ return -1;
+ if (p1->value > p2->value)
+ return 1;
+ }
}
return 0;
@@ -391,19 +399,28 @@ VersionSpec::tilde_compare(const VersionSpec & other) const
}
else
{
- unsigned long m1(1), m2(1);
- for (unsigned long x(0) ; x < p2->multiplier ; ++x)
- m1 *= 10;
- for (unsigned long x(0) ; x < p1->multiplier ; ++x)
- m2 *= 10;
-
if (p2->kind == revision)
{
- if (p2->value * m2 > p1->value * m1)
+ if (p2->value > p1->value)
return false;
}
- else if (p1->value * m1 != p2->value * m2)
- return false;
+ else
+ {
+ if ((0 != p1->leading_zeroes) || (0 != p2->leading_zeroes))
+ {
+ std::string p1s(std::string(p1->leading_zeroes, '0') + strip_trailing(stringify(p1->value), "0"));
+ std::string p2s(std::string(p2->leading_zeroes, '0') + strip_trailing(stringify(p2->value), "0"));
+ int c(p1s.compare(p2s));
+
+ if (c != 0)
+ return false;
+ }
+ else
+ {
+ if (p1->value != p2->value)
+ return false;
+ }
+ }
}
}
@@ -438,7 +455,7 @@ VersionSpec::hash_value() const
std::size_t hh(result & h_mask);
result <<= 5;
result ^= (hh >> h_shift);
- result ^= (static_cast<std::size_t>(r->kind) + (r->value << 3) + (r->multiplier << 12));
+ result ^= (static_cast<std::size_t>(r->kind) + (r->value << 3) + (r->leading_zeroes << 12));
}
} while (false);
diff --git a/paludis/version_spec.sr b/paludis/version_spec.sr
index 118fa5f..0125b6f 100644
--- a/paludis/version_spec.sr
+++ b/paludis/version_spec.sr
@@ -5,7 +5,7 @@ make_class_Part()
{
key kind PartKind
key value "unsigned long"
- key multiplier "unsigned long"
+ key leading_zeroes "unsigned long"
}
diff --git a/paludis/version_spec_TEST.cc b/paludis/version_spec_TEST.cc
index a681427..2b28a12 100644
--- a/paludis/version_spec_TEST.cc
+++ b/paludis/version_spec_TEST.cc
@@ -374,6 +374,7 @@ namespace test_cases
v.push_back(VersionSpec("1.0.0"));
v.push_back(VersionSpec("1.001"));
v.push_back(VersionSpec("1.01"));
+ v.push_back(VersionSpec("1.0101"));
v.push_back(VersionSpec("1.1_alpha3"));
v.push_back(VersionSpec("1.1"));
v.push_back(VersionSpec("1.1-r1"));