def format_description(description, prefix, prefixes, prefix_format_func=None):
if prefix is not None and prefix_format_func is not None:
prefix = prefix_format_func(prefix)
# Default multi -> '' if no format func given
if prefix_format_func is None and prefix == cr_constants.MULTI_REFS_PREFIX:
prefix = ''
if '%s' in description:
# Escape stray percents
description = re.sub('%([^s])', '%%\\1', description)
# Only add the prefix if there are multiple possibilities
s = str(prefix) if len(prefixes) > 1 and prefix else ''
description = description % s
# Collapse whitespace
description = re.sub('\s+', ' ', description)
return description
评论列表
文章目录