diff options
author | Franck Arnulfo <franck.arnulfo@gmail.com> | 2019-05-31 11:55:03 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2019-06-28 08:45:52 +0200 |
commit | e74f2a8c8bc791eae8ff6f9f5f8210a3068c44ae (patch) | |
tree | a1cb5706c30014dbd0d3d2c7ffec7c363f5b9d4d /server/sonar-db-dao | |
parent | 3a1a6e9107f42b4689a1b5d3ce09f770dbb46bda (diff) | |
download | sonarqube-e74f2a8c8bc791eae8ff6f9f5f8210a3068c44ae.tar.gz sonarqube-e74f2a8c8bc791eae8ff6f9f5f8210a3068c44ae.zip |
Replace 3 regex with 1 and precompiled pattern
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r-- | server/sonar-db-dao/src/main/java/org/sonar/db/DaoUtils.java | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoUtils.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoUtils.java index 6ba6d6be80f..2d5ff4e4019 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoUtils.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoUtils.java @@ -19,7 +19,10 @@ */ 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"); } } |