diff options
author | Manuel Mall <manuel@apache.org> | 2006-04-27 15:08:17 +0000 |
---|---|---|
committer | Manuel Mall <manuel@apache.org> | 2006-04-27 15:08:17 +0000 |
commit | 0040a29ecce57798e6947fdb33750a4dba1afea0 (patch) | |
tree | 501628c14f955bac7a8006e81b3155b5e906f57d /src/sandbox/org/apache/fop/render/afp/tools/StringUtils.java | |
parent | 31c92194560170ea22c7537736bbdf2ad5e5aaf6 (diff) | |
download | xmlgraphics-fop-0040a29ecce57798e6947fdb33750a4dba1afea0.tar.gz xmlgraphics-fop-0040a29ecce57798e6947fdb33750a4dba1afea0.zip |
AFP Renderer as per IP clearance (http://mail-archives.apache.org/mod_mbox/xmlgraphics-general/200604.mbox/%3c20060426085421.B456.DEV@jeremias-maerki.ch%3e) plus some further corrections and changes made by manuel@apache.org since
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@397562 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/sandbox/org/apache/fop/render/afp/tools/StringUtils.java')
-rw-r--r-- | src/sandbox/org/apache/fop/render/afp/tools/StringUtils.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/sandbox/org/apache/fop/render/afp/tools/StringUtils.java b/src/sandbox/org/apache/fop/render/afp/tools/StringUtils.java new file mode 100644 index 000000000..67b578446 --- /dev/null +++ b/src/sandbox/org/apache/fop/render/afp/tools/StringUtils.java @@ -0,0 +1,80 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed 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. + */ + +/* $Id$ */ + +package org.apache.fop.render.afp.tools; + +/** + * Library of utility methods useful in dealing with strings. + * + */ +public class StringUtils { + + /** + * Padds the string to the left with the given character for + * the specified length. + * @param input The input string. + * @param padding The char used for padding. + * @param length The length of the new string. + * @return The padded string. + */ + public static String lpad(String input, char padding, int length) { + + if (input == null) { + input = new String(); + } + + if (input.length() >= length) { + return input; + } else { + StringBuffer result = new StringBuffer(); + int numChars = length - input.length(); + for (int i = 0; i < numChars; i++) { + result.append(padding); + } + result.append(input); + return result.toString(); + } + } + + /** + * Padds the string to the right with the given character for + * the specified length. + * @param input The input string. + * @param padding The char used for padding. + * @param length The length of the new string. + * @return The padded string. + */ + public static String rpad(String input, char padding, int length) { + + if (input == null) { + input = new String(); + } + + if (input.length() >= length) { + return input; + } else { + StringBuffer result = new StringBuffer(input); + int numChars = length - input.length(); + for (int i = 0; i < numChars; i++) { + result.append(padding); + } + return result.toString(); + } + } + +}
\ No newline at end of file |