Replaces strings with old references with ones with updated references. @param orig @param oldStr @param newStr @return
(String orig, String oldStr, String newStr)
| 83 | * @return |
| 84 | */ |
| 85 | public static String replace(String orig, String oldStr, String newStr) { |
| 86 | StringBuffer sb = new StringBuffer(orig); |
| 87 | while (contains(sb.toString(), oldStr)) { |
| 88 | if (orig.contains("(") && orig.contains(";")) { |
| 89 | // orig is most likely a method desc |
| 90 | int start = sb.indexOf("L" + oldStr) + 1; |
| 91 | int end = sb.indexOf(oldStr + ";") + oldStr.length(); |
| 92 | if (start > -1 && end <= orig.length()) { |
| 93 | sb.replace(start, end, newStr); |
| 94 | } else { |
| 95 | System.err.println("REPLACE FAIL: (" + oldStr + ") - " + orig); |
| 96 | break; |
| 97 | } |
| 98 | } else if (orig.startsWith("L") && orig.endsWith(";")) { |
| 99 | // orig is most likely a class desc |
| 100 | if (orig.substring(1, orig.length() - 1).equals(oldStr)) { |
| 101 | sb.replace(1, orig.length() - 1, newStr); |
| 102 | } |
| 103 | } else { |
| 104 | // Dunno |
| 105 | if (orig.equals(oldStr)) { |
| 106 | sb.replace(0, sb.length(), newStr); |
| 107 | } else { |
| 108 | // This shouldn't happen. |
| 109 | System.err.println("FUCK: (" + sb.toString() + ") - " + oldStr + ":" + newStr); |
| 110 | break; |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | return sb.toString(); |
| 115 | } |
| 116 | |
| 117 | public static boolean contains(String orig, String check) { |
| 118 | if (orig.contains(check)) { |
no test coverage detected