Last active
August 24, 2023 22:45
-
-
Save jtmcdole/476ac44f54c9f17a0cd587ed42b0ecfa to your computer and use it in GitHub Desktop.
unicode fun in dart
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
===[π]=== | |
length: 2 | |
codeunits: 2 | |
runes: 1 | |
utf16: 0xd83c 0xdf08 | |
utf8len: 4 | |
utf8 bytes: 0xf0 0x9f 0x8c 0x88 | |
===[Helloπ]=== | |
length: 7 | |
codeunits: 7 | |
runes: 6 | |
utf16: 0x0048 0x0065 0x006c 0x006c 0x006f 0xd83c 0xdf0e | |
utf8len: 9 | |
utf8 bytes: 0x48 0x65 0x6c 0x6c 0x6f 0xf0 0x9f 0x8c 0x8e | |
===[π³οΈβπ]=== | |
length: 6 | |
codeunits: 6 | |
runes: 4 | |
utf16: 0xd83c 0xdff3 0xfe0f 0x200d 0xd83c 0xdf08 | |
utf8len: 14 | |
utf8 bytes: 0xf0 0x9f 0x8f 0xb3 0xef 0xb8 0x8f 0xe2 0x80 0x8d 0xf0 0x9f 0x8c 0x88 | |
===[π³οΈβ]=== | |
length: 4 | |
codeunits: 4 | |
runes: 3 | |
utf16: 0xd83c 0xdff3 0xfe0f 0x200d | |
utf8len: 10 | |
utf8 bytes: 0xf0 0x9f 0x8f 0xb3 0xef 0xb8 0x8f 0xe2 0x80 0x8d |
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
import 'dart:convert'; | |
main() { | |
printIt(String sup) { | |
print('===[$sup]==='); | |
print(' length: ${sup.length}'); | |
print(' codeunits: ${sup.codeUnits.length}'); | |
print(' runes: ${sup.runes.length}'); | |
var hex = | |
sup.codeUnits.map((d) => '0x${d.toRadixString(16).padLeft(4, '0')}'); | |
print(' utf16: ${hex.join(' ')}'); | |
var utf8bytes = utf8.encode(sup); | |
hex = | |
utf8bytes.map((d) => '0x${d.toRadixString(16).padLeft(2, '0')}'); | |
print(' utf8len: ${utf8bytes.length}'); | |
print(' utf8 bytes: ${hex.join(' ')}'); | |
} | |
printIt('π'); | |
printIt('Helloπ'); | |
printIt('π³οΈβπ'); | |
printIt('π³οΈβ'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment