0

Users submitted those weird characters. How to sort them along with normal text in Dart ?

๐”ฆ๐” ๐”ฆ๐”ž๐”ฉ๐”ž
๐“•๐“ช๐“ด๐“ท๐“ฌ๐“ป๐“ช
๐—บ๐—น๐—ฒ๐—–๐—น๐—ฎ๐—ฟ๐—ฎ
๐™–๐™จ๐™ก๐™–๐™œ๐™–๐™ˆ๐™ฎ
๐–ง๐—‹๐—‚๐–พ
๐‘ฎ๐’‚๐’๐’๐’†๐’‚
๐ฟ๐‘ข๐‘›๐‘Ž
๐ƒ๐ก๐ข๐š
๐• โ„๐•’๐•ฅ๐•ง๐•’๐• ๐•œ๐• 

The good old b.name.toLowerCase().compareTo(a.name.toLowerCase()); does not work

2
  • in other words how to translate them to iciala Fakncra mleClara Hrie ... Commented Jun 21, 2023 at 2:00
  • .toLowerCase says "This function uses the language independent Unicode mapping and thus only works in some languages." I don't think there's any better way of doing it, unless you have magical knowledge about the Unicode characters involved. Commented Jun 21, 2023 at 2:10

1 Answer 1

0

UPDATE: Just found https://pub.dev/packages/diacritic, which appears as though it might do roughly what you want, although I'm not sure of how many different characters it supports.


Well, a good place to start might be looking at the internal implementation of the ES6 String.prototype.normalize() function.

Interestingly, it only works in Compatibility Decomposition mode - ie. NFKC or NFKD.

for (const weirdString of [
  '๐”ฆ๐” ๐”ฆ๐”ž๐”ฉ๐”ž',
  '๐“•๐“ช๐“ด๐“ท๐“ฌ๐“ป๐“ช',
  '๐—บ๐—น๐—ฒ๐—–๐—น๐—ฎ๐—ฟ๐—ฎ',
  '๐™–๐™จ๐™ก๐™–๐™œ๐™–๐™ˆ๐™ฎ',
  '๐–ง๐—‹๐—‚๐–พ',
  '๐‘ฎ๐’‚๐’๐’๐’†๐’‚',
  '๐ฟ๐‘ข๐‘›๐‘Ž',
  '๐ƒ๐ก๐ข๐š',
  '๐• โ„๐•’๐•ฅ๐•ง๐•’๐• ๐•œ๐• ',
]) {console.log(weirdString.normalize('NFKC'))}


Anyway, maybe there is a translation in Dart, or you can use the 'dart:js' library if you're running on the web, or you could find the implementation in the V8 engine (although it'll probably be in C).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking โ€œPost Your Answerโ€, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.