Hello,

On 2019-10-08 12:36 a.m., Peng Yu wrote:
The following example shows that version sort is not natural sort. Is
natural sort supported in by `sort`?

There is no such thing as "THE correct natural sort" order...

$ printf '%s\n' 1G13 1.02 | LC_ALL=C sort -k 1,1V # The result order
should have been reversed.

... therefore "should have" is simply incorrect expectation.

You might think it "should" be one way, and other implementations
think it "should" be another way.

For more details, please see the attached HTML file for details.

(this HTML file is a new chapter of the coreutils manual that will be
included in the next release. The source texinfo is here:
https://git.savannah.gnu.org/cgit/coreutils.git/tree/doc/sort-version.texi ).

regards,
 - assaf

   #[1]Version sort ordering


1 Version sort ordering

   • [2]Version sort overview:
   • [3]Implementation Details:
   • [4]Differences from the official Debian Algorithm:
   • [5]Advanced Topics:
     __________________________________________________________________

   Next: [6]Implementation Details, Up: [7]Version sort ordering

  1.1 Version sort overview

   version sort ordering (and similarly, natural sort ordering) is a
   method to sort items such as file names and lines of text in an order
   that feels more natural to people, when the text contains a mixture of
   letters and digits.

   Standard sorting usually does not produce the order that one expects
   because comparisons are made on a character-by-character basis.

   Compare the sorting of the following items:

Alphabetical sort:           Version Sort:

a1                           a1
a120                         a2
a13                          a13
a2                           a120

   version sort functionality in GNU coreutils is available in the ‘ls
   -v’, ‘ls --sort=version’, ‘sort -V’, ‘sort --version-sort’ commands.

   • [8]Using version sort in GNU coreutils:
   • [9]Origin of version sort and differences from natural sort:
   • [10]Correct/Incorrect ordering and Expected/Unexpected results:
     __________________________________________________________________

   Next: [11]Origin of version sort and differences from natural sort, Up:
   [12]Version sort overview

    1.1.1 Using version sort in GNU coreutils

   Two GNU coreutils programs use version sort: ls and sort.

   To list files in version sort order, use ls with -v or --sort=version
   options:

default sort:              version sort:

$ ls -1                    $ ls -1 -v
a1                         a1
a100                       a1.4
a1.13                      a1.13
a1.4                       a1.40
a1.40                      a2
a2                         a100

   To sort text files in version sort order, use sort with the -V option:

$ cat input
b3
b11
b1
b20


alphabetical order:        version sort order:

$ sort input               $ sort -V input
b1                         b1
b11                        b3
b20                        b11
b3                         b20

   To sort a specific column in a file use -k/--key with ‘V’ ordering
   option:

$ cat input2
1000  b3   apples
2000  b11  oranges
3000  b1   potatoes
4000  b20  bananas

$ sort -k2V,2 input2
3000  b1   potatoes
1000  b3   apples
2000  b11  oranges
4000  b20  bananas
     __________________________________________________________________

   Next: [13]Correct/Incorrect ordering and Expected/Unexpected results,
   Previous: [14]Using version sort in GNU coreutils, Up: [15]Version sort
   overview

    1.1.2 Origin of version sort and differences from natural sort

   In GNU coreutils, the name version sort was chosen because it is based
   on Debian GNU/Linux’s algorithm of sorting packages’ versions.

   Its goal is to answer the question “which package is newer,
   firefox-60.7.2 or firefox-60.12.3 ?”

   In coreutils this algorithm was slightly modified to work on more
   general input such as textual strings and file names (see
   [16]Differences from the official Debian Algorithm).

   In other contexts, such as other programs and other programming
   languages, a similar sorting functionality is called [17]natural sort.
     __________________________________________________________________

   Previous: [18]Origin of version sort and differences from natural sort,
   Up: [19]Version sort overview

    1.1.3 Correct/Incorrect ordering and Expected/Unexpected results

   Currently there is no standard for version/natural sort ordering.

   That is: there is no one correct way or universally agreed-upon way to
   order items. Each program and each programming language can decide its
   own ordering algorithm and call it ’natural sort’ (or other various
   names).

   See [20]Other version/natural sort implementations for many examples of
   differing sorting possibilities, each with its own rules and
   variations.

   If you do suspect a bug in coreutils’ implementation of version-sort,
   see [21]Reporting bugs or incorrect results on how to report them.
     __________________________________________________________________

   Next: [22]Differences from the official Debian Algorithm, Previous:
   [23]Version sort overview, Up: [24]Version sort ordering

  1.2 Implementation Details

   GNU coreutils’ version sort algorithm is based on [25]Debian’s
   versioning scheme, specifically on the "upstream version" part.

   This section describes the ordering rules.

   The next section ([26]Differences from the official Debian Algorithm)
   describes some differences between GNU coreutils implementation and
   Debian’s official algorithm.

   • [27]Version-sort ordering rules:
   • [28]Version sort is not the same as numeric sort:
   • [29]Punctuation Characters:
   • [30]Punctuation Characters vs letters:
   • [31]Tilde ‘~’ character:
   • [32]Version sort ignores locale:
     __________________________________________________________________

   Next: [33]Version sort is not the same as numeric sort, Up:
   [34]Implementation Details

    1.2.1 Version-sort ordering rules

   The version sort ordering rules are:
    1. The strings are compared from left to right.
    2. First the initial part of each string consisting entirely of
       non-digit characters is determined.
         1. These two parts (one of which may be empty) are compared
            lexically. If a difference is found it is returned.
         2. The lexical comparison is a comparison of ASCII values
            modified so that:
              1. all the letters sort earlier than all the non-letters and
              2. so that a tilde sorts before anything, even the end of a
                 part.
    3. Then the initial part of the remainder of each string which
       consists entirely of digit characters is determined. The numerical
       values of these two parts are compared, and any difference found is
       returned as the result of the comparison.
         1. For these purposes an empty string (which can only occur at
            the end of one or both version strings being compared) counts
            as zero.
    4. These two steps (comparing and removing initial non-digit strings
       and initial digit strings) are repeated until a difference is found
       or both strings are exhausted.

   Consider the version-sort comparison of two file names: foo07.7z and
   foo7a.7z. The two strings will be broken down to the following parts,
   and the parts compared respectively from each string:

foo  vs  foo   (rule 2, non-digits characters)
07   vs  7     (rule 3, digits characters)
.    vs  a.    (rule 2)
7    vs  7     (rule 3)
z    vs  z     (rule 2)

   Comparison flow based on above algorithm:
    1. The first parts (foo) are identical in both strings.
    2. The second parts (07 and 7) are compared numerically, and are
       identical.
    3. The third parts (‘.’ vs ‘a.’) are compared lexically by ASCII value
       (rule 2.2).
    4. The first character of the first string (‘.’) is compared to the
       first character of the second string (‘a’).
    5. Rule 2.2.1 dictates that "all letters sorts earlier than all
       non-letters". Hence, ‘a’ comes before ‘.’.
    6. The returned result is that foo7a.7z comes before foo07.7z.

   Result when using sort:

$ cat input3
foo07.7z
foo7a.7z

$ sort -V input3
foo7a.7z
foo07.7z

   See [35]Differences from the official Debian Algorithm for additional
   rules that extend the Debian algorithm in coreutils.
     __________________________________________________________________

   Next: [36]Punctuation Characters, Previous: [37]Version-sort ordering
   rules, Up: [38]Implementation Details

    1.2.2 Version sort is not the same as numeric sort

   Consider the following text file:

$ cat input4
8.10
8.5
8.1
8.01
8.010
8.100
8.49



Numerical Sort:                   Version Sort:

$ sort -n input4                  $ sort -V input4
8.01                              8.01
8.010                             8.1
8.1                               8.5
8.10                              8.010
8.100                             8.10
8.49                              8.49
8.5                               8.100

   Numeric sort (‘sort -n’) treats the entire string as a single numeric
   value, and compares it to other values. For example, 8.1, 8.10 and
   8.100 are numerically equivalent, and are ordered together. Similarly,
   8.49 is numerically smaller than 8.5, and appears before first.

   Version sort (‘sort -V’) first breaks down the string into digits and
   non-digits parts, and only then compares each part (see annotated
   example in Version-sort ordering rules).

   Comparing the string 8.1 to 8.01, first the ‘8’ characters are compared
   (and are identical), then the dots (‘.’) are compared and are
   identical, and lastly the remaining digits are compared numerically (1
   and 01) - which are numerically equivalent. Hence, 8.01 and 8.1 are
   grouped together.

   Similarly, comparing 8.5 to 8.49 - the ‘8’ and ‘.’ parts are identical,
   then the numeric values 5 and 49 are compared. The resulting 5 appears
   before 49.

   This sorting order (where 8.5 comes before 8.49) is common when
   assigning versions to computer programs (while perhaps not intuitive or
   ’natural’ for people).
     __________________________________________________________________

   Next: [39]Punctuation Characters vs letters, Previous: [40]Version sort
   is not the same as numeric sort, Up: [41]Implementation Details

    1.2.3 Punctuation Characters

   Punctuation characters are sorted by ASCII order (rule 2.2).

$ touch    1.0.5_src.tar.gz    1.0_src.tar.gz

$ ls -v -1
1.0.5_src.tar.gz
1.0_src.tar.gz

   Why is 1.0.5_src.tar.gz listed before 1.0_src.tar.gz ?

   Based on the [42]algorithm above, the strings are broken down into the
   following parts:

          1   vs  1               (rule 3, all digit characters)
          .   vs  .               (rule 2, all non-digit characters)
          0   vs  0               (rule 3)
          .   vs  _src.tar.gz     (rule 2)
          5   vs  empty string    (no more character in the file name)
_src.tar.gz   vs  empty string

   The fourth parts (‘.’ and _src.tar.gz) are compared lexically by ASCII
   order. The character ‘.’ (ASCII value 46) is smaller than ‘_’ (ASCII
   value 95) - and should be listed before it.

   Hence, 1.0.5_src.tar.gz is listed first.

   If a different character appears instead of the underscore (for
   example, percent sign ‘%’ ASCII value 37, which is smaller than dot’s
   ASCII value of 46), that file will be listed first:

$ touch   1.0.5_src.tar.gz     1.0%zzzzz.gz
1.0%zzzzz.gz
1.0.5_src.tar.gz

   The same reasoning applies to the following example: The character ‘.’
   has ASCII value 46, and is smaller than slash character ‘/’ ASCII value
   47:

$ cat input5
3.0/
3.0.5

$ sort -V input5
3.0.5
3.0/
     __________________________________________________________________

   Next: [43]Tilde ‘~’ character, Previous: [44]Punctuation Characters,
   Up: [45]Implementation Details

    1.2.4 Punctuation Characters vs letters

   Rule 2.2.1 dictates that letters sorts earlier than all non-letters
   (after breaking down a string to digits and non-digits parts).

$ cat input6
a%
az

$ sort -V input6
az
a%

   The input strings consist entirely of non-digits, and based on the
   above algorithm have only one part, all non-digit characters (‘a%’ vs
   ‘az’).

   Each part is then compared lexically, character-by-character. ‘a’
   compares identically in both strings.

   Rule 2.2.1 dictates that letters (‘z’) sorts earlier than all
   non-letters (‘%’) - hence ‘az’ appears first (despite ‘z’ having ASCII
   value of 122, much bigger than ‘%’ with ASCII value 37).
     __________________________________________________________________

   Next: [46]Version sort ignores locale, Previous: [47]Punctuation
   Characters vs letters, Up: [48]Implementation Details

    1.2.5 Tilde ‘~’ character

   Rule 2.2.2 dictates that tilde character ‘~’ (ASCII 126) sorts before
   all other non-digit characters, including an empty part.

$ cat input7
1
1%
1.2
1~
~

$ sort -V input7
~
1~
1
1%
1.2

   The sorting algorithm starts by breaking down the string into
   non-digits (rule 2) and digits parts (rule 3).

   In the above input file, only the last line in the input file starts
   with a non-digit (‘~’). This is the first part. All other lines in the
   input file start with a digit - their first non-digit part is empty.

   Based on rule 2.2.2, tilde ‘~’ sorts before all other non-digits
   including the empty part - hence it comes before all other strings, and
   is listed first in the sorted output.

   The remaining lines (1, 1%, 1.2, 1~) follow similar logic: The digit
   part is extracted (1 for all strings) and compares identical. The
   following extracted parts for the remaining input lines are: empty
   part, %, ., ~.

   Tilde sorts before all others, hence the line 1~ appears next.

   The remaining lines (1, 1%, 1.2) are sorted based on previously
   explained rules.
     __________________________________________________________________

   Previous: [49]Tilde ‘~’ character, Up: [50]Implementation Details

    1.2.6 Version sort uses ASCII order, ignores locale, unicode characters

   In version sort, unicode characters are compared byte-by-byte according
   to their binary representation, ignoring their unicode value or the
   current locale.

   Most commonly, unicode characters (e.g. Greek Small Letter Alpha U+03B1
   ‘α’) are encoded as UTF-8 bytes (e.g. ‘α’ is encoded as UTF-8
   sequence 0xCE 0xB1). The encoding will be compared byte-by-byte, e.g.
   first 0xCE (decimal value 206) then 0xB1 (decimal value 177).

$ touch   aa    az    "a%"    "aα"

$ ls -1 -v
aa
az
a%
aα

   Ignoring the first letter (a) which is identical in all strings, the
   compared values are:

   ‘a’ and ‘z’ are letters, and sort earlier than all other non-digit
   characters.

   Then, percent sign ‘%’ (ASCII value 37) is compared to the first byte
   of the UTF-8 sequence of ‘α’, which is 0xCE or 206). The value 37 is
   smaller, hence ‘a%’ is listed before ‘aα’.
     __________________________________________________________________

   Next: [51]Advanced Topics, Previous: [52]Implementation Details, Up:
   [53]Version sort ordering

  1.3 Differences from the official Debian Algorithm

   The GNU coreutils’ version sort algorithm differs slightly from the
   official Debian algorithm, in order to accommodate more general usage
   and file name listing.

   • [54]Minus/Hyphen ‘-’ and Colon ‘:’ characters:
   • [55]Additional hard-coded priorities in GNU coreutils' version sort:

   • [56]Special handling of file extensions:
     __________________________________________________________________

   Next: [57]Additional hard-coded priorities in GNU coreutils' version
   sort, Up: [58]Differences from the official Debian Algorithm

    1.3.1 Minus/Hyphen ‘-’ and Colon ‘:’ characters

   In Debian’s version string syntax the version consists of three parts:

