NaturalDocs:: StringSort

A package that does proper string sorting.  A proper sort orders the characters as follows. 

  • End of string. 
  • Whitespace.  Line break-tab-space. 
  • Symbols, which is anything not included in the other entries. 
  • Numbers, 0-9. 
  • Letters, case insensitive except to break ties. 

Normal string sorting would place certain symbols between letters and numbers instead of having them all grouped together.  Also, you would have to choose between case sensitivity or complete case insensitivity, in which ties are broken arbitrarily. 

This is one more package I wish I didn’t have to write.  Sigh. 

Summary
A package that does proper string sorting.
Compares two strings.
Returns an ordinal value for a character that can be used for sorting.
Compares two strings that are completely the same when compared in a case-insensitive manner.

Compare

sub Compare #(a, b)

Compares two strings.  Returns zero if A and B are equal, a positive value if A is greater than B, and a negative value if A is less than B. 

Support Functions

SortOrdinal

sub SortOrdinal #(character)

Returns an ordinal value for a character that can be used for sorting.  Note that the value is completely case insensitive; capital and lowercase letters return the same value. 

BreakTie

sub BreakTie #(a, b)

Compares two strings that are completely the same when compared in a case-insensitive manner.  Lower case letters come first.