提交 fd31e277 authored 作者: Thomas Mueller's avatar Thomas Mueller

StringUtils.replaceAllIgnoreCase

上级 19633328
...@@ -10,7 +10,6 @@ import java.sql.Connection; ...@@ -10,7 +10,6 @@ import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.DriverPropertyInfo; import java.sql.DriverPropertyInfo;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Locale;
import java.util.Properties; import java.util.Properties;
import org.h2.engine.Constants; import org.h2.engine.Constants;
...@@ -58,8 +57,8 @@ public class Driver implements java.sql.Driver { ...@@ -58,8 +57,8 @@ public class Driver implements java.sql.Driver {
if (!acceptsURL(url)) { if (!acceptsURL(url)) {
return null; return null;
} }
boolean noUpgrade = url.toUpperCase(Locale.ENGLISH).contains(";NO_UPGRADE=TRUE"); boolean noUpgrade = StringUtils.toUpperEnglish(url).indexOf(";NO_UPGRADE=TRUE") >= 0;
url = StringUtils.replaceAll(url, ";NO_UPGRADE=TRUE", "", true); url = StringUtils.replaceAllIgnoreCase(url, ";NO_UPGRADE=TRUE", "");
if (DbUpgrade.areV1dot1ClassesPresent()) { if (DbUpgrade.areV1dot1ClassesPresent()) {
if (noUpgrade) { if (noUpgrade) {
Connection connection = DbUpgrade.connectWithOldVersion(url, info); Connection connection = DbUpgrade.connectWithOldVersion(url, info);
......
...@@ -230,21 +230,21 @@ public class Bnf { ...@@ -230,21 +230,21 @@ public class Bnf {
private String[] tokenize() { private String[] tokenize() {
ArrayList<String> list = New.arrayList(); ArrayList<String> list = New.arrayList();
syntax = StringUtils.replaceAll(syntax, "yyyy-MM-dd", "@ymd@", false); syntax = StringUtils.replaceAll(syntax, "yyyy-MM-dd", "@ymd@");
syntax = StringUtils.replaceAll(syntax, "hh:mm:ss", "@hms@", false); syntax = StringUtils.replaceAll(syntax, "hh:mm:ss", "@hms@");
syntax = StringUtils.replaceAll(syntax, "nnnnnnnnn", "@nanos@", false); syntax = StringUtils.replaceAll(syntax, "nnnnnnnnn", "@nanos@");
syntax = StringUtils.replaceAll(syntax, "function", "@func@", false); syntax = StringUtils.replaceAll(syntax, "function", "@func@");
syntax = StringUtils.replaceAll(syntax, "0x", "@hexStart@", false); syntax = StringUtils.replaceAll(syntax, "0x", "@hexStart@");
syntax = StringUtils.replaceAll(syntax, ",...", "@commaDots@", false); syntax = StringUtils.replaceAll(syntax, ",...", "@commaDots@");
syntax = StringUtils.replaceAll(syntax, "...", "@dots@", false); syntax = StringUtils.replaceAll(syntax, "...", "@dots@");
syntax = StringUtils.replaceAll(syntax, "||", "@concat@", false); syntax = StringUtils.replaceAll(syntax, "||", "@concat@");
syntax = StringUtils.replaceAll(syntax, "a-z|_", "@az_@", false); syntax = StringUtils.replaceAll(syntax, "a-z|_", "@az_@");
syntax = StringUtils.replaceAll(syntax, "A-Z|_", "@az_@", false); syntax = StringUtils.replaceAll(syntax, "A-Z|_", "@az_@");
syntax = StringUtils.replaceAll(syntax, "a-f", "@af@", false); syntax = StringUtils.replaceAll(syntax, "a-f", "@af@");
syntax = StringUtils.replaceAll(syntax, "A-F", "@af@", false); syntax = StringUtils.replaceAll(syntax, "A-F", "@af@");
syntax = StringUtils.replaceAll(syntax, "0-9", "@digit@", false); syntax = StringUtils.replaceAll(syntax, "0-9", "@digit@");
syntax = StringUtils.replaceAll(syntax, "'['", "@openBracket@", false); syntax = StringUtils.replaceAll(syntax, "'['", "@openBracket@");
syntax = StringUtils.replaceAll(syntax, "']'", "@closeBracket@", false); syntax = StringUtils.replaceAll(syntax, "']'", "@closeBracket@");
StringTokenizer tokenizer = getTokenizer(syntax); StringTokenizer tokenizer = getTokenizer(syntax);
while (tokenizer.hasMoreTokens()) { while (tokenizer.hasMoreTokens()) {
String s = tokenizer.nextToken(); String s = tokenizer.nextToken();
......
...@@ -2380,7 +2380,7 @@ public class Parser { ...@@ -2380,7 +2380,7 @@ public class Parser {
String text = currentValue.getString(); String text = currentValue.getString();
// the PostgreSQL ODBC driver uses // the PostgreSQL ODBC driver uses
// LIKE E'PROJECT\\_DATA' instead of LIKE 'PROJECT\_DATA' // LIKE E'PROJECT\\_DATA' instead of LIKE 'PROJECT\_DATA'
text = StringUtils.replaceAll(text, "\\\\", "\\", false); text = StringUtils.replaceAll(text, "\\\\", "\\");
read(); read();
r = ValueExpression.get(ValueString.get(text)); r = ValueExpression.get(ValueString.get(text));
} else { } else {
......
...@@ -63,7 +63,7 @@ public class CreateFunctionAlias extends SchemaCommand { ...@@ -63,7 +63,7 @@ public class CreateFunctionAlias extends SchemaCommand {
* @param method the qualified method name * @param method the qualified method name
*/ */
public void setJavaClassMethod(String method) { public void setJavaClassMethod(String method) {
this.javaClassMethod = StringUtils.replaceAll(method, " ", "", false); this.javaClassMethod = StringUtils.replaceAll(method, " ", "");
} }
public void setIfNotExists(boolean ifNotExists) { public void setIfNotExists(boolean ifNotExists) {
......
...@@ -304,9 +304,9 @@ public class WebApp { ...@@ -304,9 +304,9 @@ public class WebApp {
value = space + value; value = space + value;
} }
key = StringUtils.urlEncode(key); key = StringUtils.urlEncode(key);
key = StringUtils.replaceAll(key, "+", " ", false); key = StringUtils.replaceAll(key, "+", " ");
value = StringUtils.urlEncode(value); value = StringUtils.urlEncode(value);
value = StringUtils.replaceAll(value, "+", " ", false); value = StringUtils.replaceAll(value, "+", " ");
list.add(type + "#" + key + "#" + value); list.add(type + "#" + key + "#" + value);
} }
Collections.sort(list); Collections.sort(list);
...@@ -738,7 +738,7 @@ public class WebApp { ...@@ -738,7 +738,7 @@ public class WebApp {
if (isH2) { if (isH2) {
stackTrace = linkToSource(stackTrace); stackTrace = linkToSource(stackTrace);
} }
stackTrace = StringUtils.replaceAll(stackTrace, "\t", "&nbsp;&nbsp;&nbsp;&nbsp;", false); stackTrace = StringUtils.replaceAll(stackTrace, "\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
String message = PageParser.escapeHtml(e.getMessage()); String message = PageParser.escapeHtml(e.getMessage());
String error = "<a class=\"error\" href=\"#\" onclick=\"var x=document.getElementById('st" + id String error = "<a class=\"error\" href=\"#\" onclick=\"var x=document.getElementById('st" + id
+ "').style;x.display=x.display==''?'none':'';\">" + message + "</a>"; + "').style;x.display=x.display==''?'none':'';\">" + message + "</a>";
......
...@@ -221,9 +221,9 @@ public class RunScript extends Tool { ...@@ -221,9 +221,9 @@ public class RunScript extends Tool {
for (int i = 0; i < columns; i++) { for (int i = 0; i < columns; i++) {
String s = rs.getString(i + 1); String s = rs.getString(i + 1);
if (s != null) { if (s != null) {
s = StringUtils.replaceAll(s, "\r\n", "\n", false); s = StringUtils.replaceAll(s, "\r\n", "\n");
s = StringUtils.replaceAll(s, "\n", "\n--> ", false); s = StringUtils.replaceAll(s, "\n", "\n--> ");
s = StringUtils.replaceAll(s, "\r", "\r--> ", false); s = StringUtils.replaceAll(s, "\r", "\r--> ");
} }
buff.append(' ').append(s); buff.append(' ').append(s);
} }
...@@ -235,11 +235,11 @@ public class RunScript extends Tool { ...@@ -235,11 +235,11 @@ public class RunScript extends Tool {
} }
if (checkResults) { if (checkResults) {
String expected = r.readStatement() + ";"; String expected = r.readStatement() + ";";
expected = StringUtils.replaceAll(expected, "\r\n", "\n", false); expected = StringUtils.replaceAll(expected, "\r\n", "\n");
expected = StringUtils.replaceAll(expected, "\r", "\n", false); expected = StringUtils.replaceAll(expected, "\r", "\n");
if (!expected.equals(result)) { if (!expected.equals(result)) {
expected = StringUtils.replaceAll(expected, " ", "+", false); expected = StringUtils.replaceAll(expected, " ", "+");
result = StringUtils.replaceAll(result, " ", "+", false); result = StringUtils.replaceAll(result, " ", "+");
throw new SQLException("Unexpected output for:\n" + sql.trim() + "\nGot:\n" + result + "\nExpected:\n" + expected); throw new SQLException("Unexpected output for:\n" + sql.trim() + "\nGot:\n" + result + "\nExpected:\n" + expected);
} }
} }
......
...@@ -473,7 +473,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -473,7 +473,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
if (browser.indexOf("%url") >= 0) { if (browser.indexOf("%url") >= 0) {
String[] args = StringUtils.arraySplit(browser, ',', false); String[] args = StringUtils.arraySplit(browser, ',', false);
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
args[i] = StringUtils.replaceAll(args[i], "%url", url, false); args[i] = StringUtils.replaceAll(args[i], "%url", url);
} }
rt.exec(args); rt.exec(args);
} else if (osName.indexOf("windows") >= 0) { } else if (osName.indexOf("windows") >= 0) {
......
...@@ -56,10 +56,10 @@ public class DbUpgrade { ...@@ -56,10 +56,10 @@ public class DbUpgrade {
public static Connection connectWithOldVersion(String url, Properties info) throws SQLException { public static Connection connectWithOldVersion(String url, Properties info) throws SQLException {
try { try {
String oldStartUrlPrefix = (String) Utils.getStaticField("org.h2.upgrade.v1_1.engine.Constants.START_URL"); String oldStartUrlPrefix = (String) Utils.getStaticField("org.h2.upgrade.v1_1.engine.Constants.START_URL");
url = StringUtils.replaceAll(url, org.h2.engine.Constants.START_URL, oldStartUrlPrefix, false); url = StringUtils.replaceAll(url, org.h2.engine.Constants.START_URL, oldStartUrlPrefix);
url = StringUtils.replaceAll(url, ";IGNORE_UNKNOWN_SETTINGS=TRUE", "", true); url = StringUtils.replaceAllIgnoreCase(url, ";IGNORE_UNKNOWN_SETTINGS=TRUE", "");
url = StringUtils.replaceAll(url, ";IGNORE_UNKNOWN_SETTINGS=FALSE", "", true); url = StringUtils.replaceAllIgnoreCase(url, ";IGNORE_UNKNOWN_SETTINGS=FALSE", "");
url = StringUtils.replaceAll(url, ";PAGE_STORE=TRUE", "", true); url = StringUtils.replaceAllIgnoreCase(url, ";PAGE_STORE=TRUE", "");
url += ";IGNORE_UNKNOWN_SETTINGS=TRUE"; url += ";IGNORE_UNKNOWN_SETTINGS=TRUE";
Object ci = Utils.newInstance("org.h2.upgrade.v1_1.engine.ConnectionInfo", url, info); Object ci = Utils.newInstance("org.h2.upgrade.v1_1.engine.ConnectionInfo", url, info);
boolean isRemote = (Boolean) Utils.callMethod(ci, "isRemote"); boolean isRemote = (Boolean) Utils.callMethod(ci, "isRemote");
......
...@@ -62,17 +62,17 @@ public class DbUpgradeNonPageStoreToCurrent { ...@@ -62,17 +62,17 @@ public class DbUpgradeNonPageStoreToCurrent {
private void init() throws SQLException { private void init() throws SQLException {
try { try {
newUrl = url; newUrl = url;
newUrl = StringUtils.replaceAll(newUrl, ";UNDO_LOG=1", "", true); newUrl = StringUtils.replaceAllIgnoreCase(newUrl, ";UNDO_LOG=1", "");
newUrl = StringUtils.replaceAll(newUrl, ";UNDO_LOG=0", "", true); newUrl = StringUtils.replaceAllIgnoreCase(newUrl, ";UNDO_LOG=0", "");
newUrl += ";UNDO_LOG=0"; newUrl += ";UNDO_LOG=0";
String oldStartUrlPrefix = (String) Utils.getStaticField("org.h2.upgrade.v1_1.engine.Constants.START_URL"); String oldStartUrlPrefix = (String) Utils.getStaticField("org.h2.upgrade.v1_1.engine.Constants.START_URL");
oldUrl = url; oldUrl = url;
oldUrl = StringUtils.replaceAll(oldUrl, org.h2.engine.Constants.START_URL, oldStartUrlPrefix, false); oldUrl = StringUtils.replaceAll(oldUrl, org.h2.engine.Constants.START_URL, oldStartUrlPrefix);
oldUrl = StringUtils.replaceAll(oldUrl, ";IGNORE_UNKNOWN_SETTINGS=TRUE", "", true); oldUrl = StringUtils.replaceAllIgnoreCase(oldUrl, ";IGNORE_UNKNOWN_SETTINGS=TRUE", "");
oldUrl = StringUtils.replaceAll(oldUrl, ";IGNORE_UNKNOWN_SETTINGS=FALSE", "", true); oldUrl = StringUtils.replaceAllIgnoreCase(oldUrl, ";IGNORE_UNKNOWN_SETTINGS=FALSE", "");
oldUrl = StringUtils.replaceAll(oldUrl, ";IFEXISTS=TRUE", "", true); oldUrl = StringUtils.replaceAllIgnoreCase(oldUrl, ";IFEXISTS=TRUE", "");
oldUrl = StringUtils.replaceAll(oldUrl, ";IFEXISTS=FALSE", "", true); oldUrl = StringUtils.replaceAllIgnoreCase(oldUrl, ";IFEXISTS=FALSE", "");
oldUrl = StringUtils.replaceAll(oldUrl, ";PAGE_STORE=TRUE", "", true); oldUrl = StringUtils.replaceAllIgnoreCase(oldUrl, ";PAGE_STORE=TRUE", "");
oldUrl += ";IGNORE_UNKNOWN_SETTINGS=TRUE"; oldUrl += ";IGNORE_UNKNOWN_SETTINGS=TRUE";
Object ci = Utils.newInstance("org.h2.upgrade.v1_1.engine.ConnectionInfo", oldUrl, info); Object ci = Utils.newInstance("org.h2.upgrade.v1_1.engine.ConnectionInfo", oldUrl, info);
boolean isRemote = (Boolean) Utils.callMethod(ci, "isRemote"); boolean isRemote = (Boolean) Utils.callMethod(ci, "isRemote");
......
...@@ -146,7 +146,7 @@ public class JdbcUtils { ...@@ -146,7 +146,7 @@ public class JdbcUtils {
if (pattern == null || pattern.length() == 0) { if (pattern == null || pattern.length() == 0) {
return pattern; return pattern;
} }
return StringUtils.replaceAll(pattern, "\\", "\\\\", false); return StringUtils.replaceAll(pattern, "\\", "\\\\");
} }
/** /**
......
...@@ -210,7 +210,7 @@ public class SourceCompiler { ...@@ -210,7 +210,7 @@ public class SourceCompiler {
private void throwSyntaxError(ByteArrayOutputStream out) { private void throwSyntaxError(ByteArrayOutputStream out) {
String err = StringUtils.utf8Decode(out.toByteArray()); String err = StringUtils.utf8Decode(out.toByteArray());
if (err.length() > 0) { if (err.length() > 0) {
err = StringUtils.replaceAll(err, compileDir, "", false); err = StringUtils.replaceAll(err, compileDir, "");
throw DbException.get(ErrorCode.SYNTAX_ERROR_1, err); throw DbException.get(ErrorCode.SYNTAX_ERROR_1, err);
} }
} }
......
...@@ -697,18 +697,27 @@ public class StringUtils { ...@@ -697,18 +697,27 @@ public class StringUtils {
* @param s the string * @param s the string
* @param before the old text * @param before the old text
* @param after the new text * @param after the new text
* @param caseInsensitive true if it should be case insensitive
* @return the string with the before string replaced * @return the string with the before string replaced
*/ */
public static String replaceAll(String s, String before, String after, boolean caseInsensitive) { public static String replaceAll(String s, String before, String after) {
String testString; return replaceAll(s, s, before, after);
if (caseInsensitive) { }
testString = s.toLowerCase(Locale.ENGLISH);
before = before.toLowerCase(Locale.ENGLISH); /**
} else { * Replace all occurrences of the "before" string with the "after" string.
testString = s; * A case-insensitive comparison is made.
} *
int next = testString.indexOf(before); * @param s the string
* @param before the old text
* @param after the new text
* @return the string with the before string replaced
*/
public static String replaceAllIgnoreCase(String s, String before, String after) {
return replaceAll(s, toUpperEnglish(s), toUpperEnglish(before), after);
}
private static String replaceAll(String s, String test, String before, String after) {
int next = test.indexOf(before);
if (next < 0) { if (next < 0) {
return s; return s;
} }
...@@ -717,7 +726,7 @@ public class StringUtils { ...@@ -717,7 +726,7 @@ public class StringUtils {
while (true) { while (true) {
buff.append(s.substring(index, next)).append(after); buff.append(s.substring(index, next)).append(after);
index = next + before.length(); index = next + before.length();
next = testString.indexOf(before, index); next = test.indexOf(before, index);
if (next < 0) { if (next < 0) {
buff.append(s.substring(index)); buff.append(s.substring(index));
break; break;
...@@ -763,8 +772,8 @@ public class StringUtils { ...@@ -763,8 +772,8 @@ public class StringUtils {
* @return the resulting string * @return the resulting string
*/ */
public static String quoteRemarkSQL(String sql) { public static String quoteRemarkSQL(String sql) {
sql = replaceAll(sql, "*/", "++/", false); sql = replaceAll(sql, "*/", "++/");
return replaceAll(sql, "/*", "/++", false); return replaceAll(sql, "/*", "/++");
} }
/** /**
......
...@@ -63,18 +63,18 @@ public class Newsfeed { ...@@ -63,18 +63,18 @@ public class Newsfeed {
*/ */
private static String convertHtml2Text(String html) { private static String convertHtml2Text(String html) {
String s = html; String s = html;
s = StringUtils.replaceAll(s, "<b>", "", false); s = StringUtils.replaceAll(s, "<b>", "");
s = StringUtils.replaceAll(s, "</b>", "", false); s = StringUtils.replaceAll(s, "</b>", "");
s = StringUtils.replaceAll(s, "<ul>", "", false); s = StringUtils.replaceAll(s, "<ul>", "");
s = StringUtils.replaceAll(s, "</ul>", "", false); s = StringUtils.replaceAll(s, "</ul>", "");
s = StringUtils.replaceAll(s, "<li>", "- ", false); s = StringUtils.replaceAll(s, "<li>", "- ");
s = StringUtils.replaceAll(s, "</li>", "", false); s = StringUtils.replaceAll(s, "</li>", "");
s = StringUtils.replaceAll(s, "<a href=\"", "( ", false); s = StringUtils.replaceAll(s, "<a href=\"", "( ");
s = StringUtils.replaceAll(s, "\">", " ) ", false); s = StringUtils.replaceAll(s, "\">", " ) ");
s = StringUtils.replaceAll(s, "</a>", "", false); s = StringUtils.replaceAll(s, "</a>", "");
s = StringUtils.replaceAll(s, "<br />", "", false); s = StringUtils.replaceAll(s, "<br />", "");
s = StringUtils.replaceAll(s, "<br/>", "", false); s = StringUtils.replaceAll(s, "<br/>", "");
s = StringUtils.replaceAll(s, "<br>", "", false); s = StringUtils.replaceAll(s, "<br>", "");
if (s.indexOf('<') >= 0 || s.indexOf('>') >= 0) { if (s.indexOf('<') >= 0 || s.indexOf('>') >= 0) {
throw new RuntimeException("Unsupported HTML Tag: < or > in " + s); throw new RuntimeException("Unsupported HTML Tag: < or > in " + s);
} }
......
...@@ -247,7 +247,7 @@ class Database { ...@@ -247,7 +247,7 @@ class Database {
String key = (String) k; String key = (String) k;
if (key.startsWith(databaseType + ".")) { if (key.startsWith(databaseType + ".")) {
String pattern = key.substring(databaseType.length() + 1); String pattern = key.substring(databaseType.length() + 1);
pattern = StringUtils.replaceAll(pattern, "_", " ", false); pattern = StringUtils.replaceAll(pattern, "_", " ");
pattern = StringUtils.toUpperEnglish(pattern); pattern = StringUtils.toUpperEnglish(pattern);
String replacement = prop.getProperty(key); String replacement = prop.getProperty(key);
replace.add(new String[]{pattern, replacement}); replace.add(new String[]{pattern, replacement});
...@@ -270,7 +270,7 @@ class Database { ...@@ -270,7 +270,7 @@ class Database {
for (String[] pair : replace) { for (String[] pair : replace) {
String pattern = pair[0]; String pattern = pair[0];
String replacement = pair[1]; String replacement = pair[1];
sql = StringUtils.replaceAll(sql, pattern, replacement, false); sql = StringUtils.replaceAll(sql, pattern, replacement);
} }
return sql; return sql;
} }
......
...@@ -208,7 +208,7 @@ public class TestCsv extends TestBase { ...@@ -208,7 +208,7 @@ public class TestCsv extends TestBase {
stat.execute("call csvwrite('"+fileName+"', 'select 1 id, ''Hello'' name', null, '|', '', null, null, chr(10))"); stat.execute("call csvwrite('"+fileName+"', 'select 1 id, ''Hello'' name', null, '|', '', null, null, chr(10))");
InputStreamReader reader = new InputStreamReader(IOUtils.openFileInputStream(fileName)); InputStreamReader reader = new InputStreamReader(IOUtils.openFileInputStream(fileName));
String text = IOUtils.readStringAndClose(reader, -1).trim(); String text = IOUtils.readStringAndClose(reader, -1).trim();
text = StringUtils.replaceAll(text, "\n", " ", false); text = StringUtils.replaceAll(text, "\n", " ");
assertEquals("ID|NAME 1|Hello", text); assertEquals("ID|NAME 1|Hello", text);
ResultSet rs = stat.executeQuery("select * from csvread('" + fileName + "', null, null, '|', '')"); ResultSet rs = stat.executeQuery("select * from csvread('" + fileName + "', null, null, '|', '')");
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
......
...@@ -92,7 +92,7 @@ public class TestSampleApps extends TestBase { ...@@ -92,7 +92,7 @@ public class TestSampleApps extends TestBase {
System.setOut(oldOut); System.setOut(oldOut);
System.setErr(oldErr); System.setErr(oldErr);
String s = new String(buff.toByteArray(), "UTF-8"); String s = new String(buff.toByteArray(), "UTF-8");
s = StringUtils.replaceAll(s, "\r\n", "\n", false); s = StringUtils.replaceAll(s, "\r\n", "\n");
s = s.trim(); s = s.trim();
expected = expected.trim(); expected = expected.trim();
if (expected.endsWith("*")) { if (expected.endsWith("*")) {
......
...@@ -169,19 +169,19 @@ public class TestStringUtils extends TestBase { ...@@ -169,19 +169,19 @@ public class TestStringUtils extends TestBase {
} }
private void testReplaceAll() { private void testReplaceAll() {
assertEquals("def", StringUtils.replaceAll("abc def", "abc ", "", false)); assertEquals("def", StringUtils.replaceAll("abc def", "abc ", ""));
assertEquals("af", StringUtils.replaceAll("abc def", "bc de", "", false)); assertEquals("af", StringUtils.replaceAll("abc def", "bc de", ""));
assertEquals("abc def", StringUtils.replaceAll("abc def", "bc ", "bc ", false)); assertEquals("abc def", StringUtils.replaceAll("abc def", "bc ", "bc "));
assertEquals("abc ", StringUtils.replaceAll("abc def", "def", "", false)); assertEquals("abc ", StringUtils.replaceAll("abc def", "def", ""));
assertEquals(" ", StringUtils.replaceAll("abc abc", "abc", "", false)); assertEquals(" ", StringUtils.replaceAll("abc abc", "abc", ""));
assertEquals("xyz xyz", StringUtils.replaceAll("abc abc", "abc", "xyz", false)); assertEquals("xyz xyz", StringUtils.replaceAll("abc abc", "abc", "xyz"));
assertEquals("abc def", StringUtils.replaceAll("abc def", "xyz", "abc", false)); assertEquals("abc def", StringUtils.replaceAll("abc def", "xyz", "abc"));
assertEquals("", StringUtils.replaceAll("abcabcabc", "abc", "", false)); assertEquals("", StringUtils.replaceAll("abcabcabc", "abc", ""));
assertEquals("abcabcabc", StringUtils.replaceAll("abcabcabc", "aBc", "", false)); assertEquals("abcabcabc", StringUtils.replaceAll("abcabcabc", "aBc", ""));
assertEquals("d", StringUtils.replaceAll("abcd", "aBc", "", true)); assertEquals("d", StringUtils.replaceAllIgnoreCase("abcd", "aBc", ""));
assertEquals("d", StringUtils.replaceAll("abcd", "abc", "", true)); assertEquals("d", StringUtils.replaceAllIgnoreCase("abcd", "abc", ""));
assertEquals("D", StringUtils.replaceAll("abcD", "aBc", "", true)); assertEquals("D", StringUtils.replaceAllIgnoreCase("abcD", "aBc", ""));
assertEquals("D", StringUtils.replaceAll("abcD", "abc", "", true)); assertEquals("D", StringUtils.replaceAllIgnoreCase("abcD", "abc", ""));
} }
} }
...@@ -34,12 +34,12 @@ public class BnfRailroad implements BnfVisitor { ...@@ -34,12 +34,12 @@ public class BnfRailroad implements BnfVisitor {
public String getHtml(Bnf bnf, String syntaxLines) { public String getHtml(Bnf bnf, String syntaxLines) {
syntaxVisitor = new BnfSyntax(); syntaxVisitor = new BnfSyntax();
this.config = bnf; this.config = bnf;
syntaxLines = StringUtils.replaceAll(syntaxLines, "\n ", " ", false); syntaxLines = StringUtils.replaceAll(syntaxLines, "\n ", " ");
String[] syntaxList = StringUtils.arraySplit(syntaxLines, '\n', true); String[] syntaxList = StringUtils.arraySplit(syntaxLines, '\n', true);
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
for (String s : syntaxList) { for (String s : syntaxList) {
bnf.visit(this, s); bnf.visit(this, s);
html = StringUtils.replaceAll(html, "</code></td><td class=\"d\"><code class=\"c\">", " ", false); html = StringUtils.replaceAll(html, "</code></td><td class=\"d\"><code class=\"c\">", " ");
if (buff.length() > 0) { if (buff.length() > 0) {
buff.append("<br />"); buff.append("<br />");
} }
......
...@@ -30,7 +30,7 @@ public class BnfSyntax implements BnfVisitor { ...@@ -30,7 +30,7 @@ public class BnfSyntax implements BnfVisitor {
* @return the HTML * @return the HTML
*/ */
public String getHtml(Bnf bnf, String syntaxLines) { public String getHtml(Bnf bnf, String syntaxLines) {
syntaxLines = StringUtils.replaceAll(syntaxLines, "\n ", "\n", false); syntaxLines = StringUtils.replaceAll(syntaxLines, "\n ", "\n");
StringTokenizer tokenizer = bnf.getTokenizer(syntaxLines); StringTokenizer tokenizer = bnf.getTokenizer(syntaxLines);
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
while (tokenizer.hasMoreTokens()) { while (tokenizer.hasMoreTokens()) {
...@@ -43,7 +43,7 @@ public class BnfSyntax implements BnfVisitor { ...@@ -43,7 +43,7 @@ public class BnfSyntax implements BnfVisitor {
} }
String s = buff.toString(); String s = buff.toString();
// ensure it works within XHTML comments // ensure it works within XHTML comments
s = StringUtils.replaceAll(s, "--", "&#45;-", false); s = StringUtils.replaceAll(s, "--", "&#45;-");
return s; return s;
} }
......
...@@ -149,15 +149,15 @@ public class GenerateDoc { ...@@ -149,15 +149,15 @@ public class GenerateDoc {
String text = map.get("text"); String text = map.get("text");
if (text != null) { if (text != null) {
// text is enclosed in <p> .. </p> so this works. // text is enclosed in <p> .. </p> so this works.
text = StringUtils.replaceAll(text, "<br /><br />", "</p><p>", false); text = StringUtils.replaceAll(text, "<br /><br />", "</p><p>");
text = StringUtils.replaceAll(text, "<br />", " ", false); text = StringUtils.replaceAll(text, "<br />", " ");
map.put("text", text); map.put("text", text);
} }
String link = topic.toLowerCase(); String link = topic.toLowerCase();
link = StringUtils.replaceAll(link, " ", "_", false); link = StringUtils.replaceAll(link, " ", "_");
// link = StringUtils.replaceAll(link, "_", ""); // link = StringUtils.replaceAll(link, "_", "");
link = StringUtils.replaceAll(link, "@", "_", false); link = StringUtils.replaceAll(link, "@", "_");
map.put("link", StringUtils.urlEncode(link)); map.put("link", StringUtils.urlEncode(link));
list.add(map); list.add(map);
......
...@@ -41,7 +41,7 @@ public class MergeDocs { ...@@ -41,7 +41,7 @@ public class MergeDocs {
for (String fileName : pages) { for (String fileName : pages) {
String text = getContent(fileName); String text = getContent(fileName);
for (String page : pages) { for (String page : pages) {
text = StringUtils.replaceAll(text, page + "#", "#", false); text = StringUtils.replaceAll(text, page + "#", "#");
} }
text = disableRailroads(text); text = disableRailroads(text);
text = removeHeaderFooter(fileName, text); text = removeHeaderFooter(fileName, text);
...@@ -61,10 +61,10 @@ public class MergeDocs { ...@@ -61,10 +61,10 @@ public class MergeDocs {
} }
private String disableRailroads(String text) { private String disableRailroads(String text) {
text = StringUtils.replaceAll(text, "<!-- railroad-start -->", "<!-- railroad-start ", false); text = StringUtils.replaceAll(text, "<!-- railroad-start -->", "<!-- railroad-start ");
text = StringUtils.replaceAll(text, "<!-- railroad-end -->", " railroad-end -->", false); text = StringUtils.replaceAll(text, "<!-- railroad-end -->", " railroad-end -->");
text = StringUtils.replaceAll(text, "<!-- syntax-start", "<!-- syntax-start -->", false); text = StringUtils.replaceAll(text, "<!-- syntax-start", "<!-- syntax-start -->");
text = StringUtils.replaceAll(text, "syntax-end -->", "<!-- syntax-end -->", false); text = StringUtils.replaceAll(text, "syntax-end -->", "<!-- syntax-end -->");
return text; return text;
} }
......
...@@ -175,7 +175,7 @@ public class SpellChecker { ...@@ -175,7 +175,7 @@ public class SpellChecker {
StringBuilder buff = new StringBuilder(text.length()); StringBuilder buff = new StringBuilder(text.length());
int pos = 0, last = 0; int pos = 0, last = 0;
if (fileName.endsWith(".properties")) { if (fileName.endsWith(".properties")) {
text = StringUtils.replaceAll(text, "\\:", ":", false); text = StringUtils.replaceAll(text, "\\:", ":");
} }
while (true) { while (true) {
pos = text.indexOf("http://", pos); pos = text.indexOf("http://", pos);
......
...@@ -55,8 +55,8 @@ public class UploadBuild { ...@@ -55,8 +55,8 @@ public class UploadBuild {
idx = index.indexOf("</A>"); idx = index.indexOf("</A>");
index = index.substring(0, idx) + index.substring(idx + "</A>".length()); index = index.substring(0, idx) + index.substring(idx + "</A>".length());
} }
index = StringUtils.replaceAll(index, "[all", "", false); index = StringUtils.replaceAll(index, "[all", "");
index = StringUtils.replaceAll(index, "classes]", "", false); index = StringUtils.replaceAll(index, "classes]", "");
FileOutputStream out = new FileOutputStream("coverage/overview.html"); FileOutputStream out = new FileOutputStream("coverage/overview.html");
out.write(index.getBytes("ISO-8859-1")); out.write(index.getBytes("ISO-8859-1"));
out.close(); out.close();
......
...@@ -138,18 +138,18 @@ public class WebSite { ...@@ -138,18 +138,18 @@ public class WebSite {
if (name.endsWith(".html")) { if (name.endsWith(".html")) {
String page = new String(bytes, "UTF-8"); String page = new String(bytes, "UTF-8");
if (web) { if (web) {
page = StringUtils.replaceAll(page, ANALYTICS_TAG, ANALYTICS_SCRIPT, false); page = StringUtils.replaceAll(page, ANALYTICS_TAG, ANALYTICS_SCRIPT);
} }
if (replaceFragments) { if (replaceFragments) {
page = replaceFragments(name, page); page = replaceFragments(name, page);
page = StringUtils.replaceAll(page, "<a href=\"frame", "<a href=\"main", false); page = StringUtils.replaceAll(page, "<a href=\"frame", "<a href=\"main");
page = StringUtils.replaceAll(page, "html/frame.html", "html/main.html", false); page = StringUtils.replaceAll(page, "html/frame.html", "html/main.html");
} }
if (web) { if (web) {
page = StringUtils.replaceAll(page, TRANSLATE_START, "", false); page = StringUtils.replaceAll(page, TRANSLATE_START, "");
page = StringUtils.replaceAll(page, TRANSLATE_END, "", false); page = StringUtils.replaceAll(page, TRANSLATE_END, "");
page = StringUtils.replaceAll(page, "<pre>", "<pre class=\"notranslate\">", false); page = StringUtils.replaceAll(page, "<pre>", "<pre class=\"notranslate\">");
page = StringUtils.replaceAll(page, "<code>", "<code class=\"notranslate\">", false); page = StringUtils.replaceAll(page, "<code>", "<code class=\"notranslate\">");
} }
bytes = page.getBytes("UTF-8"); bytes = page.getBytes("UTF-8");
} }
......
...@@ -153,7 +153,7 @@ public class Doclet { ...@@ -153,7 +153,7 @@ public class Doclet {
boolean isVarArgs = method.isVarArgs() && j == params.length - 1; boolean isVarArgs = method.isVarArgs() && j == params.length - 1;
String typeName = getTypeName(false, isVarArgs, param.type()); String typeName = getTypeName(false, isVarArgs, param.type());
buff.append(typeName); buff.append(typeName);
buffSignature.append(StringUtils.replaceAll(typeName, "[]", "-", false)); buffSignature.append(StringUtils.replaceAll(typeName, "[]", "-"));
buff.append(' '); buff.append(' ');
buff.append(param.name()); buff.append(param.name());
} }
...@@ -380,7 +380,7 @@ public class Doclet { ...@@ -380,7 +380,7 @@ public class Doclet {
if (text == null) { if (text == null) {
return text; return text;
} }
text = StringUtils.replaceAll(text, "\n </pre>", "</pre>", false); text = StringUtils.replaceAll(text, "\n </pre>", "</pre>");
return text; return text;
} }
......
...@@ -129,16 +129,16 @@ public class PrepareTranslation { ...@@ -129,16 +129,16 @@ public class PrepareTranslation {
map.put(k.toString(), prop.get(k)); map.put(k.toString(), prop.get(k));
} }
String html = PageParser.parse(template, map); String html = PageParser.parse(template, map);
html = StringUtils.replaceAll(html, "lang=\"" + MAIN_LANGUAGE + "\"", "lang=\"" + language + "\"", false); html = StringUtils.replaceAll(html, "lang=\"" + MAIN_LANGUAGE + "\"", "lang=\"" + language + "\"");
for (String n : fileNames) { for (String n : fileNames) {
if ("frame".equals(n)) { if ("frame".equals(n)) {
// don't translate 'frame.html' to 'frame_ja.html', // don't translate 'frame.html' to 'frame_ja.html',
// otherwise we can't switch back to English // otherwise we can't switch back to English
continue; continue;
} }
html = StringUtils.replaceAll(html, n + ".html\"", n + "_" + language + ".html\"", false); html = StringUtils.replaceAll(html, n + ".html\"", n + "_" + language + ".html\"");
} }
html = StringUtils.replaceAll(html, "_" + MAIN_LANGUAGE + ".html\"", ".html\"", false); html = StringUtils.replaceAll(html, "_" + MAIN_LANGUAGE + ".html\"", ".html\"");
String target; String target;
if (language.equals(MAIN_LANGUAGE)) { if (language.equals(MAIN_LANGUAGE)) {
target = targetDir + "/" + name + ".html"; target = targetDir + "/" + name + ".html";
...@@ -376,7 +376,7 @@ public class PrepareTranslation { ...@@ -376,7 +376,7 @@ public class PrepareTranslation {
text = text.replace('\r', ' '); text = text.replace('\r', ' ');
text = text.replace('\n', ' '); text = text.replace('\n', ' ');
while (true) { while (true) {
String s = StringUtils.replaceAll(text, " ", " ", false); String s = StringUtils.replaceAll(text, " ", " ");
if (s.equals(text)) { if (s.equals(text)) {
break; break;
} }
......
...@@ -146,8 +146,8 @@ public class PropertiesToUTF8 { ...@@ -146,8 +146,8 @@ public class PropertiesToUTF8 {
out.close(); out.close();
} }
String java = StringUtils.javaEncode(utf8); String java = StringUtils.javaEncode(utf8);
java = StringUtils.replaceAll(java, "\\r", "\r", false); java = StringUtils.replaceAll(java, "\\r", "\r");
java = StringUtils.replaceAll(java, "\\n", "\n", false); java = StringUtils.replaceAll(java, "\\n", "\n");
RandomAccessFile out = new RandomAccessFile("_java." + name, "rw"); RandomAccessFile out = new RandomAccessFile("_java." + name, "rw");
out.write(java.getBytes()); out.write(java.getBytes());
out.setLength(out.getFilePointer()); out.setLength(out.getFilePointer());
......
...@@ -447,7 +447,7 @@ public class FtpClient { ...@@ -447,7 +447,7 @@ public class FtpClient {
for (int i = 0; i < files.length; i++) { for (int i = 0; i < files.length; i++) {
String s = list[i]; String s = list[i];
while (true) { while (true) {
String s2 = StringUtils.replaceAll(s, " ", " ", false); String s2 = StringUtils.replaceAll(s, " ", " ");
if (s2.equals(s)) { if (s2.equals(s)) {
break; break;
} }
......
...@@ -101,15 +101,15 @@ public class Railroads { ...@@ -101,15 +101,15 @@ public class Railroads {
String text = map.get("text"); String text = map.get("text");
if (text != null) { if (text != null) {
// text is enclosed in <p> .. </p> so this works. // text is enclosed in <p> .. </p> so this works.
text = StringUtils.replaceAll(text, "<br /><br />", "</p><p>", false); text = StringUtils.replaceAll(text, "<br /><br />", "</p><p>");
text = StringUtils.replaceAll(text, "<br />", " ", false); text = StringUtils.replaceAll(text, "<br />", " ");
map.put("text", text); map.put("text", text);
} }
String link = topic.toLowerCase(); String link = topic.toLowerCase();
link = StringUtils.replaceAll(link, " ", "_", false); link = StringUtils.replaceAll(link, " ", "_");
// link = StringUtils.replaceAll(link, "_", ""); // link = StringUtils.replaceAll(link, "_", "");
link = StringUtils.replaceAll(link, "@", "_", false); link = StringUtils.replaceAll(link, "@", "_");
map.put("link", StringUtils.urlEncode(link)); map.put("link", StringUtils.urlEncode(link));
list.add(map); list.add(map);
} }
......
...@@ -134,7 +134,7 @@ public class FunctionsMySQL { ...@@ -134,7 +134,7 @@ public class FunctionsMySQL {
private static String convertToSimpleDateFormat(String format) { private static String convertToSimpleDateFormat(String format) {
String[] replace = FORMAT_REPLACE; String[] replace = FORMAT_REPLACE;
for (int i = 0; i < replace.length; i += 2) { for (int i = 0; i < replace.length; i += 2) {
format = StringUtils.replaceAll(format, replace[i], replace[i + 1], false); format = StringUtils.replaceAll(format, replace[i], replace[i + 1]);
} }
return format; return format;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论