From 6e3aa7e84388fa446f82996a7c589dd214cca191 Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Sat, 3 Apr 2010 18:22:52 +0800 Subject: [PATCH] [STRIP_SUFFIX] ability to flag suffixes to be stripped. Pretty usefully for things like libapr0 / libsvn which use _t as a type suffix. --- giscanner/scannermain.py | 5 +++++ giscanner/transformer.py | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 44c0287..6ef80ee 100644 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -75,6 +75,10 @@ def _get_option_parser(): parser.add_option("", "--strip-prefix", action="store", dest="strip_prefix", default=None, help="remove this prefix from objects and functions") + parser.add_option("", "--strip-suffix", + action="store", dest="strip_suffix", default=None, + help="remove this suffix from objects and functions, " + "only done when also removing prefix") parser.add_option("", "--add-init-section", action="append", dest="init_sections", default=[], help="add extra initialization code in the introspection program") @@ -271,6 +275,7 @@ def scanner_main(args): transformer.set_strip_prefix(options.strip_prefix) else: transformer.set_strip_prefix(options.namespace_name) + transformer.set_strip_suffix(options.strip_suffix) transformer.set_include_paths(options.include_paths) shown_include_warning = False for include in options.includes: diff --git a/giscanner/transformer.py b/giscanner/transformer.py index 87be006..6179c2b 100644 --- a/giscanner/transformer.py +++ b/giscanner/transformer.py @@ -83,6 +83,9 @@ class Transformer(object): def get_includes(self): return self._includes + def set_strip_suffix(self, strip_suffix): + self._strip_suffix = strip_suffix + def set_strip_prefix(self, strip_prefix): self._strip_prefix = strip_prefix @@ -181,14 +184,23 @@ class Transformer(object): # when --strip-prefix=g: # GHashTable -> HashTable # g_hash_table_new -> hash_table_new + stripped = False prefix = self._strip_prefix.lower() - if isfunction: + + if isfunction and '_' in name: prefix += '_' if len(name) > len(prefix) and name.lower().startswith(prefix): name = name[len(prefix):] + stripped = True while name.startswith('_'): name = name[1:] + + if (stripped and self._strip_suffix and + len(name) > len(self._strip_suffix) and + name.endswith(self._strip_suffix) + name = name[:-1*len(self._strip_suffix)] + return name def _traverse_one(self, symbol, stype=None): -- 2.39.2