MCPcopy Create free account
hub / github.com/GraxCode/zelixkiller / replace

Method replace

src/me/lpk/util/StringUtils.java:85–115  ·  view source on GitHub ↗

Replaces strings with old references with ones with updated references. @param orig @param oldStr @param newStr @return

(String orig, String oldStr, String newStr)

Source from the content-addressed store, hash-verified

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)) {

Callers 15

createProxyMethod · 0.80
transformMethod · 0.80
removeDynamicCallsMethod · 0.80
getOriginalNodeMethod · 0.80
preTransformMethod · 0.80
preTransformMethod · 0.80
treatAsInnerMethod · 0.80
createProxyMethod · 0.80
getTypesFromMemberMethod · 0.80
addFieldMethod · 0.80
addMethodMethod · 0.80
saveMethod · 0.80

Calls 3

containsMethod · 0.95
toStringMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected