summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYouness Alaoui <youness.alaoui@collabora.co.uk>2009-03-06 23:40:26 (GMT)
committerYouness Alaoui <youness.alaoui@collabora.co.uk>2009-03-06 23:40:26 (GMT)
commitfeeced3f4ff0fa8a1353e83eb45028f448fb5cb6 (patch)
tree587cd67116b931368fd57c7b0e7f51eed9f748a2
parent744a1bde71444ca4fa43a109d25d7ca557013ff7 (diff)
downloadtelepathy-doc-feeced3f4ff0fa8a1353e83eb45028f448fb5cb6.tar.gz
telepathy-doc-feeced3f4ff0fa8a1353e83eb45028f448fb5cb6.tar.xz
Fix issue with inserting examples in the docs when an id is a substring of another id. We make sure the 'begin %id' and 'end %id' have a line ending or a space after them before considering them valid
-rwxr-xr-xdocs/book/insert-examples.py39
1 files changed, 31 insertions, 8 deletions
diff --git a/docs/book/insert-examples.py b/docs/book/insert-examples.py
index 70b8137..24c8090 100755
--- a/docs/book/insert-examples.py
+++ b/docs/book/insert-examples.py
@@ -53,13 +53,24 @@ for example in examples:
begin = False
lines = []
for line in contents.split ('\n'):
- if begin and line.find ('end %s' % id) != -1:
- break
- elif begin:
- lines.append (line)
- elif not begin and line.find ('begin %s' % id) != -1:
- begin = True
- continue
+ if begin:
+ idx = line.find ('end %s' % id)
+ l = len('end %s' % id)
+ if idx != -1 and \
+ (len(line) == idx + l or \
+ line[idx + l] == ' '):
+ break
+ else:
+ lines.append (line)
+ else:
+ idx = line.find ('begin %s' % id)
+ l = len('begin %s' % id)
+
+ if idx != -1 and \
+ (len(line) == idx + l or \
+ line[idx + l] == ' '):
+ begin = True
+ continue
if lines != []: contents = '\n'.join (lines)
@@ -91,7 +102,19 @@ for nicename in included_files:
# find the starting offsets for each id in the file
def get_tuple (prefix, id):
str = '%s %s' % (prefix, id)
- return (contents.find (str), prefix, id, len (str))
+ start = 0
+ while start < len(contents):
+ idx = contents.find (str, start)
+ start = idx + 1
+ l = len(str)
+ if idx != -1 and \
+ (len(contents) == idx + l or \
+ contents[idx + l] == ' ' or \
+ contents[idx + l] == '\n'):
+ return (idx, prefix, id, len (str))
+ elif idx == -1:
+ return (idx, prefix, id, len (str))
+
offsets = map (lambda id: get_tuple ('begin', id),
included_files[nicename]) + \
map (lambda id: get_tuple ('end', id),