From ab127091d84336a851e0cec9cfdd0435065d9e2a Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Mon, 23 Nov 2009 10:52:09 -0500 Subject: [PATCH] Fix enum prefix stripping to work only up to word boundaries https://bugzilla.gnome.org/show_bug.cgi?id=602672 --- giscanner/transformer.py | 16 +++++++--------- tests/scanner/foo-1.0-expected.gir | 5 +++++ tests/scanner/foo-1.0-expected.tgir | 5 +++++ tests/scanner/foo.h | 7 +++++++ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/giscanner/transformer.py b/giscanner/transformer.py index 86a2114..a131e3c 100644 --- a/giscanner/transformer.py +++ b/giscanner/transformer.py @@ -214,15 +214,13 @@ class Transformer(object): def _enum_common_prefix(self, symbol): def common_prefix(a, b): - alen = len(a) - blen = len(b) - l = min(alen, blen) - for i in xrange(l): - if a[i] != b[i]: - return a[:i] - if alen > blen: - return b - return a + commonparts = [] + for aword, bword in zip(a.split('_'), b.split('_')): + if aword != bword: + return '_'.join(commonparts) + '_' + commonparts.append(aword) + return min(a, b) + # Nothing less than 2 has a common prefix if len(list(symbol.base_type.child_list)) < 2: return None diff --git a/tests/scanner/foo-1.0-expected.gir b/tests/scanner/foo-1.0-expected.gir index 85c2322..fa3d73c 100644 --- a/tests/scanner/foo-1.0-expected.gir +++ b/tests/scanner/foo-1.0-expected.gir @@ -23,6 +23,11 @@ and/or use gtk-doc annotations. --> value="0" c:identifier="FOO_SOME_SINGLE_ENUM"/> + + + + + + + + + + diff --git a/tests/scanner/foo.h b/tests/scanner/foo.h index 7c2afe6..199d57a 100644 --- a/tests/scanner/foo.h +++ b/tests/scanner/foo.h @@ -188,6 +188,13 @@ typedef enum FOO_ENUM_FULLNAME_THREE } FooEnumFullname; +typedef enum +{ + FOO_ADDRESS_INVALID, + FOO_ADDRESS_IPV4, + FOO_ADDRESS_IPV6 +} FooAddressType; + typedef struct _FooBoxed FooBoxed; GType foo_boxed_get_type (void) G_GNUC_CONST; -- 2.7.4