Skip to content

Conversation

immqu
Copy link
Contributor

@immqu immqu commented Jul 16, 2025

This PR introduces a simple string versioning scheme that compares strings based on lexicographical order (UTF-8 encoded).

Addresses package-url/vers-spec#24

immqu added 3 commits August 21, 2025 10:10
Signed-off-by: Kunz, Immanuel <[email protected]>
Signed-off-by: Kunz, Immanuel <[email protected]>
@immqu immqu force-pushed the lexicographic-versioning-scheme branch from 13e36ad to 9064438 Compare August 21, 2025 08:14
return remove_spaces(str(string))

def __lt__(self, other):
return self.value.encode("utf-8") < other.value.encode("utf-8")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some reference docs that explain how two UTF-8 byte strings are compared, so we can get that working beyond Python?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this conforms with rfc 3629 which states

UTF-8 encodes UCS characters as a varying number of octets, where the number of octets, and the value of each, depend on the integer value assigned to the character in ISO/IEC 10646 (the character number, a.k.a. code position, code point or Unicode scalar value). This encoding form has the following characteristics (all values are in hexadecimal):
...

  • The byte-value lexicographic sorting order of UTF-8 strings is the same as if ordered by character numbers. Of course this is of limited interest since a sort order based on character numbers is almost never culturally valid.

https://www.rfc-editor.org/rfc/rfc3629.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for checking!

Copy link
Member

@pombredanne pombredanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also consider using JSON tests in the same style as https://github.com/package-url/vers-spec/blob/main/tests/conan_version_cmp_test.json

@immqu
Copy link
Contributor Author

immqu commented Sep 11, 2025

It is now further specified here: package-url/vers-spec#37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants