Created
April 23, 2020 18:43
-
-
Save emchateau/f3439ccd81a0e155198f18f9148b4c4d to your computer and use it in GitHub Desktop.
Sorts strings, prefer letters to numbers
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
(:~ | |
: Sorts strings, prefer letters to numbers. | |
: @param $items strings to be sorted | |
: @return sorted sequence | |
: Christian Grün on SlackXML 2020 | |
:) | |
declare function local:sort( | |
$items as xs:string* | |
) as xs:string* { | |
sort($items, (), function($item) { | |
$item | |
=> lower-case() | |
=> normalize-space() | |
=> replace('(\p{L})', 'A$1') (: letters :) | |
=> replace('(\p{N})', 'B$1') (: numbers :) | |
=> replace('([^\p{L}\p{N}])', 'C$1') (: everything else :) | |
}) | |
}; | |
local:sort(('jack', ' John', '184', 'Sean')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment