assert id.startswith(state.current_definition_url_base)
return id[len(state.current_definition_url_base)+2:]
+and_re_src = re.compile(r'([^\s])&&([^\s])')
+and_re_dst = r'\1 && \2'
+
def fix_type_spacing(type: str) -> str:
- return type.replace('< ', '<').replace(' >', '>').replace(' &', '&').replace(' *', '*')
+ return and_re_src.sub(and_re_dst, type
+ .replace('< ', '<')
+ .replace(' >', '>')
+ .replace(' &', '&')
+ .replace(' *', '*'))
def parse_type(state: State, type: ET.Element) -> str:
# Constructors and typeless enums might not have it
#
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):
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>')