chiark / gitweb /
doxygen: add back removed spaces around &&.
authorVladimír Vondruš <mosra@centrum.cz>
Mon, 26 Nov 2018 13:38:48 +0000 (14:38 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Mon, 26 Nov 2018 13:53:01 +0000 (14:53 +0100)
And test this whole thing.

doxygen/dox2html5.py
doxygen/test/test_utility.py

index 08dfc77399a20a3c53746feefc14f89d59779561..ff6dac2b7e23f33d8bc082969c11dee3b7a2f873 100755 (executable)
@@ -432,8 +432,15 @@ def extract_id_hash(state: State, element: ET.Element) -> str:
     assert id.startswith(state.current_definition_url_base)
     return id[len(state.current_definition_url_base)+2:]
 
+and_re_src = re.compile(r'([^\s])&amp;&amp;([^\s])')
+and_re_dst = r'\1 &amp;&amp; \2'
+
 def fix_type_spacing(type: str) -> str:
-    return type.replace('&lt; ', '&lt;').replace(' &gt;', '&gt;').replace(' &amp;', '&amp;').replace(' *', '*')
+    return and_re_src.sub(and_re_dst, type
+        .replace('&lt; ', '&lt;')
+        .replace(' &gt;', '&gt;')
+        .replace(' &amp;', '&amp;')
+        .replace(' *', '*'))
 
 def parse_type(state: State, type: ET.Element) -> str:
     # Constructors and typeless enums might not have it
index 169826e95242636ceeec0d9144fa25072dda1f3d..7ab6b60c30b59a27444db33cd5446e4306d2765d 100644 (file)
@@ -23,8 +23,9 @@
 #
 
 import unittest
+import html
 
-from dox2html5 import add_wbr
+from dox2html5 import add_wbr, fix_type_spacing
 
 class Utility(unittest.TestCase):
     def test_add_wbr(self):
@@ -32,3 +33,11 @@ class Utility(unittest.TestCase):
         self.assertEqual(add_wbr('CORRADE_TEST_MAIN()'), 'CORRADE_<wbr />TEST_<wbr />MAIN()')
         self.assertEqual(add_wbr('https://magnum.graphics/showcase/'), 'https:/<wbr />/<wbr />magnum.graphics/<wbr />showcase/<wbr />')
         self.assertEqual(add_wbr('<strong>a</strong>'), '<strong>a</strong>')
+
+    def test_fix_type_spacing(self):
+        def fix_escaped(str):
+            return html.unescape(fix_type_spacing(html.escape(str)))
+
+        self.assertEqual(fix_escaped('Foo< T, U > *'), 'Foo<T, U>*')
+        self.assertEqual(fix_escaped('Foo< T, U > &'), 'Foo<T, U>&')
+        self.assertEqual(fix_escaped('Foo< T&&U >'), 'Foo<T && U>')