Avoid compiling "the same" regex multiple times
Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is contained in:
parent
045f1f0ad5
commit
fd2daf44b4
1 changed files with 6 additions and 3 deletions
|
|
@ -80,6 +80,9 @@ XML_ENTS_ESCAPE_APOS["'"] = '''
|
|||
XML_ENTS_ESCAPE_QUOT = XML_ENTS_NO_QUOTES.copy()
|
||||
XML_ENTS_ESCAPE_QUOT['"'] = '"'
|
||||
|
||||
# Used to split values where "x y" or "x,y" or a mix of the two is allowed
|
||||
RE_COMMA_WSP = re.compile(r"\s*[\s,]\s*")
|
||||
|
||||
NS = {'SVG': 'http://www.w3.org/2000/svg',
|
||||
'XLINK': 'http://www.w3.org/1999/xlink',
|
||||
'SODIPODI': 'http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd',
|
||||
|
|
@ -2738,7 +2741,7 @@ def parseListOfPoints(s):
|
|||
# coordinate-pair = coordinate comma-or-wsp coordinate
|
||||
# coordinate = sign? integer
|
||||
# comma-wsp: (wsp+ comma? wsp*) | (comma wsp*)
|
||||
ws_nums = re.split(r"\s*[\s,]\s*", s.strip())
|
||||
ws_nums = RE_COMMA_WSP.split(s.strip())
|
||||
nums = []
|
||||
|
||||
# also, if 100-100 is found, split it into two also
|
||||
|
|
@ -3351,7 +3354,7 @@ def properlySizeDoc(docElement, options):
|
|||
# else we have a statically sized image and we should try to remedy that
|
||||
|
||||
# parse viewBox attribute
|
||||
vbSep = re.split('[, ]+', docElement.getAttribute('viewBox'))
|
||||
vbSep = RE_COMMA_WSP.split(docElement.getAttribute('viewBox'))
|
||||
# if we have a valid viewBox we need to check it
|
||||
vbWidth, vbHeight = 0, 0
|
||||
if len(vbSep) == 4:
|
||||
|
|
@ -3810,7 +3813,7 @@ def scourString(in_string, options=None):
|
|||
elem.setAttribute(attr, scourLength(elem.getAttribute(attr)))
|
||||
viewBox = doc.documentElement.getAttribute('viewBox')
|
||||
if viewBox:
|
||||
lengths = re.split('[, ]+', viewBox)
|
||||
lengths = RE_COMMA_WSP.split(viewBox)
|
||||
lengths = [scourUnitlessLength(length) for length in lengths]
|
||||
doc.documentElement.setAttribute('viewBox', ' '.join(lengths))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue