Jump to content

Natural sorting: Difference between revisions

corrected some misspellings, added whitespace, changed horizontal lists to vertical list so as to not have a scroll bar for the sample inputs, aligned sample input text strings, insured that the sample inputs fit on one screen page..
m (added whitespace so that the "sample input" in the task's preamble displays at full width.)
(corrected some misspellings, added whitespace, changed horizontal lists to vertical list so as to not have a scroll bar for the sample inputs, aligned sample input text strings, insured that the sample inputs fit on one screen page..)
Line 1:
{{task|Sorting Algorithms}}
[[Category:Sorting]]
{{Sorting Algorithm}}
 
{{task|Sorting Algorithms}}
Natural sorting is the sorting of text that does more than rely on the
order of individual characters codes to make the finding of
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:
Line 22 ⟶ 21:
:7. Sort ligatures as separate letters.
:8. Replacements:
:: Sort germanGerman scharfes S (ß) as ss
:: Sort ſ, LATIN SMALL LETTER LONG S as s
:: Sort ʒ, LATIN SMALL LETTER EZH as s
:: <big><big> ∙∙∙ </big></big>
:: ...
 
 
;Task Description
Line 32 ⟶ 30:
* Test each feature implemented separately with an ordered list of test strings from the 'Sample inputs' section below, and make sure your naturally sorted output is in the same order as other language outputs such as Python.
* Print and display your output.
 
* '''For extra credit''' implement more than the first four.
 
Note: It&nbsp; it is not necessary to have individual control of which features are active in the natural sorting routine at any time.
 
 
;Sample input:
 
<pre>
# Ignoring leading spaces. Text strings: ['ignore leading spaces: 2-2',
'ignore leading spaces: 2-1',
Text strings:
['ignore leading spaces: 2-2', ' ignore leading spaces: 2-1', ' ignore leading spaces: 2+0', ' 'ignore leading spaces: 2+10'],
'ignore leading spaces: 2+1']
 
# Ignoring multiple adjacent spaces (m.a.s)
Text strings:
['ignore m.a.s spaces: 2-2', 'ignore m.a.s spaces: 2-1', 'ignore m.a.s spaces: 2+0', 'ignore m.a.s spaces: 2+1']
 
 
# Equivalent whitespace characters
Text strings:
['Equiv. spaces: 3-3', 'Equiv.\rspaces: 3-2', 'Equiv.\x0cspaces: 3-1', 'Equiv.\x0bspaces: 3+0', 'Equiv.\nspaces: 3+1', 'Equiv.\tspaces: 3+2']
 
# Ignoring multiple adjacent spaces (m.a.s). Text strings: ['ignore m.a.s spaces: 2-2',
# Case Indepenent sort
'ignore m.a.s spaces: 2-1',
Text strings:
'ignore m.a.s spaces: 2+0',
['cASE INDEPENENT: 3-2', 'caSE INDEPENENT: 3-1', 'casE INDEPENENT: 3+0', 'case INDEPENENT: 3+1']
'ignore m.a.s spaces: 2+1']
 
# Equivalent whitespace characters. Text strings: ['Equiv. spaces: 3-3',
# Numeric fields as numerics
'Equiv. \rspaces: 3-2',
Text strings:
'Equiv. \x0cspaces: 3-1',
['foo100bar99baz0.txt', 'foo100bar10baz0.txt', 'foo1000bar99baz10.txt', 'foo1000bar99baz9.txt']
'Equiv. \x0bspaces: 3+0',
'Equiv. \nspaces: 3+1',
'Equiv. \tspaces: 3+2']
 
# Case Independent sort. Text strings: ['cASE INDEPENDENT: 3-2',
# Title sorts
'caSE INDEPENDENT: 3-1',
Text strings:
'casE INDEPENDENT: 3+0',
['The Wind in the Willows', 'The 40th step more', 'The 39 steps', 'Wanda']
'case INDEPENDENT: 3+1']
# Numeric fields as numerics. Text strings: ['foo100bar99baz0.txt',
'foo100bar10baz0.txt',
'foo1000bar99baz10.txt',
'foo1000bar99baz9.txt']
 
# Title sorts. Text strings: ['The Wind in the Willows',
# Equivalent accented characters (and case)
'The 40th step more',
Text strings:
'The 39 steps',
[u'Equiv. \xfd accents: 2-2', u'Equiv. \xdd accents: 2-1', u'Equiv. y accents: 2+0', u'Equiv. Y accents: 2+1']
'Wanda']
 
# Equivalent accented characters (and case). Text strings: [u'Equiv. \xfd accents: 2-2',
u'Equiv. \xdd accents: 2-1',
u'Equiv. y accents: 2+0',
u'Equiv. Y accents: 2+1']
 
# Separated ligatures. Text strings: [u'\u0132 ligatured ij',
'no ligature']
Text strings:
[u'\u0132 ligatured ij', 'no ligature']
 
# Character replacements. Text strings: [u'Start with an \u0292: 2-2',
u'Start with an \u017f: 2-1',
Text strings:
[u'Start with an \u0292: 2-2', u'Start with an \u017f: 2-1', u'Start with an \xdf: 2+0', u'Start with an s\xdf: 2+10']</pre>,
u'Start with an s: 2+1']
</pre><br><br>
 
=={{header|AppleScript}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.