[epoch:]upstream_version[-debian_revision]

   The epoch and debian_revision parts are optional.

   Example of such version strings:

60.7.2esr-1~deb9u1
52.9.0esr-1~deb9u1
1:2.3.4-1+b2
327-2
1:1.0.13-3
2:1.19.2-1+deb9u5

   If the debian_revision part is not present, hyphen characters ‘-’ are
   not allowed. If epoch is not present, colons ‘:’ are not allowed.

   If these parts are present, hyphen and/or colons can appear only once
   in valid Debian version strings.

   In GNU coreutils, such restrictions are not reasonable (a file name can
   have many hyphens, a line of text can have many colons).

   As a result, in GNU coreutils hyphens and colons are treated exactly
   like all other punctuation characters (i.e., they are sorted after
   letters. See Punctuation Characters above).

   In Debian, these characters are treated differently than in coreutils:
   a version string with hyphen will sort before similar strings without
   hyphens.

   Compare:

$ touch   abb   ab-cd

$ ls -v -1
abb
ab-cd

   With Debian’s dpkg they will be listed as ab-cd first and abb second.

   For further technical details see [59]bug35939.
     __________________________________________________________________

   Next: [60]Special handling of file extensions, Previous:
   [61]Minus/Hyphen ‘-’ and Colon ‘:’ characters, Up: [62]Differences from
   the official Debian Algorithm

    1.3.2 Additional hard-coded priorities in GNU coreutils’ version sort

   In GNU coreutils’ version sort algorithm, the following items have
   special priority and sort earlier than all other characters (listed in
   order);
    1. The empty string
    2. The string ‘.’ (a single dot character, ASCII 46)
    3. The string ‘..’ (two dot characters)
    4. Strings start with a dot (‘.’) sort earlier than strings starting
       with any other characters.

   Example:

