# Linguistic sorting?

**URL:** <https://forum.crystal-lang.org/t/linguistic-sorting/4088>\
**Category:** Help & Support\
**Created:** [November 25, 2021, 8:36pm UTC](https://forum.crystal-lang.org/t/linguistic-sorting/4088 "2021-11-25T20:36:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrucePerens](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/bruceperens/32/852_2.png) [@BrucePerens](https://forum.crystal-lang.org/u/BrucePerens)\
**Post date:** [November 25, 2021, 8:36pm UTC](https://forum.crystal-lang.org/t/linguistic-sorting/4088/1 "2021-11-25T20:36:00Z")

</div>

`String#<=>` uses `unsafe.memcmp`, so it’s a numeric byte sort rather than anything language-aware. Sorting of UTF-8 codepoints for a particular language would require a table of character-order for that language, so that `"ä"` and `"a"` are in proper order relative to each other. A table of characters to ignore in sorting, like `"'"`, is also necessary.

Has anyone done this for Crystal? There is a treatise on Unicode sorting at [UTS #10: Unicode Collation Algorithm](http://unicode.org/reports/tr10/) that is a mullti-level sort with weights, a lot more than just two tables, but I don’t know of an implementation.

```
Thanks

Bruce
```

---

<div class="post-metadata">

**Author:** ![naqvis](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/naqvis/32/906_2.png) [@naqvis](https://forum.crystal-lang.org/u/naqvis)\
**Post date:** [November 26, 2021, 4:31pm UTC](https://forum.crystal-lang.org/t/linguistic-sorting/4088/2 "2021-11-26T16:31:30Z")

</div>

None i’m aware of. Your best bet would be to go with `icu` and luckily there is a Crystal bindings for that. [GitHub - olbat/icu.cr: A Cystal binding/wrapper to the ICU library](https://github.com/olbat/icu.cr)

**Collator** might be something you are looking for  
[https://olbat.github.io/icu.cr/ICU/Collator.html](https://olbat.github.io/icu.cr/ICU/Collator.html)

Hope it helps.

Ali Naqvi
