Use String.replace() instead of replaceAll() when we don't need a Regex.
diff --git a/src/main/java/org/apache/commons/codec/language/Caverphone1.java b/src/main/java/org/apache/commons/codec/language/Caverphone1.java
index 9be557c..0c5a0be 100644
--- a/src/main/java/org/apache/commons/codec/language/Caverphone1.java
+++ b/src/main/java/org/apache/commons/codec/language/Caverphone1.java
@@ -65,29 +65,29 @@
txt = txt.replaceAll("mb$", "m2");
// 4. Handle replacements
- txt = txt.replaceAll("cq", "2q");
- txt = txt.replaceAll("ci", "si");
- txt = txt.replaceAll("ce", "se");
- txt = txt.replaceAll("cy", "sy");
- txt = txt.replaceAll("tch", "2ch");
- txt = txt.replaceAll("c", "k");
- txt = txt.replaceAll("q", "k");
- txt = txt.replaceAll("x", "k");
- txt = txt.replaceAll("v", "f");
- txt = txt.replaceAll("dg", "2g");
- txt = txt.replaceAll("tio", "sio");
- txt = txt.replaceAll("tia", "sia");
- txt = txt.replaceAll("d", "t");
- txt = txt.replaceAll("ph", "fh");
- txt = txt.replaceAll("b", "p");
- txt = txt.replaceAll("sh", "s2");
- txt = txt.replaceAll("z", "s");
+ txt = txt.replace("cq", "2q");
+ txt = txt.replace("ci", "si");
+ txt = txt.replace("ce", "se");
+ txt = txt.replace("cy", "sy");
+ txt = txt.replace("tch", "2ch");
+ txt = txt.replace("c", "k");
+ txt = txt.replace("q", "k");
+ txt = txt.replace("x", "k");
+ txt = txt.replace("v", "f");
+ txt = txt.replace("dg", "2g");
+ txt = txt.replace("tio", "sio");
+ txt = txt.replace("tia", "sia");
+ txt = txt.replace("d", "t");
+ txt = txt.replace("ph", "fh");
+ txt = txt.replace("b", "p");
+ txt = txt.replace("sh", "s2");
+ txt = txt.replace("z", "s");
txt = txt.replaceAll("^[aeiou]", "A");
// 3 is a temporary placeholder marking a vowel
txt = txt.replaceAll("[aeiou]", "3");
- txt = txt.replaceAll("3gh3", "3kh3");
- txt = txt.replaceAll("gh", "22");
- txt = txt.replaceAll("g", "k");
+ txt = txt.replace("3gh3", "3kh3");
+ txt = txt.replace("gh", "22");
+ txt = txt.replace("g", "k");
txt = txt.replaceAll("s+", "S");
txt = txt.replaceAll("t+", "T");
txt = txt.replaceAll("p+", "P");
@@ -95,26 +95,26 @@
txt = txt.replaceAll("f+", "F");
txt = txt.replaceAll("m+", "M");
txt = txt.replaceAll("n+", "N");
- txt = txt.replaceAll("w3", "W3");
- txt = txt.replaceAll("wy", "Wy"); // 1.0 only
- txt = txt.replaceAll("wh3", "Wh3");
- txt = txt.replaceAll("why", "Why"); // 1.0 only
- txt = txt.replaceAll("w", "2");
+ txt = txt.replace("w3", "W3");
+ txt = txt.replace("wy", "Wy"); // 1.0 only
+ txt = txt.replace("wh3", "Wh3");
+ txt = txt.replace("why", "Why"); // 1.0 only
+ txt = txt.replace("w", "2");
txt = txt.replaceAll("^h", "A");
- txt = txt.replaceAll("h", "2");
- txt = txt.replaceAll("r3", "R3");
- txt = txt.replaceAll("ry", "Ry"); // 1.0 only
- txt = txt.replaceAll("r", "2");
- txt = txt.replaceAll("l3", "L3");
- txt = txt.replaceAll("ly", "Ly"); // 1.0 only
- txt = txt.replaceAll("l", "2");
- txt = txt.replaceAll("j", "y"); // 1.0 only
- txt = txt.replaceAll("y3", "Y3"); // 1.0 only
- txt = txt.replaceAll("y", "2"); // 1.0 only
+ txt = txt.replace("h", "2");
+ txt = txt.replace("r3", "R3");
+ txt = txt.replace("ry", "Ry"); // 1.0 only
+ txt = txt.replace("r", "2");
+ txt = txt.replace("l3", "L3");
+ txt = txt.replace("ly", "Ly"); // 1.0 only
+ txt = txt.replace("l", "2");
+ txt = txt.replace("j", "y"); // 1.0 only
+ txt = txt.replace("y3", "Y3"); // 1.0 only
+ txt = txt.replace("y", "2"); // 1.0 only
// 5. Handle removals
- txt = txt.replaceAll("2", "");
- txt = txt.replaceAll("3", "");
+ txt = txt.replace("2", "");
+ txt = txt.replace("3", "");
// 6. put six 1s on the end
txt = txt + SIX_1;
diff --git a/src/main/java/org/apache/commons/codec/language/Caverphone2.java b/src/main/java/org/apache/commons/codec/language/Caverphone2.java
index 1a38ec6..e11728a 100644
--- a/src/main/java/org/apache/commons/codec/language/Caverphone2.java
+++ b/src/main/java/org/apache/commons/codec/language/Caverphone2.java
@@ -69,32 +69,32 @@
txt = txt.replaceAll("mb$", "m2");
// 4. Handle replacements
- txt = txt.replaceAll("cq", "2q");
- txt = txt.replaceAll("ci", "si");
- txt = txt.replaceAll("ce", "se");
- txt = txt.replaceAll("cy", "sy");
- txt = txt.replaceAll("tch", "2ch");
- txt = txt.replaceAll("c", "k");
- txt = txt.replaceAll("q", "k");
- txt = txt.replaceAll("x", "k");
- txt = txt.replaceAll("v", "f");
- txt = txt.replaceAll("dg", "2g");
- txt = txt.replaceAll("tio", "sio");
- txt = txt.replaceAll("tia", "sia");
- txt = txt.replaceAll("d", "t");
- txt = txt.replaceAll("ph", "fh");
- txt = txt.replaceAll("b", "p");
- txt = txt.replaceAll("sh", "s2");
- txt = txt.replaceAll("z", "s");
+ txt = txt.replace("cq", "2q");
+ txt = txt.replace("ci", "si");
+ txt = txt.replace("ce", "se");
+ txt = txt.replace("cy", "sy");
+ txt = txt.replace("tch", "2ch");
+ txt = txt.replace("c", "k");
+ txt = txt.replace("q", "k");
+ txt = txt.replace("x", "k");
+ txt = txt.replace("v", "f");
+ txt = txt.replace("dg", "2g");
+ txt = txt.replace("tio", "sio");
+ txt = txt.replace("tia", "sia");
+ txt = txt.replace("d", "t");
+ txt = txt.replace("ph", "fh");
+ txt = txt.replace("b", "p");
+ txt = txt.replace("sh", "s2");
+ txt = txt.replace("z", "s");
txt = txt.replaceAll("^[aeiou]", "A");
txt = txt.replaceAll("[aeiou]", "3");
- txt = txt.replaceAll("j", "y"); // 2.0 only
+ txt = txt.replace("j", "y"); // 2.0 only
txt = txt.replaceAll("^y3", "Y3"); // 2.0 only
txt = txt.replaceAll("^y", "A"); // 2.0 only
- txt = txt.replaceAll("y", "3"); // 2.0 only
- txt = txt.replaceAll("3gh3", "3kh3");
- txt = txt.replaceAll("gh", "22");
- txt = txt.replaceAll("g", "k");
+ txt = txt.replace("y", "3"); // 2.0 only
+ txt = txt.replace("3gh3", "3kh3");
+ txt = txt.replace("gh", "22");
+ txt = txt.replace("g", "k");
txt = txt.replaceAll("s+", "S");
txt = txt.replaceAll("t+", "T");
txt = txt.replaceAll("p+", "P");
@@ -102,23 +102,23 @@
txt = txt.replaceAll("f+", "F");
txt = txt.replaceAll("m+", "M");
txt = txt.replaceAll("n+", "N");
- txt = txt.replaceAll("w3", "W3");
- txt = txt.replaceAll("wh3", "Wh3");
+ txt = txt.replace("w3", "W3");
+ txt = txt.replace("wh3", "Wh3");
txt = txt.replaceAll("w$", "3"); // 2.0 only
- txt = txt.replaceAll("w", "2");
+ txt = txt.replace("w", "2");
txt = txt.replaceAll("^h", "A");
- txt = txt.replaceAll("h", "2");
- txt = txt.replaceAll("r3", "R3");
+ txt = txt.replace("h", "2");
+ txt = txt.replace("r3", "R3");
txt = txt.replaceAll("r$", "3"); // 2.0 only
- txt = txt.replaceAll("r", "2");
- txt = txt.replaceAll("l3", "L3");
+ txt = txt.replace("r", "2");
+ txt = txt.replace("l3", "L3");
txt = txt.replaceAll("l$", "3"); // 2.0 only
- txt = txt.replaceAll("l", "2");
+ txt = txt.replace("l", "2");
// 5. Handle removals
- txt = txt.replaceAll("2", "");
+ txt = txt.replace("2", "");
txt = txt.replaceAll("3$", "A"); // 2.0 only
- txt = txt.replaceAll("3", "");
+ txt = txt.replace("3", "");
// 6. put ten 1s on the end
txt = txt + TEN_1;
diff --git a/src/main/java/org/apache/commons/codec/language/MatchRatingApproachEncoder.java b/src/main/java/org/apache/commons/codec/language/MatchRatingApproachEncoder.java
index acb1af7..50f6e81 100644
--- a/src/main/java/org/apache/commons/codec/language/MatchRatingApproachEncoder.java
+++ b/src/main/java/org/apache/commons/codec/language/MatchRatingApproachEncoder.java
@@ -405,11 +405,11 @@
// Extract first letter
final String firstLetter = name.substring(0, 1);
- name = name.replaceAll("A", EMPTY);
- name = name.replaceAll("E", EMPTY);
- name = name.replaceAll("I", EMPTY);
- name = name.replaceAll("O", EMPTY);
- name = name.replaceAll("U", EMPTY);
+ name = name.replace("A", EMPTY);
+ name = name.replace("E", EMPTY);
+ name = name.replace("I", EMPTY);
+ name = name.replace("O", EMPTY);
+ name = name.replace("U", EMPTY);
name = name.replaceAll("\\s{2,}\\b", SPACE);
diff --git a/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java b/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java
index c65d155..93172b9 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base64InputStreamTest.java
@@ -222,7 +222,7 @@
testByChunk(encoded, decoded, BaseNCodec.PEM_CHUNK_SIZE, LF);
// Single Line test.
- final String singleLine = Base64TestData.ENCODED_64_CHARS_PER_LINE.replaceAll("\n", "");
+ final String singleLine = Base64TestData.ENCODED_64_CHARS_PER_LINE.replace("\n", "");
encoded = StringUtils.getBytesUtf8(singleLine);
decoded = BaseNTestData.DECODED;
testByChunk(encoded, decoded, 0, LF);
@@ -261,7 +261,7 @@
testByteByByte(encoded, decoded, BaseNCodec.PEM_CHUNK_SIZE, LF);
// Single Line test.
- final String singleLine = Base64TestData.ENCODED_64_CHARS_PER_LINE.replaceAll("\n", "");
+ final String singleLine = Base64TestData.ENCODED_64_CHARS_PER_LINE.replace("\n", "");
encoded = StringUtils.getBytesUtf8(singleLine);
decoded = BaseNTestData.DECODED;
testByteByByte(encoded, decoded, 0, LF);
diff --git a/src/test/java/org/apache/commons/codec/binary/Base64OutputStreamTest.java b/src/test/java/org/apache/commons/codec/binary/Base64OutputStreamTest.java
index 51a9a5c..be35db3 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base64OutputStreamTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base64OutputStreamTest.java
@@ -115,7 +115,7 @@
testByChunk(encoded, decoded, BaseNCodec.PEM_CHUNK_SIZE, LF);
// Single Line test.
- final String singleLine = Base64TestData.ENCODED_64_CHARS_PER_LINE.replaceAll("\n", "");
+ final String singleLine = Base64TestData.ENCODED_64_CHARS_PER_LINE.replace("\n", "");
encoded = StringUtils.getBytesUtf8(singleLine);
decoded = BaseNTestData.DECODED;
testByChunk(encoded, decoded, 0, LF);
@@ -154,7 +154,7 @@
testByteByByte(encoded, decoded, 64, LF);
// Single Line test.
- final String singleLine = Base64TestData.ENCODED_64_CHARS_PER_LINE.replaceAll("\n", "");
+ final String singleLine = Base64TestData.ENCODED_64_CHARS_PER_LINE.replace("\n", "");
encoded = StringUtils.getBytesUtf8(singleLine);
decoded = BaseNTestData.DECODED;
testByteByByte(encoded, decoded, 0, LF);
diff --git a/src/test/java/org/apache/commons/codec/binary/Base64Test.java b/src/test/java/org/apache/commons/codec/binary/Base64Test.java
index e4be6d0..8b80a55 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base64Test.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base64Test.java
@@ -190,7 +190,7 @@
// convert to "\r\n" so we're equal to the old openssl encoding test
// stored
// in Base64TestData.ENCODED_76_CHARS_PER_LINE:
- final String actualResult = Base64TestData.ENCODED_76_CHARS_PER_LINE.replaceAll("\n", "\r\n");
+ final String actualResult = Base64TestData.ENCODED_76_CHARS_PER_LINE.replace("\n", "\r\n");
final byte[] actualEncode = StringUtils.getBytesUtf8(actualResult);
assertTrue("chunkedEncodeMultipleOf76", Arrays.equals(expectedEncode, actualEncode));
}
@@ -324,7 +324,7 @@
final Base64 base64 = new Base64(64, new byte[] { '\t' }, true);
final byte[] encoded = base64.encode(BaseNTestData.DECODED);
String expectedResult = Base64TestData.ENCODED_64_CHARS_PER_LINE;
- expectedResult = expectedResult.replaceAll("=", ""); // url-safe has no
+ expectedResult = expectedResult.replace("=", ""); // url-safe has no
// == padding.
expectedResult = expectedResult.replace('\n', '\t');
expectedResult = expectedResult.replace('+', '-');