$ printf "%s\n" a "" b "." c  ".."  ".d20" ".d3"  | sort -V

.
..
.d3
.d20
a
b
c

   These priorities make perfect sense for ‘ls -v’: The special files dot
   ‘.’ and dot-dot ‘..’ will be listed first, followed by any hidden files
   (files starting with a dot), followed by non-hidden files.

   For ‘sort -V’ these priorities might seem arbitrary. However, because
   the sorting code is shared between the ls and sort program, the
   ordering rules are the same.
     __________________________________________________________________

   Previous: [63]Additional hard-coded priorities in GNU coreutils'
   version sort, Up: [64]Differences from the official Debian Algorithm

    1.3.3 Special handling of file extensions

   GNU coreutils’ version sort algorithm implements specialized handling
   of file extensions (or strings that look like file names with
   extensions).

   This nuanced implementation enables slightly more natural ordering of
   files.

   The additional rules are:
    1. A suffix (i.e., a file extension) is defined as: a dot, followed by
       a letter or tilde, followed by one or more letters, digits, or
       tildes (possibly repeated more than once), until the end of the
       string (technically, matching the regular expression
       (\.[A-Za-z~][A-Za-z0-9~]*)*).
    2. If the strings contains suffixes, the suffixes are temporarily
       removed, and the strings are compared without them (using the
       [65]algorithm above).
    3. If the suffix-less strings are identical, the suffix is restored
       and the entire strings are compared.
    4. If the non-suffixed strings differ, the result is returned and the
       suffix is effectively ignored.

   Examples for rule 1:
     * hello-8.txt: the suffix is .txt
     * hello-8.2.txt: the suffix is .txt (‘.2’ is not included because the
       dot is not followed by a letter)
     * hello-8.0.12.tar.gz: the suffix is .tar.gz (‘.0.12’ is not
       included)
     * hello-8.2: no suffix (suffix is an empty string)
     * hello.foobar65: the suffix is .foobar65
     * gcc-c++-10.8.12-0.7rc2.fc9.tar.bz2: the suffix is .fc9.tar.bz2
       (.7rc2 is not included as it begins with a digit)

   Examples for rule 2:
     * Comparing hello-8.txt to hello-8.2.12.txt, the .txt suffix is
       temporarily removed from both strings.
     * Comparing foo-10.3.tar.gz to foo-10.tar.xz, the suffixes .tar.gz
       and .tar.xz are temporarily removed from the strings.

   Example for rule 3:
     * Comparing hello.foobar65 to hello.foobar4, the suffixes (.foobar65
       and .foobar4) are temporarily removed. The remaining strings are
       identical (hello). The suffixes are then restored, and the entire
       strings are compared (hello.foobar4 comes first).

   Examples for rule 4:
     * When comparing the strings hello-8.2.txt and hello-8.10.txt, the
       suffixes (.txt) are temporarily removed. The remaining strings
       (hello-8.2 and hello-8.10) are compared as previously described
       (hello-8.2 comes first). (In this case the suffix removal algorithm
       does not have a noticeable effect on the resulting order.)

   How does the suffix-removal algorithm effect ordering results?

   Consider the comparison of hello-8.txt and hello-8.2.txt.

   Without the suffix-removal algorithm, the strings will be broken down
   to the following parts:

