Last active
October 22, 2022 14:42
-
-
Save joewiz/af04074c28e0ae2a1b92 to your computer and use it in GitHub Desktop.
Strip diacritics, with XQuery
This file contains 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
xquery version "3.1"; | |
declare function local:strip-diacritics($string as xs:string) as xs:string { | |
$string | |
=> normalize-unicode("NFD") | |
=> replace("\p{IsCombiningDiacriticalMarks}", "") | |
}; | |
declare function local:inspect-diacritics($string as xs:string) as element() { | |
let $normalized := normalize-unicode($string, "NFD") | |
let $stripped := local:strip-diacritics($string) | |
return | |
<result> | |
<source>{$string}</source> | |
<source-is-nfc-normalized>{$string = normalize-unicode($string)}</source-is-nfc-normalized> | |
<nfd-normalized>{$normalized}</nfd-normalized> | |
<stripped-of-combining-diacritical-marks>{$stripped}</stripped-of-combining-diacritical-marks> | |
<src-codepoints>{string-to-codepoints($string)}</src-codepoints> | |
<nfd-codepoints>{string-to-codepoints($normalized)}</nfd-codepoints> | |
<fin-codepoints>{string-to-codepoints($stripped)}</fin-codepoints> | |
</result> | |
}; | |
let $source := 'çéüå' | |
return | |
local:inspect-diacritics($source) |
This file contains 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
<result> | |
<source>çéüå</source> | |
<source-is-nfc-normalized>true</source-is-nfc-normalized> | |
<nfd-normalized>çéüå</nfd-normalized> | |
<stripped-of-combining-diacritical-marks>ceua</stripped-of-combining-diacritical-marks> | |
<src-codepoints>231 233 252 229</src-codepoints> | |
<nfd-codepoints>99 807 101 769 117 776 97 778</nfd-codepoints> | |
<fin-codepoints>99 101 117 97</fin-codepoints> | |
</result> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ssire So glad you found it useful!