use single regex

This commit is contained in:
Jakub Trllo 2022-02-15 17:24:32 +01:00
parent 7e1203ea51
commit 646eb2e519

View file

@ -31,8 +31,7 @@ INT_TAGS = {
"subimages", "subimages",
} }
CHAR_REF_REGEX_DECIMAL = re.compile(r"&#[0-9]+;") XML_CHAR_REF_REGEX_HEX = re.compile(r"&#x?[0-9a-fA-F]+;")
CHAR_REF_REGEX_HEX = re.compile(r"&#x[0-9a-zA-Z]+;")
# Regex to parse array attributes # Regex to parse array attributes
ARRAY_TYPE_REGEX = re.compile(r"^(int|float|string)\[\d+\]$") ARRAY_TYPE_REGEX = re.compile(r"^(int|float|string)\[\d+\]$")
@ -196,12 +195,9 @@ def parse_oiio_xml_output(xml_string, logger=None):
return output return output
# Fix values with ampresand (lazy fix) # Fix values with ampresand (lazy fix)
# - ElementTree can't handle all escaped values with ampresand # - oiiotool exports invalid xml which ElementTree can't handle
# e.g. "" # e.g. ""
matches = ( matches = XML_CHAR_REF_REGEX_HEX.findall(xml_string)
set(CHAR_REF_REGEX_HEX.findall(xml_string))
| set(CHAR_REF_REGEX_DECIMAL.findall(xml_string))
)
for match in matches: for match in matches:
new_value = match.replace("&", "&") new_value = match.replace("&", "&")
xml_string = xml_string.replace(match, new_value) xml_string = xml_string.replace(match, new_value)