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.