]> source.dussan.org Git - sonarqube.git/commitdiff
Replace 3 regex with 1 and precompiled pattern
authorFranck Arnulfo <franck.arnulfo@gmail.com>
Fri, 31 May 2019 09:55:03 +0000 (11:55 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 28 Jun 2019 06:45:52 +0000 (08:45 +0200)
server/sonar-db-dao/src/main/java/org/sonar/db/DaoUtils.java

index 6ba6d6be80f9f2b41294f9c34ba769a65e32ede9..2d5ff4e40196c2c592e82c3b569746f2c3edc18d 100644 (file)
  */
 package org.sonar.db;
 
+import java.util.regex.Pattern;
+
 public class DaoUtils {
+  private static final Pattern ESCAPE_PERCENT_AND_UNDERSCORE = Pattern.compile("[/%_]");
 
   private DaoUtils() {
     // prevent new instances
@@ -55,9 +58,8 @@ public class DaoUtils {
    * Replace escape percent and underscore by adding a slash just before
    */
   private static String escapePercentAndUnderscore(String value) {
-    return value
-        .replaceAll("/", "//")
-        .replaceAll("%", "/%")
-        .replaceAll("_", "/_");
+    return ESCAPE_PERCENT_AND_UNDERSCORE.matcher(value)
+      // $0 : Group zero, stands for the entire expression
+      .replaceAll("/$0");
   }
 }