[gobject-introspection] Fix enum prefix stripping to work only up to word boundaries
- From: Dan Winship <danw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gobject-introspection] Fix enum prefix stripping to work only up to word boundaries
- Date: Mon, 23 Nov 2009 16:06:00 +0000 (UTC)
commit ab127091d84336a851e0cec9cfdd0435065d9e2a
Author: Dan Winship <danw gnome org>
Date: Mon Nov 23 10:52:09 2009 -0500
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"/>
</enumeration>
+ <enumeration name="AddressType" c:type="FooAddressType">
+ <member name="invalid" value="0" c:identifier="FOO_ADDRESS_INVALID"/>
+ <member name="ipv4" value="1" c:identifier="FOO_ADDRESS_IPV4"/>
+ <member name="ipv6" value="2" c:identifier="FOO_ADDRESS_IPV6"/>
+ </enumeration>
<record name="BRect"
c:type="FooBRect"
glib:type-name="FooBRect"
diff --git a/tests/scanner/foo-1.0-expected.tgir b/tests/scanner/foo-1.0-expected.tgir
index 8504bc4..bcba5a2 100644
--- a/tests/scanner/foo-1.0-expected.tgir
+++ b/tests/scanner/foo-1.0-expected.tgir
@@ -10,6 +10,11 @@
<enumeration name="ASingle">
<member name="some_single_enum" value="0"/>
</enumeration>
+ <enumeration name="AddressType">
+ <member name="invalid" value="0"/>
+ <member name="ipv4" value="1"/>
+ <member name="ipv6" value="2"/>
+ </enumeration>
<record name="BRect" glib:type-name="FooBRect" glib:get-type="foo_brect_get_type">
<field name="x" writable="1">
<type name="double"/>
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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]