def isolate_native_function_v1(function): original_function = function function = function.strip() # Ensure we don't operated on objc functions if function.startswith(('[', '+[', '-[')): return function # Chop off C++ trailers while 1: match = _cpp_trailer_re.search(function) if match is None: break function = function[:match.start()].rstrip() # Because operator<< really screws with our balancing, so let's work # around that by replacing it with a character we do not observe in # `split_func_tokens` or `replace_enclosed_string`. function = function \ .replace('operator<<', u'operator⟨⟨') \ .replace('operator<', u'operator⟨') \ .replace('operator()', u'operator◯') # Remove the arguments if there is one. def process_args(value, start): value = value.strip() if value in ('anonymous namespace', 'operator'): return '(%s)' % value return '' function = replace_enclosed_string(function, '(', ')', process_args) # Resolve generic types, but special case rust which uses things like # <Foo as Bar>::baz to denote traits. def process_generics(value, start): # Rust special case if start == 0: return '<%s>' % replace_enclosed_string(value, '<', '>', process_generics) return '<T>' function = replace_enclosed_string(function, '<', '>', process_generics) # The last token is the function name. tokens = split_func_tokens(function) if tokens: function = tokens[-1].replace(u'⟨', '<').replace(u'◯', '()') # This really should never happen else: function = original_function # trim off rust markers function = _rust_hash.sub('', function) # trim off windows decl markers return _windecl_hash.sub('\\1', function)
def test_split_func_tokens(input, output): assert split_func_tokens(input) == output