1 19 package org.webdocwf.util.loader.generator; 20 21 22 27 28 public class Utils { 29 30 37 public static String replaceAll(String input, String forReplace, 38 String replaceWith) { 39 StringBuffer result = new StringBuffer (); 40 boolean hasMore = true; 41 while (hasMore) { 42 int start = input.indexOf(forReplace); 43 int end = start + forReplace.length(); 44 if (start != -1) { 45 result.append(input.substring(0, start) + replaceWith); 46 input = input.substring(end); 47 } 48 else { 49 hasMore = false; 50 result.append(input); 51 } 52 } 53 if (result.toString().equals("")) 54 return input; else 56 return result.toString(); 57 } 58 59 60 public static String handleQuotedString(String quotedString) { 61 String retVal = quotedString; 62 if ( (retVal.startsWith("'") && retVal.endsWith("'"))) { 63 if (!retVal.equals("''")) { 64 retVal = retVal.substring(retVal.indexOf("'") + 1, 65 retVal.lastIndexOf("'")); 66 } 67 else { 68 retVal = ""; 69 } 70 } 71 return retVal; 72 } 73 74 public static String [] replaceLineBrakesAndCarrReturn( 75 String [] toReplace, 76 String lineBreakEscape, 77 String carriageReturnEscape) { 78 String [] retVal = new String [toReplace.length]; 79 for (int i = 0; i < toReplace.length; i++) { 80 if (toReplace[i] != null) { 81 retVal[i] = replaceAll(toReplace[i], "\n", lineBreakEscape); 82 retVal[i] = replaceAll(retVal[i], "\r", carriageReturnEscape); 83 } 84 } 85 return retVal; 86 } 87 88 89 90 91 92 } | Popular Tags |