Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- p = re.compile(r'(\[*)([ZBCSIJFDV]|L([^;\s]+);)')
- prims = {'Z': 'boolean', 'B': 'byte', 'C': 'char', 'S': 'short', 'I': 'int', 'J': 'long', 'F': 'float', 'D': 'double', 'V': 'void'}
- def tr(s):
- return [(i.group(3).replace('/', '.') if i.group(3) else prims[i.group(2)]) + ('[]' * len(i.group(1)))
- for i in p.finditer(s)]
- # Example:
- >>> tr('')
- []
- >>> tr('Z')
- ['boolean']
- >>> tr('V')
- ['void']
- >>> tr('FIS')
- ['float', 'int', 'short']
- >>> tr('Ljava/lang/String;I[[SJ')
- ['java.lang.String', 'int', 'short[][]', 'long']
- >>> tr('[V') # notice that this is actually invalid
- ['void[]']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement