def test_find_offsets(self): text = "Trying to find the start of this section and the other " text += "start here" self.assertEqual((19, 55), search.find_offsets(text, lambda t: t.find("start"))) self.assertEqual((10, len(text)), search.find_offsets(text, lambda t: t.find("find"))) self.assertEqual((0, len(text)), search.find_offsets(text, lambda t: t.find("Trying"))) self.assertEqual(None, search.find_offsets(text, lambda t: t.find("xxxx")))
def find_next_appendix_offsets(text): """Find the start/end of the next appendix. Accounts for supplements""" offsets = search.find_offsets(text, find_appendix_start) if offsets is None: return None start, end = offsets supplement_start = find_supplement_start(text) if supplement_start is not None and supplement_start < start: return None if supplement_start is not None and supplement_start < end: return (start, supplement_start) return (start, end)
def next_subpart_offsets(text): """Find the start,end of the next subpart""" offsets = find_offsets(text, find_next_subpart_start) if offsets is None: return None start, end = offsets appendix_start = find_appendix_start(text) supplement_start = find_supplement_start(text) if appendix_start is not None and appendix_start < end: return (start, appendix_start) if supplement_start is not None and supplement_start < end: return (start, supplement_start) return (start, end)
def next_subpart_offsets(text): """Find the start,end of the next subpart""" offsets = find_offsets(text, find_next_subpart_start) if offsets is None: return None start, end = offsets appendix_start = find_appendix_start(text) supplement_start = find_supplement_start(text) if appendix_start is not None and appendix_start < end: end = appendix_start elif supplement_start is not None and supplement_start < end: end = supplement_start if end >= start: return (start, end)
def next_section_offsets(text, part): """Find the start/end of the next section""" offsets = find_offsets(text, lambda t: find_next_section_start(t, part)) if offsets is None: return None start, end = offsets subpart_start = find_next_subpart_start(text) appendix_start = find_appendix_start(text) supplement_start = find_supplement_start(text) if subpart_start is not None \ and subpart_start > start and subpart_start < end: return (start, subpart_start) if appendix_start is not None and appendix_start < end: return (start, appendix_start) if supplement_start is not None and supplement_start < end: return (start, supplement_start) return (start, end)
def next_section_offsets(text, part): """Find the start/end of the next section""" offsets = find_offsets(text, lambda t: find_next_section_start(t, part)) if offsets is None: return None start, end = offsets subpart_start = find_next_subpart_start(text) appendix_start = find_appendix_start(text) supplement_start = find_supplement_start(text) if subpart_start is not None \ and subpart_start > start and subpart_start < end: end = subpart_start elif appendix_start is not None and appendix_start < end: end = appendix_start elif supplement_start is not None and supplement_start < end: end = supplement_start if end >= start: return (start, end)
def find_next_appendix_section_offsets(text, appendix): """Find the start/end of the next appendix section.""" return search.find_offsets( text, lambda t: find_appendix_section_start( t, appendix))
def find_next_appendix_section_offsets(text, appendix): """Find the start/end of the next appendix section.""" return search.find_offsets( text, lambda t: find_appendix_section_start(t, appendix))