Advertisement
Guest User

Untitled

a guest
Feb 26th, 2024
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.69 KB | Source Code | 0 0
  1. Map<String, String> reSwu = {
  2.   'symbol': r'[\\U00040001-\\U0004FFFF]',
  3.   'coord': r'[\\U0001D80C-\\U0001DFFF]{2}',
  4. };
  5.  
  6. String swu2fsw(String swuText) {
  7.   if (swuText.isEmpty) {
  8.     return '';
  9.   }
  10.  
  11.   // Initial replacements
  12.   String fsw = swuText
  13.       .replaceAll("𝠀", "A")
  14.       .replaceAll("𝠁", "B")
  15.       .replaceAll("𝠂", "L")
  16.       .replaceAll("𝠃", "M")
  17.       .replaceAll("𝠄", "R");
  18.  
  19.   // SWU symbols to FSW keys
  20.   RegExp symbolRegex = RegExp(reSwu['symbol']!, unicode: true);
  21.   Iterable<RegExpMatch> symbols = symbolRegex.allMatches(fsw);
  22.   if (symbols.isNotEmpty) {
  23.     for (RegExpMatch sym in symbols) {
  24.       fsw = fsw.replaceAll(sym.group(0)!, swu2key(sym.group(0)!));
  25.     }
  26.   }
  27.  
  28.   // SWU coordinates to FSW coordinates
  29.   RegExp coordRegex = RegExp(reSwu['coord']!, unicode: true);
  30.   Iterable<Match> coords = coordRegex.allMatches(fsw);
  31.   if (coords.isNotEmpty) {
  32.     for (Match coord in coords) {
  33.       fsw = fsw.replaceAll(
  34.           coord.group(0)!, swu2coord(coord.group(0)!).toString());
  35.     }
  36.   }
  37.  
  38.   return fsw;
  39. }
  40.  
  41. String swu2key(String swuSym) {
  42.   int symcode = swuSym.runes.first - 0x40001;
  43.   int base = symcode ~/ 96;
  44.   int fill = (symcode - (base * 96)) ~/ 16;
  45.   int rotation = symcode - (base * 96) - (fill * 16);
  46.   return 'S${(base + 0x100).toRadixString(16)}${fill.toRadixString(16)}${rotation.toRadixString(16)}';
  47. }
  48.  
  49. int swu2num(String swuNum) {
  50.   return swuNum.runes.first - 0x1D80C + 250;
  51. }
  52.  
  53. List<int> swu2coord(String swuCoord) {
  54.   return [swu2num(swuCoord[0]), swu2num(swuCoord[1])];
  55. }
  56.  
  57. void main() {
  58.   String swu = '𝠃ðĪŸðĪĐņ‹›ĐðĢĩðĪņ€€’ðĪ‡ðĢĪņ‹šĨðĪðĪ†ņ€€šðĢŪðĢ­';
  59.   String fsw = swu2fsw(swu);
  60.   print(fsw);
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement