forked from jasder/antlr
Remove unnecessary method Utils.replace (already exists as String.replace)
This commit is contained in:
parent
c46bce3251
commit
3d59e47fb4
|
@ -211,9 +211,9 @@ public class CommonToken implements WritableToken, Serializable {
|
|||
}
|
||||
String txt = getText();
|
||||
if ( txt!=null ) {
|
||||
txt = txt.replaceAll("\n","\\\\n");
|
||||
txt = txt.replaceAll("\r","\\\\r");
|
||||
txt = txt.replaceAll("\t","\\\\t");
|
||||
txt = txt.replace("\n","\\n");
|
||||
txt = txt.replace("\r","\\r");
|
||||
txt = txt.replace("\t","\\t");
|
||||
}
|
||||
else {
|
||||
txt = "<no text>";
|
||||
|
|
|
@ -431,9 +431,9 @@ public class DefaultErrorStrategy implements ANTLRErrorStrategy {
|
|||
|
||||
protected String escapeWSAndQuote(String s) {
|
||||
// if ( s==null ) return s;
|
||||
s = s.replaceAll("\n","\\\\n");
|
||||
s = s.replaceAll("\r","\\\\r");
|
||||
s = s.replaceAll("\t","\\\\t");
|
||||
s = s.replace("\n","\\n");
|
||||
s = s.replace("\r","\\r");
|
||||
s = s.replace("\t","\\t");
|
||||
return "'"+s+"'";
|
||||
}
|
||||
|
||||
|
|
|
@ -100,9 +100,9 @@ public abstract class Recognizer<Symbol, ATNInterpreter extends ATNSimulator> {
|
|||
s = "<"+t.getType()+">";
|
||||
}
|
||||
}
|
||||
s = s.replaceAll("\n","\\\\n");
|
||||
s = s.replaceAll("\r","\\\\r");
|
||||
s = s.replaceAll("\t","\\\\t");
|
||||
s = s.replace("\n","\\n");
|
||||
s = s.replace("\r","\\r");
|
||||
s = s.replace("\t","\\t");
|
||||
return "'"+s+"'";
|
||||
}
|
||||
|
||||
|
|
|
@ -89,31 +89,6 @@ public class Utils {
|
|||
return buf.toString();
|
||||
}
|
||||
|
||||
/** Given a source string, src,
|
||||
a string to replace, replacee,
|
||||
and a string to replace with, replacer,
|
||||
return a new string w/ the replacing done.
|
||||
You can use replacer==null to remove replacee from the string.
|
||||
|
||||
This should be faster than Java's String.replaceAll as that one
|
||||
uses regex (I only want to play with strings anyway).
|
||||
*/
|
||||
public static String replace(String src, String replacee, String replacer) {
|
||||
StringBuilder result = new StringBuilder(src.length() + 50);
|
||||
int startIndex = 0;
|
||||
int endIndex = src.indexOf(replacee);
|
||||
while(endIndex != -1) {
|
||||
result.append(src.substring(startIndex,endIndex));
|
||||
if ( replacer!=null ) {
|
||||
result.append(replacer);
|
||||
}
|
||||
startIndex = endIndex + replacee.length();
|
||||
endIndex = src.indexOf(replacee,startIndex);
|
||||
}
|
||||
result.append(src.substring(startIndex,src.length()));
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String sortLinesInString(String s) {
|
||||
String lines[] = s.split("\n");
|
||||
Arrays.sort(lines);
|
||||
|
|
|
@ -181,9 +181,7 @@ public class BuildDependencyGenerator {
|
|||
}
|
||||
|
||||
if (outputDir.getName().indexOf(' ') >= 0) { // has spaces?
|
||||
String escSpaces = Utils.replace(outputDir.toString(),
|
||||
" ",
|
||||
"\\ ");
|
||||
String escSpaces = outputDir.toString().replace(" ", "\\ ");
|
||||
outputDir = new File(escSpaces);
|
||||
}
|
||||
return new File(outputDir, fileName);
|
||||
|
@ -266,9 +264,7 @@ public class BuildDependencyGenerator {
|
|||
return fileName;
|
||||
}
|
||||
else if (outputDir.indexOf(' ') >= 0) { // has spaces?
|
||||
String escSpaces = Utils.replace(outputDir,
|
||||
" ",
|
||||
"\\ ");
|
||||
String escSpaces = outputDir.replace(" ", "\\ ");
|
||||
return escSpaces + File.separator + fileName;
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -441,10 +441,10 @@ public class DOTGenerator {
|
|||
* generate any gated predicates on edge too.
|
||||
*/
|
||||
protected String getEdgeLabel(String label) {
|
||||
label = Utils.replace(label,"\\", "\\\\");
|
||||
label = Utils.replace(label,"\"", "\\\"");
|
||||
label = Utils.replace(label,"\n", "\\\\n");
|
||||
label = Utils.replace(label,"\r", "");
|
||||
label = label.replace("\\", "\\\\");
|
||||
label = label.replace("\"", "\\\"");
|
||||
label = label.replace("\n", "\\\\n");
|
||||
label = label.replace("\r", "");
|
||||
return label;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ public class DefaultToolListener implements ANTLRToolListener {
|
|||
@Override
|
||||
public void info(String msg) {
|
||||
if (tool.errMgr.formatWantsSingleLineMessage()) {
|
||||
msg = msg.replaceAll("\n", " ");
|
||||
msg = msg.replace('\n', ' ');
|
||||
}
|
||||
System.out.println(msg);
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class DefaultToolListener implements ANTLRToolListener {
|
|||
ST msgST = tool.errMgr.getMessageTemplate(msg);
|
||||
String outputMsg = msgST.render();
|
||||
if (tool.errMgr.formatWantsSingleLineMessage()) {
|
||||
outputMsg = outputMsg.replaceAll("\n", " ");
|
||||
outputMsg = outputMsg.replace('\n', ' ');
|
||||
}
|
||||
System.err.println(outputMsg);
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ public class DefaultToolListener implements ANTLRToolListener {
|
|||
ST msgST = tool.errMgr.getMessageTemplate(msg);
|
||||
String outputMsg = msgST.render();
|
||||
if (tool.errMgr.formatWantsSingleLineMessage()) {
|
||||
outputMsg = outputMsg.replaceAll("\n", " ");
|
||||
outputMsg = outputMsg.replace('\n', ' ');
|
||||
}
|
||||
System.err.println(outputMsg);
|
||||
}
|
||||
|
|
|
@ -687,9 +687,9 @@ public abstract class BaseTest {
|
|||
String actual = equeue.toString(g != null ? g.tool : new Tool());
|
||||
System.err.println(actual);
|
||||
String msg = input;
|
||||
msg = msg.replaceAll("\n","\\\\n");
|
||||
msg = msg.replaceAll("\r","\\\\r");
|
||||
msg = msg.replaceAll("\t","\\\\t");
|
||||
msg = msg.replace("\n","\\n");
|
||||
msg = msg.replace("\r","\\r");
|
||||
msg = msg.replace("\t","\\t");
|
||||
|
||||
assertEquals("error in: "+msg,expect,actual);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue