Fix enum prefix stripping to work only up to word boundaries
authorDan Winship <danw@gnome.org>
Mon, 23 Nov 2009 15:52:09 +0000 (10:52 -0500)
committerDan Winship <danw@gnome.org>
Mon, 23 Nov 2009 15:52:09 +0000 (10:52 -0500)
https://bugzilla.gnome.org/show_bug.cgi?id=602672

giscanner/transformer.py
tests/scanner/foo-1.0-expected.gir
tests/scanner/foo-1.0-expected.tgir
tests/scanner/foo.h

index 86a2114..a131e3c 100644 (file)
@@ -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
index 85c2322..fa3d73c 100644 (file)
@@ -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"
index 8504bc4..bcba5a2 100644 (file)
     <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"/>
index 7c2afe6..199d57a 100644 (file)
@@ -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;