hello-  vs  hello-  (rule 2, all non-digit characters)
8       vs  8       (rule 3, all digit characters)
.txt    vs  .       (rule 2)
empty   vs  2
empty   vs  .txt

   The comparison of the third parts (‘.’ vs ‘.txt’) will determine that
   the shorter string comes first - resulting in hello-8.2.txt appearing
   first.

   Indeed this is the order in which Debian’s dpkg compares the strings.

   A more natural result is that hello-8.txt should come before
   hello-8.2.txt, and this is where the suffix-removal comes into play:

   The suffixes (.txt) are removed, and the remaining strings are broken
   down into the following parts:

hello-  vs  hello-  (rule 2, all non-digit characters)
8       vs  8       (rule 3, all digit characters)
empty   vs  .       (rule 2)
empty   vs  2

   As empty strings sort before non-empty strings, the result is hello-8
   being first.

   A real-world example would be listing files such as: gcc_10.fc9.tar.gz
   and gcc_10.8.12.7rc2.fc9.tar.bz2: Debian’s algorithm would list
   gcc_10.8.12.7rc2.fc9.tar.bz2 first, while ‘ls -v’ will list
   gcc_10.fc9.tar.gz first.

   These priorities make sense for ‘ls -v’: Versioned files will be listed
   in a more natural order.

   For ‘sort -V’ these priorities might seem arbitrary. However, because
   the sorting code is shared between the ls and sort program, the
   ordering rules are the same.
     __________________________________________________________________

   Previous: [66]Differences from the official Debian Algorithm, Up:
   [67]Version sort ordering

  1.4 Advanced Topics

   • [68]Comparing two strings using Debian's algorithm:
   • [69]Reporting bugs or incorrect results:
   • [70]Other version/natural sort implementations:
   • [71]Related Source code:
     __________________________________________________________________

   Next: [72]Reporting bugs or incorrect results, Up: [73]Advanced Topics

    1.4.1 Comparing two strings using Debian’s algorithm

   The Debian program dpkg (available on all Debian and Ubuntu
   installations) can compare two strings using the --compare-versions
   option.

   To use it, create a helper shell function (simply copy & paste the
   following snippet to your shell command-prompt):

