Fix the subitems formatter function to split only when the period is surrounded by non-white space and not another period

This commit is contained in:
Kovid Goyal 2011-12-08 08:36:39 +05:30
commit a9b701d685

View File

@ -717,15 +717,23 @@ class BuiltinSubitems(BuiltinFormatterFunction):
return ''
si = int(start_index)
ei = int(end_index)
has_periods = '.' in val
items = [v.strip() for v in val.split(',')]
rv = set()
if has_periods:
pp = re.compile(r'(?<=[^\.\s])\.(?=[^\.\s])', re.U)
else:
pp = None
for item in items:
component = item.split('.')
if has_periods and '.' in item:
components = pp.split(item)
else:
components = [item]
try:
if ei == 0:
rv.add('.'.join(component[si:]))
rv.add('.'.join(components[si:]))
else:
rv.add('.'.join(component[si:ei]))
rv.add('.'.join(components[si:ei]))
except:
pass
return ', '.join(sorted(rv, key=sort_key))