clic.region.utils: Internal utilities for tagging

clic.region.utils.region_append_without_whitespace(book, rclass, start, end, *extra)

Shrink the region (start, end) until there is no whitespace either end of the region. Then if it is non-zero, append the region to (rclass)

Return true iff a region is added.

clic.region.utils.regions_flatten(book)

Flatten a book’s regions down to a single array-of-arrays, suitable for exporting

clic.region.utils.regions_invert(rlist, full_length=None)

Given a list of regions, return the inverse. If full_length not given, ignore first and last extremities

>>> list(regions_invert([], 100))
[(0, 100)]
>>> list(regions_invert([]))
[]
>>> list(regions_invert([(10, 20), (50, 60)], 100))
[(0, 10), (20, 50), (60, 100)]
>>> list(regions_invert([(10, 20), (50, 60)]))
[(20, 50)]
>>> list(regions_invert([(0, 0), (10, 15), (15, 20), (50, 50)], 100))
[(0, 10), (20, 50), (50, 100)]
clic.region.utils.regions_unflatten(regions)

Reverse regions_flatten, return a dict to update a book with. For example:

book.update(regions_unflatten(regions))