Author: tilman Date: Mon Feb 12 14:30:48 2024 New Revision: 1915745 URL: http://svn.apache.org/viewvc?rev=1915745&view=rev Log: PDFBOX-5660: introduce StringUtil class for reusable functionality, by Axel Howind
Added: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/util/StringUtil.java (with props) Modified: pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ShowTextWithPositioning.java pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java Modified: pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ShowTextWithPositioning.java URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ShowTextWithPositioning.java?rev=1915745&r1=1915744&r2=1915745&view=diff ============================================================================== --- pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ShowTextWithPositioning.java (original) +++ pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ShowTextWithPositioning.java Mon Feb 12 14:30:48 2024 @@ -30,6 +30,7 @@ import org.apache.pdfbox.pdmodel.font.PD import org.apache.pdfbox.pdmodel.font.PDType0Font; import org.apache.pdfbox.pdmodel.font.encoding.WinAnsiEncoding; import org.apache.pdfbox.util.Matrix; +import org.apache.pdfbox.util.StringUtil; /** * This example shows how to justify a string using the showTextWithPositioning method. First only @@ -92,7 +93,7 @@ public class ShowTextWithPositioning float justifyWidth = pageSize.getWidth() * 1000f - stringWidth; List<Object> text = new ArrayList<Object>(); - String[] parts = message.split("\\s"); + String[] parts = StringUtil.splitOnSpace(message); float spaceWidth = (justifyWidth / (parts.length - 1)) / FONT_SIZE; Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java?rev=1915745&r1=1915744&r2=1915745&view=diff ============================================================================== --- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java (original) +++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java Mon Feb 12 14:30:48 2024 @@ -55,6 +55,7 @@ import org.apache.pdfbox.pdmodel.encrypt import org.apache.pdfbox.pdmodel.encryption.PublicKeyDecryptionMaterial; import org.apache.pdfbox.pdmodel.encryption.SecurityHandler; import org.apache.pdfbox.pdmodel.encryption.StandardDecryptionMaterial; +import org.apache.pdfbox.util.StringUtil; import static org.apache.pdfbox.util.Charsets.ISO_8859_1; @@ -2764,7 +2765,7 @@ public class COSParser extends BaseParse while(true) { String currentLine = readLine(); - String[] splitString = currentLine.split("\\s"); + String[] splitString = StringUtil.splitOnSpace(currentLine); if (splitString.length != 2) { LOG.warn("Unexpected XRefTable Entry: " + currentLine); @@ -2807,7 +2808,7 @@ public class COSParser extends BaseParse } //Ignore table contents currentLine = readLine(); - splitString = currentLine.split("\\s"); + splitString = StringUtil.splitOnSpace(currentLine); if (splitString.length < 3) { LOG.warn("invalid xref line: " + currentLine); Added: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/util/StringUtil.java URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/util/StringUtil.java?rev=1915745&view=auto ============================================================================== --- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/util/StringUtil.java (added) +++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/util/StringUtil.java Mon Feb 12 14:30:48 2024 @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pdfbox.util; + +import java.util.regex.Pattern; + +public final class StringUtil +{ + public static final Pattern PATTERN_SPACE = Pattern.compile("\\s"); + + public static String[] splitOnSpace(String s) + { + return PATTERN_SPACE.split(s); + } +} Propchange: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/util/StringUtil.java ------------------------------------------------------------------------------ svn:eol-style = native