[Telepathy-commits] [telepathy-doc/master] Use regular expressions rather than find() to prevent undesired substring matching
Davyd Madeley
davyd at madeley.id.au
Sun Mar 8 19:22:30 PDT 2009
---
docs/book/insert-examples.py | 10 +++++++---
1 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/docs/book/insert-examples.py b/docs/book/insert-examples.py
index 70b8137..8638ccb 100755
--- a/docs/book/insert-examples.py
+++ b/docs/book/insert-examples.py
@@ -15,6 +15,7 @@
import sys
import os.path
+import re
from lxml import etree
doc = etree.parse (sys.stdin)
@@ -49,15 +50,18 @@ for example in examples:
if id:
print >> sys.stderr, "Including `%s' from `%s'..." % (id, filename)
-
+
+ begin_re = re.compile ('begin %s(\\s|$)' % id)
+ end_re = re.compile ('end %s(\\s|$)' % id)
+
begin = False
lines = []
for line in contents.split ('\n'):
- if begin and line.find ('end %s' % id) != -1:
+ if begin and end_re.search (line):
break
elif begin:
lines.append (line)
- elif not begin and line.find ('begin %s' % id) != -1:
+ elif not begin and begin_re.search (line):
begin = True
continue
--
1.5.6.5
More information about the telepathy-commits
mailing list