Geoffrey Sneddon avatar Geoffrey Sneddon committed 9dba2f9

Check whether a basic form of the string exists before running the regular expression.

Comments (0)

Files changed (1)

specGen/processes/sub.py

 
 year = re.compile(r"\[YEAR(:[^\]]*)?\]")
 year_sub = time.strftime("%Y", time.gmtime())
+year_identifier = u"[YEAR"
 
 date = re.compile(r"\[DATE(:[^\]]*)?\]")
 date_sub = time.strftime("%d %B %Y", time.gmtime())
+date_identifier = u"[DATE"
 
 cdate = re.compile(r"\[CDATE(:[^\]]*)?\]")
 cdate_sub = time.strftime("%", time.gmtime())
+cdate_identifier = u"[DATE"
 
-string_subs = {year: year_sub, date: date_sub, cdate: cdate_sub}
+string_subs = ((year, year_sub, year_identifier),
+               (date, date_sub, date_identifier),
+               (cdate, cdate_sub, cdate_identifier))
 
 class sub(object):
 	"""Perform substitutions."""
 	
 	def stringSubstitutions(self, ElementTree, **kwargs):
 		for node in ElementTree.iter():
-			for regex, sub in string_subs.items():
-				if node.text is not None:
+			for regex, sub, identifier in string_subs:
+				if node.text is not None and identifier in node.text:
 					node.text = regex.sub(sub, node.text)
-				if node.tail is not None:
+				if node.tail is not None and identifier in node.tail:
 					node.tail = regex.sub(sub, node.tail)
 				for name, value in node.attrib.items():
-					node.attrib[name] = regex.sub(sub, value)
+					if identifier in value:
+						node.attrib[name] = regex.sub(sub, value)
 	
 	def commentSubstitutions(self, ElementTree, **kwargs):
 		pass
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.