compver() {
  dpkg --compare-versions "$1" lt "$2" \
    && printf "%s\n" "$1" "$2" \
    || printf "%s\n" "$2" "$1" ; \
}

   Then compare two strings by calling compver:

$ compver 8.49 8.5
8.5
8.49

   Note that dpkg will warn if the strings have invalid syntax:

$ compver "foo07.7z" "foo7a.7z"
dpkg: warning: version 'foo07.7z' has bad syntax:
               version number does not start with digit
dpkg: warning: version 'foo7a.7z' has bad syntax:
               version number does not start with digit
foo7a.7z
foo07.7z

$ compver "3.0/" "3.0.5"
dpkg: warning: version '3.0/' has bad syntax:
               invalid character in version number
3.0.5
3.0/

   To illustrate the different handling of hyphens between Debian and
   coreutils’ algorithms (see [74]Minus/Hyphen ‘-’ and Colon ‘:’
   characters):

$ compver abb ab-cd 2>/dev/null     $ printf "abb\nab-cd\n" | sort -V
ab-cd                               abb
abb                                 ab-cd

   To illustrate the different handling of file extension: (see
   [75]Special handling of file extensions):

$ compver hello-8.txt hello-8.2.txt 2>/dev/null
hello-8.2.txt
hello-8.txt

