feat: RFC and sub-series aware ref sorting#1320
Closed
kesara wants to merge 5 commits into
Closed
Conversation
Contributor
|
Hi Kesara,
please do not solve this with a ton of brittle special cases.
Please do read up on:
[Natural sort order](https://en.wikipedia.org/wiki/Natural_sort_order)
[Sorting for Humans : Natural Sort Order](https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/)
You can simply use Python's natsort to use a debugged implementation.
[natsort · PyPI](https://pypi.org/project/natsort/)
Grüße, Carsten
|
Member
Author
|
@cabo, Thanks for the suggestion I wasn't aware about it. But there are issues with using |
Contributor
|
Hi Kesara,
glad to be of service!
On Apr 14, 2026, at 01:55, Kesara Rathnayake ***@***.***> wrote:
We are adding another third party dependency to xml2rfc.
Right. The essence can be written in a few lines of code.
I don’t speak Python, but a friendly bot said:
```
import re
_num_re = re.compile(r'(\d+)')
def natural_key(s: str):
"""
E.g. "file000abc" -> ["file", (0, -3), "abc"]
"""
parts = _num_re.split(s)
key = []
for i, part in enumerate(parts):
if i % 2 == 1: # digit run
value = int(part)
key.append((value, -len(part)))
else: # text
key.append(part)
return key
def human_sort(strings):
return sorted(strings, key=natural_key)
```
I prefer actually sorting leading zeros as text, so my regexp would be [1-9][0-9]*
But of course in this context the sorting of RFC0020 vs. RFC20 may argue for going with the bot’s solution.
Grüße, Carsten
|
Member
Author
|
Closing this in favour of #1321 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1318