@staticmethod
def _extract_fieldname(text: str) -> (str, str):
"""Extract a supposed field name from the given text.
Text field can be of type `@field:` (epydoc) or `:field:` (reST).
Some examples of supported input text and the returned tuple:
- "@param name: THE name" returns ("name", "THE name")
- :param name: THE name" returns ("name", "THE name")
- ":example:" returns ("example", "")
- ":return: Something" returns ("return", "Something")
- "Something here" returns (None, "Something here")
:param text: (str) Any line of text starting by a field.
:return: (field_name, description)
"""
if len(text) == 0:
return (None, '')
if text[0] not in ('@', ':'):
return (None, text)
try:
sep_whitespace = text.index(' ')
except ValueError:
sep_whitespace = len(text)
try:
sep_dots = text[1:].index(':')
except ValueError:
sep_dots = len(text)
pos = min(sep_whitespace, sep_dots)
if pos < len(text):
field_name = ClamInfoMarkdown._fieldname_variant(text[1:pos + 1])
if field_name in ClamInfoMarkdown.IGNORE_FIELDS:
return (None, '')
if pos == sep_whitespace:
content = text[pos + 1:].strip()
else:
content = text[pos + 2:].strip()
if field_name in ClamInfoMarkdown.MARKDOWN_SECTION.keys():
return (field_name, content)
return (None, text)