RED-6009: Document Tree Structure
This commit is contained in:
parent
f290df40b1
commit
de96e29b09
@ -140,23 +140,23 @@ public class Boundary implements Comparable<Boundary> {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* shrinks the boundary, such that textBlock.subSequence(boundary) returns a string without whitespaces.
|
* shrinks the boundary, such that textBlock.subSequence(boundary) returns a string without trailing or preceding whitespaces.
|
||||||
*
|
*
|
||||||
* @param textBlock TextBlock to check whitespaces against
|
* @param textBlock TextBlock to check whitespaces against
|
||||||
* @return boundary
|
* @return trimmed boundary
|
||||||
*/
|
*/
|
||||||
public Boundary trim(TextBlock textBlock) {
|
public Boundary trim(TextBlock textBlock) {
|
||||||
|
|
||||||
if (textBlock.isEmpty()) {
|
if (this.length() == 0) {
|
||||||
return textBlock.getBoundary();
|
return this;
|
||||||
}
|
}
|
||||||
int trimmedStart = this.start;
|
int trimmedStart = this.start;
|
||||||
while (Character.isWhitespace(textBlock.charAt(trimmedStart))) {
|
while (textBlock.containsIndex(trimmedStart) && trimmedStart < end && Character.isWhitespace(textBlock.charAt(trimmedStart))) {
|
||||||
trimmedStart++;
|
trimmedStart++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int trimmedEnd = this.end;
|
int trimmedEnd = this.end;
|
||||||
while (Character.isWhitespace(textBlock.charAt(trimmedEnd - 1))) {
|
while (textBlock.containsIndex(trimmedEnd - 1) && trimmedStart < trimmedEnd && Character.isWhitespace(textBlock.charAt(trimmedEnd - 1))) {
|
||||||
trimmedEnd--;
|
trimmedEnd--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user