Natural sorting: Difference between revisions

Content added Content deleted
m (→‎{{header|AppleScript}}: Typo correction.)
m (added whitespace so that the "sample input" in the task's preamble displays at full width.)
Line 6: Line 6:
order of individual characters codes to make the finding of
order of individual characters codes to make the finding of
individual strings easier for a ''human'' reader.
individual strings easier for a ''human'' reader.



There is no "one true way" to do this, but for the purpose of this task 'natural' orderings might include:
There is no "one true way" to do this, but for the purpose of this task 'natural' orderings might include:
Line 11: Line 12:
:2. Make all whitespace characters equivalent.
:2. Make all whitespace characters equivalent.
:3. Sorting without regard to case.
:3. Sorting without regard to case.
:4. Sorting numeric portions of strings in numeric order. That is split the string into fields on numeric boundaries, then sort on each field, with the rightmost fields being the most significant, and numeric fields of integers treated as numbers.
:4. Sorting numeric portions of strings in numeric order.
:: That is split the string into fields on numeric boundaries, then sort on each field, with the rightmost fields being the most significant, and numeric fields of integers treated as numbers.
:: foo9.txt before foo10.txt
:: foo9.txt before foo10.txt
:: As well as ... x9y99 before x9y100, before x10y0
:: As well as ... x9y99 before x9y100, before x10y0
Line 24: Line 26:
:: Sort ʒ, LATIN SMALL LETTER EZH as s
:: Sort ʒ, LATIN SMALL LETTER EZH as s
:: ...
:: ...



;Task Description
;Task Description
Line 31: Line 34:


* '''For extra credit''' implement more than the first four.
* '''For extra credit''' implement more than the first four.


Note: It is not necessary to have individual control of which features are active in the natural sorting routine at any time.
Note: It is not necessary to have individual control of which features are active in the natural sorting routine at any time.



;Sample input:
;Sample input: