From de96e29b0939933ebfeedb77f535e330e4878493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kilian=20Sch=C3=BCttler?= Date: Thu, 15 Jun 2023 22:11:48 +0200 Subject: [PATCH] RED-6009: Document Tree Structure --- .../layoutparsing/document/graph/Boundary.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/graph/Boundary.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/graph/Boundary.java index 845ce384..835c08b3 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/graph/Boundary.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/layoutparsing/document/graph/Boundary.java @@ -140,23 +140,23 @@ public class Boundary implements Comparable { /** - * 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 - * @return boundary + * @return trimmed boundary */ public Boundary trim(TextBlock textBlock) { - if (textBlock.isEmpty()) { - return textBlock.getBoundary(); + if (this.length() == 0) { + return this; } int trimmedStart = this.start; - while (Character.isWhitespace(textBlock.charAt(trimmedStart))) { + while (textBlock.containsIndex(trimmedStart) && trimmedStart < end && Character.isWhitespace(textBlock.charAt(trimmedStart))) { trimmedStart++; } 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--; }