Skip to content

Commit 4f9b8a3

Browse files
authored
Merge pull request #25 from bugst/relaxed-comparators
Made Version.SortableString() comparable directly with RelaxedVersion.SortableString()
2 parents aa0ac68 + fe12533 commit 4f9b8a3

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

Diff for: README.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,22 @@ This is accomplished by adding some adjustment characters to the original semver
113113

114114
To give you an idea on how it works, the following table shows some examples of semver versions and their `SortableString` counter part:
115115

116-
| semver | `SortableString()` |
117-
| ------------------ | ------------------ |
118-
| `1.2.4` | `1.2.4;` |
119-
| `1.3.0-rc` | `1.3.0-;rc` |
120-
| `1.3.0-rc.0` | `1.3.0-;rc,:0` |
121-
| `1.3.0-rc.5` | `1.3.0-;rc,:5` |
122-
| `1.3.0-rc.5+build` | `1.3.0-;rc,:5` |
123-
| `1.3.0-rc.20` | `1.3.0-;rc,::20` |
124-
| `1.3.0-rc-` | `1.3.0-;rc-` |
125-
| `1.3.0` | `1.3.0;` |
126-
| `1.20.0` | `1.:20.0;` |
127-
| `1.90.0` | `1.:90.0;` |
128-
| `1.300.0-6` | `1.::300.0-:6` |
129-
| `1.300.0-30` | `1.::300.0-::30` |
130-
| `1.300.0-1pre` | `1.::300.0-;1pre` |
131-
| `1.300.0-pre` | `1.::300.0-;pre` |
132-
| `1.300.0` | `1.::300.0;` |
116+
| semver | `SortableString()` |
117+
| ------------------ | ------------------- |
118+
| `1.2.4` | `;1.2.4;` |
119+
| `1.3.0-rc` | `;1.3.0-;rc` |
120+
| `1.3.0-rc.0` | `;1.3.0-;rc,:0` |
121+
| `1.3.0-rc.5` | `;1.3.0-;rc,:5` |
122+
| `1.3.0-rc.5+build` | `;1.3.0-;rc,:5` |
123+
| `1.3.0-rc.20` | `;1.3.0-;rc,::20` |
124+
| `1.3.0-rc-` | `;1.3.0-;rc-` |
125+
| `1.3.0` | `;1.3.0;` |
126+
| `1.20.0` | `;1.:20.0;` |
127+
| `1.90.0` | `;1.:90.0;` |
128+
| `1.300.0-6` | `;1.::300.0-:6` |
129+
| `1.300.0-30` | `;1.::300.0-::30` |
130+
| `1.300.0-1pre` | `;1.::300.0-;1pre` |
131+
| `1.300.0-pre` | `;1.::300.0-;pre` |
132+
| `1.300.0` | `;1.::300.0;` |
133133

134134
The `SortableString()` can be used in SQL databases to simplify the ordering of a set of versions in a table.

Diff for: relaxed_version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (v *RelaxedVersion) CompatibleWith(u *RelaxedVersion) bool {
114114
// introduced in a system that doesn't support semver ordering.
115115
func (v *RelaxedVersion) SortableString() string {
116116
if v.version != nil {
117-
return ";" + v.version.SortableString()
117+
return v.version.SortableString()
118118
}
119119
return ":" + string(v.customversion)
120120
}

Diff for: version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ func (v *Version) SortableString() string {
455455
vPatch = v.bytes[v.minor+1 : v.patch]
456456
}
457457

458-
res := encodeNumber(vMajor) + "." + encodeNumber(vMinor) + "." + encodeNumber(vPatch)
458+
res := ";" + encodeNumber(vMajor) + "." + encodeNumber(vMinor) + "." + encodeNumber(vPatch)
459459
// If there is no pre-release, add a ";" to the end, otherwise add a "-" followed by the pre-release.
460460
// This ensure the correct ordering of the pre-release versions (that are always lower than the normal versions).
461461
if v.prerelease == v.patch {

0 commit comments

Comments
 (0)