Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. p = re.compile(r'(\[*)([ZBCSIJFDV]|L([^;\s]+);)')
  2. prims = {'Z': 'boolean', 'B': 'byte', 'C': 'char', 'S': 'short', 'I': 'int', 'J': 'long', 'F': 'float', 'D': 'double', 'V': 'void'}
  3. def tr(s):
  4. return [(i.group(3).replace('/', '.') if i.group(3) else prims[i.group(2)]) + ('[]' * len(i.group(1)))
  5. for i in p.finditer(s)]
  6.  
  7. # Example:
  8. >>> tr('')
  9. []
  10. >>> tr('Z')
  11. ['boolean']
  12. >>> tr('V')
  13. ['void']
  14. >>> tr('FIS')
  15. ['float', 'int', 'short']
  16. >>> tr('Ljava/lang/String;I[[SJ')
  17. ['java.lang.String', 'int', 'short[][]', 'long']
  18. >>> tr('[V') # notice that this is actually invalid
  19. ['void[]']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement