From: David G. <go...@us...> - 2003-07-05 19:34:40
|
Update of /cvsroot/docutils/docutils/docutils In directory sc8-pr-cvs1:/tmp/cvs-serv22435/docutils Modified Files: statemachine.py Log Message: Renamed ``StringList.strip_indent`` to ``.trim_left``. Added ``StringList.get_2D_block``. Index: statemachine.py =================================================================== RCS file: /cvsroot/docutils/docutils/docutils/statemachine.py,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- statemachine.py 29 Jun 2003 04:53:54 -0000 1.14 +++ statemachine.py 5 Jul 2003 19:34:37 -0000 1.15 @@ -1295,11 +1295,11 @@ """A `ViewList` with string-specific methods.""" - def strip_indent(self, length, start=0, end=sys.maxint): + def trim_left(self, length, start=0, end=sys.maxint): """ - Strip `length` characters off the beginning of each item, in-place, + Trim `length` characters off the beginning of each item, in-place, from index `start` to `end`. No whitespace-checking is done on the - stripped text. Does not affect slice parent. + trimmed text. Does not affect slice parent. """ self.data[start:end] = [line[length:] for line in self.data[start:end]] @@ -1382,8 +1382,19 @@ if first_indent is not None and block: block.data[0] = block.data[0][first_indent:] if indent and strip_indent: - block.strip_indent(indent, start=(first_indent is not None)) + block.trim_left(indent, start=(first_indent is not None)) return block, indent or 0, blank_finish + + def get_2D_block(self, top, left, bottom, right, strip_indent=1): + block = self[top:bottom] + indent = right + for i in range(len(block.data)): + block.data[i] = line = block.data[i][left:right].rstrip() + if line: + indent = min(indent, len(line) - len(line.lstrip())) + if strip_indent and 0 < indent < right: + block.data = [line[indent:] for line in block.data] + return block class StateMachineError(Exception): pass |