Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Map<String, String> reSwu = {
- 'symbol': r'[\\U00040001-\\U0004FFFF]',
- 'coord': r'[\\U0001D80C-\\U0001DFFF]{2}',
- };
- String swu2fsw(String swuText) {
- if (swuText.isEmpty) {
- return '';
- }
- // Initial replacements
- String fsw = swuText
- .replaceAll("ð ", "A")
- .replaceAll("ð ", "B")
- .replaceAll("ð ", "L")
- .replaceAll("ð ", "M")
- .replaceAll("ð ", "R");
- // SWU symbols to FSW keys
- RegExp symbolRegex = RegExp(reSwu['symbol']!, unicode: true);
- Iterable<RegExpMatch> symbols = symbolRegex.allMatches(fsw);
- if (symbols.isNotEmpty) {
- for (RegExpMatch sym in symbols) {
- fsw = fsw.replaceAll(sym.group(0)!, swu2key(sym.group(0)!));
- }
- }
- // SWU coordinates to FSW coordinates
- RegExp coordRegex = RegExp(reSwu['coord']!, unicode: true);
- Iterable<Match> coords = coordRegex.allMatches(fsw);
- if (coords.isNotEmpty) {
- for (Match coord in coords) {
- fsw = fsw.replaceAll(
- coord.group(0)!, swu2coord(coord.group(0)!).toString());
- }
- }
- return fsw;
- }
- String swu2key(String swuSym) {
- int symcode = swuSym.runes.first - 0x40001;
- int base = symcode ~/ 96;
- int fill = (symcode - (base * 96)) ~/ 16;
- int rotation = symcode - (base * 96) - (fill * 16);
- return 'S${(base + 0x100).toRadixString(16)}${fill.toRadixString(16)}${rotation.toRadixString(16)}';
- }
- int swu2num(String swuNum) {
- return swuNum.runes.first - 0x1D80C + 250;
- }
- List<int> swu2coord(String swuCoord) {
- return [swu2num(swuCoord[0]), swu2num(swuCoord[1])];
- }
- void main() {
- String swu = 'ð ðĪðĪĐņĐðĢĩðĪņðĪðĢĪņĨðĪðĪņðĢŪðĢ';
- String fsw = swu2fsw(swu);
- print(fsw);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement