From 5b455cba0b88255f58d1f9e00ab41770678b8828 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Tue, 12 Aug 2014 11:29:51 +0200 Subject: Fixed PDF automatic positioning --- .../at/gv/egiz/pdfas/common/utils/StringUtils.java | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'pdf-as-common/src/main/java/at/gv') diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StringUtils.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StringUtils.java index c110b93d..dbea3c70 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StringUtils.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StringUtils.java @@ -98,4 +98,37 @@ public class StringUtils { String text = new String(replace_bytes, "windows-1252"); return text; } + + public static String whiteSpaceTrim(String string) { + String str = startStrip(string); + return endStrip(str); + } + + private static String startStrip(final String str) { + int strLen; + if (str == null || (strLen = str.length()) == 0) { + return str; + } + int start = 0; + while (start != strLen && isEmptySpace(str.charAt(start))) { + start++; + } + return str.substring(start); + } + + private static String endStrip(final String str) { + int end; + if (str == null || (end = str.length()) == 0) { + return str; + } + while (end != 0 && isEmptySpace(str.charAt(end - 1))) { + end++; + } + + return str.substring(0, end); + } + + private static boolean isEmptySpace(char c) { + return Character.isWhitespace(c) || Character.isSpaceChar(c); + } } -- cgit v1.2.3