Guest User

Untitled

a guest
Feb 26th, 2024
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | Source Code | 0 0
  1. import re
  2. from typing import List
  3.  
  4. # Define regex patterns
  5. re_swu = {
  6.     'symbol': r'[\U00040001-\U0004FFFF]',
  7.     'coord': r'[\U0001D80C-\U0001DFFF]{2}',
  8. }
  9.  
  10. def swu2fsw(swu_text: str) -> str:
  11.     if not swu_text:
  12.         return ''
  13.  
  14.     # Initial replacements
  15.     fsw = swu_text.replace("𝠀", "A").replace("𝠁", "B").replace("𝠂", "L").replace("𝠃", "M").replace("𝠄", "R")
  16.    
  17.     # SWU symbols to FSW keys
  18.     syms = re.findall(re_swu['symbol'], fsw)
  19.     if syms:
  20.         for sym in syms:
  21.             fsw = fsw.replace(sym, swu2key(sym))
  22.  
  23.     # SWU coordinates to FSW coordinates
  24.     coords = re.findall(re_swu['coord'], fsw)
  25.     if coords:
  26.         for coord in coords:
  27.             fsw = fsw.replace(coord, 'x'.join(map(str, swu2coord(coord))))
  28.  
  29.     return fsw
  30.  
  31. def swu2key(swu_sym: str) -> str:
  32.     symcode = ord(swu_sym) - 0x40001
  33.     base = symcode // 96
  34.     fill = (symcode - (base * 96)) // 16
  35.     rotation = symcode - (base * 96) - (fill * 16)
  36.     return f'S{hex(base + 0x100)[2:]}{hex(fill)[2:]}{hex(rotation)[2:]}'
  37.  
  38. def swu2num(swu_num: str) -> int:
  39.     return ord(swu_num) - 0x1D80C + 250
  40.  
  41. def swu2coord(swu_coord: str) -> List[int]:
  42.     return [swu2num(swu_coord[0]), swu2num(swu_coord[1])]
  43.  
  44.  
  45. swu = '𝠃𝤟𝤩񋛩𝣵𝤐񀀒𝤇𝣤񋚥𝤐𝤆񀀚𝣮𝣭'
  46. fsw = swu2fsw(swu)
  47. print(fsw)
Advertisement
Add Comment
Please, Sign In to add comment