1 17 18 19 20 package org.apache.fop.render.afp.tools; 21 22 26 public class StringUtils { 27 28 36 public static String lpad(String input, char padding, int length) { 37 38 if (input == null) { 39 input = new String (); 40 } 41 42 if (input.length() >= length) { 43 return input; 44 } else { 45 StringBuffer result = new StringBuffer (); 46 int numChars = length - input.length(); 47 for (int i = 0; i < numChars; i++) { 48 result.append(padding); 49 } 50 result.append(input); 51 return result.toString(); 52 } 53 } 54 55 63 public static String rpad(String input, char padding, int length) { 64 65 if (input == null) { 66 input = new String (); 67 } 68 69 if (input.length() >= length) { 70 return input; 71 } else { 72 StringBuffer result = new StringBuffer (input); 73 int numChars = length - input.length(); 74 for (int i = 0; i < numChars; i++) { 75 result.append(padding); 76 } 77 return result.toString(); 78 } 79 } 80 81 } | Popular Tags |