$ printf "%s\n" hello-8.txt hello-8.2.txt | sort -V
hello-8.txt
hello-8.2.txt
     __________________________________________________________________

   Next: [76]Other version/natural sort implementations, Previous:
   [77]Comparing two strings using Debian's algorithm, Up: [78]Advanced
   Topics

    1.4.2 Reporting bugs or incorrect results

   If you suspect a bug in GNU coreutils’ version sort (i.e., in the
   output of ‘ls -v’ or ‘sort -V’), please first check the following:
    1. Is the result consistent with Debian’s own ordering (using dpkg,
       see [79]Comparing two strings using Debian's algorithm) ? If it is,
       then this is not a bug - please do not report it.
    2. If the result differs from Debian’s, is it explained by one of the
       sections in [80]Differences from the official Debian Algorithm? If
       it is, then this is not a bug - please do not report it.
    3. If you have a question about specific ordering which is not
       explained here, please write to [81]coreutils@gnu.org, and provide
       a concise example that will help us diagnose the issue.
    4. If you still suspect a bug which is not explained by the above,
       please write to [82]bug-coreut...@gnu.org with a concrete example
       of the suspected incorrect output, with details on why you think it
       is incorrect.
     __________________________________________________________________

   Next: [83]Related Source code, Previous: [84]Reporting bugs or
   incorrect results, Up: [85]Advanced Topics

    1.4.3 Other version/natural sort implementations

   As previously mentioned, there are multiple variations on
   version/natural sort, each with its own rules. Some examples are:
     * Natural Sorting variants in [86]Rosetta Code.
     * Python’s [87]natsort package (includes detailed description of
       their sorting rules: [88]natsort - how it works).
     * Ruby’s [89]version_sorter.
     * Perl has multiple packages for natual and version sorts (each
       likely with its own rules and nuances): [90]Sort::Naturally,
       [91]Sort::Versions, [92]CPAN::Version.
     * PHP has a built-in function [93]natsort.
     * NodeJS’s [94]natural-sort package.
     * In zsh, the [95]glob modifier *(n) will expand to files in natural
       sort order.
     * When writing C programs, the GNU libc library (glibc) provides the
       [96]strvercmp(3) function to compare two strings, and
       [97]versionsort(3) function to compare two directory entries
       (despite the names, they are not identical to GNU coreutils’
       version sort ordering).
     * Using Debian’s sorting algorithm in:
          + python: [98]Stack Overflow Example #4957741.
          + NodeJS: [99]deb-version-compare.
     __________________________________________________________________

   Previous: [100]Other version/natural sort implementations, Up:
   [101]Advanced Topics

    1.4.4 Related Source code

     * Debian’s code which splits a version string into
       epoch/upstream_version/debian_revision parts:
       [102]parsehelp.c:parseversion().
     * Debian’s code which performs the upstream_version comparison:
       [103]version.c.
     * GNULIB code (used by GNU coreutils) which performs the version
       comparison: [104]filevercmp.c.
     __________________________________________________________________

References

   1. file:///tmp/tmpGWpjWH.html#Version-sort-ordering
   2. file:///tmp/tmpGWpjWH.html#Version-sort-overview
   3. file:///tmp/tmpGWpjWH.html#Implementation-Details
   4. file:///tmp/tmpGWpjWH.html#Differences-from-the-official-Debian-Algorithm
   5. file:///tmp/tmpGWpjWH.html#Advanced-Topics
   6. file:///tmp/tmpGWpjWH.html#Implementation-Details
   7. file:///tmp/tmpGWpjWH.html#Version-sort-ordering
   8. file:///tmp/tmpGWpjWH.html#Using-version-sort-in-GNU-coreutils
   9. 
file:///tmp/tmpGWpjWH.html#Origin-of-version-sort-and-differences-from-natural-sort
  10. 
file:///tmp/tmpGWpjWH.html#Correct_002fIncorrect-ordering-and-Expected_002fUnexpected-results
  11. 
file:///tmp/tmpGWpjWH.html#Origin-of-version-sort-and-differences-from-natural-sort
  12. file:///tmp/tmpGWpjWH.html#Version-sort-overview
  13. 
file:///tmp/tmpGWpjWH.html#Correct_002fIncorrect-ordering-and-Expected_002fUnexpected-results
  14. file:///tmp/tmpGWpjWH.html#Using-version-sort-in-GNU-coreutils
  15. file:///tmp/tmpGWpjWH.html#Version-sort-overview
  16. file:///tmp/tmpGWpjWH.html#Differences-from-the-official-Debian-Algorithm
  17. https://en.wikipedia.org/wiki/Natural_sort_order
  18. 
file:///tmp/tmpGWpjWH.html#Origin-of-version-sort-and-differences-from-natural-sort
  19. file:///tmp/tmpGWpjWH.html#Version-sort-overview
  20. file:///tmp/tmpGWpjWH.html#Other-version_002fnatural-sort-implementations
  21. file:///tmp/tmpGWpjWH.html#Reporting-bugs-or-incorrect-results
  22. file:///tmp/tmpGWpjWH.html#Differences-from-the-official-Debian-Algorithm
  23. file:///tmp/tmpGWpjWH.html#Version-sort-overview
  24. file:///tmp/tmpGWpjWH.html#Version-sort-ordering
  25. https://www.debian.org/doc/debian-policy/ch-controlfields.html#version
  26. file:///tmp/tmpGWpjWH.html#Differences-from-the-official-Debian-Algorithm
  27. file:///tmp/tmpGWpjWH.html#Version_002dsort-ordering-rules
  28. file:///tmp/tmpGWpjWH.html#Version-sort-is-not-the-same-as-numeric-sort
  29. file:///tmp/tmpGWpjWH.html#Punctuation-Characters
  30. file:///tmp/tmpGWpjWH.html#Punctuation-Characters-vs-letters
  31. file:///tmp/tmpGWpjWH.html#Tilde-_007e-character
  32. file:///tmp/tmpGWpjWH.html#Version-sort-ignores-locale
  33. file:///tmp/tmpGWpjWH.html#Version-sort-is-not-the-same-as-numeric-sort
  34. file:///tmp/tmpGWpjWH.html#Implementation-Details
  35. file:///tmp/tmpGWpjWH.html#Differences-from-the-official-Debian-Algorithm
  36. file:///tmp/tmpGWpjWH.html#Punctuation-Characters
  37. file:///tmp/tmpGWpjWH.html#Version_002dsort-ordering-rules
  38. file:///tmp/tmpGWpjWH.html#Implementation-Details
  39. file:///tmp/tmpGWpjWH.html#Punctuation-Characters-vs-letters
  40. file:///tmp/tmpGWpjWH.html#Version-sort-is-not-the-same-as-numeric-sort
  41. file:///tmp/tmpGWpjWH.html#Implementation-Details
  42. file:///tmp/tmpGWpjWH.html#Version_002dsort-ordering-rules
  43. file:///tmp/tmpGWpjWH.html#Tilde-_007e-character
  44. file:///tmp/tmpGWpjWH.html#Punctuation-Characters
  45. file:///tmp/tmpGWpjWH.html#Implementation-Details
  46. file:///tmp/tmpGWpjWH.html#Version-sort-ignores-locale
  47. file:///tmp/tmpGWpjWH.html#Punctuation-Characters-vs-letters
  48. file:///tmp/tmpGWpjWH.html#Implementation-Details
  49. file:///tmp/tmpGWpjWH.html#Tilde-_007e-character
  50. file:///tmp/tmpGWpjWH.html#Implementation-Details
  51. file:///tmp/tmpGWpjWH.html#Advanced-Topics
  52. file:///tmp/tmpGWpjWH.html#Implementation-Details
  53. file:///tmp/tmpGWpjWH.html#Version-sort-ordering
  54. 
file:///tmp/tmpGWpjWH.html#Minus_002fHyphen-_002d-and-Colon-_003a-characters
  55. 
file:///tmp/tmpGWpjWH.html#Additional-hard_002dcoded-priorities-in-GNU-coreutils_0027-version-sort
  56. file:///tmp/tmpGWpjWH.html#Special-handling-of-file-extensions
  57. 
file:///tmp/tmpGWpjWH.html#Additional-hard_002dcoded-priorities-in-GNU-coreutils_0027-version-sort
  58. file:///tmp/tmpGWpjWH.html#Differences-from-the-official-Debian-Algorithm
  59. https://bugs.gnu.org/35939
  60. file:///tmp/tmpGWpjWH.html#Special-handling-of-file-extensions
  61. 
file:///tmp/tmpGWpjWH.html#Minus_002fHyphen-_002d-and-Colon-_003a-characters
  62. file:///tmp/tmpGWpjWH.html#Differences-from-the-official-Debian-Algorithm
  63. 
file:///tmp/tmpGWpjWH.html#Additional-hard_002dcoded-priorities-in-GNU-coreutils_0027-version-sort
  64. file:///tmp/tmpGWpjWH.html#Differences-from-the-official-Debian-Algorithm
  65. file:///tmp/tmpGWpjWH.html#Version_002dsort-ordering-rules
  66. file:///tmp/tmpGWpjWH.html#Differences-from-the-official-Debian-Algorithm
  67. file:///tmp/tmpGWpjWH.html#Version-sort-ordering
  68. 
file:///tmp/tmpGWpjWH.html#Comparing-two-strings-using-Debian_0027s-algorithm
  69. file:///tmp/tmpGWpjWH.html#Reporting-bugs-or-incorrect-results
  70. file:///tmp/tmpGWpjWH.html#Other-version_002fnatural-sort-implementations
  71. file:///tmp/tmpGWpjWH.html#Related-Source-code
  72. file:///tmp/tmpGWpjWH.html#Reporting-bugs-or-incorrect-results
  73. file:///tmp/tmpGWpjWH.html#Advanced-Topics
  74. 
file:///tmp/tmpGWpjWH.html#Minus_002fHyphen-_002d-and-Colon-_003a-characters
  75. file:///tmp/tmpGWpjWH.html#Special-handling-of-file-extensions
  76. file:///tmp/tmpGWpjWH.html#Other-version_002fnatural-sort-implementations
  77. 
file:///tmp/tmpGWpjWH.html#Comparing-two-strings-using-Debian_0027s-algorithm
  78. file:///tmp/tmpGWpjWH.html#Advanced-Topics
  79. 
file:///tmp/tmpGWpjWH.html#Comparing-two-strings-using-Debian_0027s-algorithm
  80. file:///tmp/tmpGWpjWH.html#Differences-from-the-official-Debian-Algorithm
  81. mailto:coreutils@gnu.org
  82. mailto:bug-coreut...@gnu.org
  83. file:///tmp/tmpGWpjWH.html#Related-Source-code
  84. file:///tmp/tmpGWpjWH.html#Reporting-bugs-or-incorrect-results
  85. file:///tmp/tmpGWpjWH.html#Advanced-Topics
  86. https://rosettacode.org/wiki/Natural_sorting
  87. https://pypi.org/project/natsort/
  88. https://natsort.readthedocs.io/en/master/howitworks.html
  89. https://github.com/github/version_sorter
  90. https://metacpan.org/pod/Sort::Naturally
  91. https://metacpan.org/pod/Sort::Versions
  92. https://metacpan.org/pod/CPAN::Version
  93. https://www.php.net/manual/en/function.natsort.php
  94. https://www.npmjs.com/package/natural-sort
  95. http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Qualifiers
  96. http://man7.org/linux/man-pages/man3/strverscmp.3.html
  97. http://man7.org/linux/man-pages/man3/versionsort.3.html
  98. https://stackoverflow.com/a/4957741
  99. https://www.npmjs.com/package/deb-version-compare
 100. file:///tmp/tmpGWpjWH.html#Other-version_002fnatural-sort-implementations
 101. file:///tmp/tmpGWpjWH.html#Advanced-Topics
 102. https://git.dpkg.org/cgit/dpkg/dpkg.git/tree/lib/dpkg/parsehelp.c#n191
 103. https://git.dpkg.org/cgit/dpkg/dpkg.git/tree/lib/dpkg/version.c#n140
 104. https://git.savannah.gnu.org/cgit/gnulib.git/tree/lib/filevercmp.c

Reply via email to