Coverage Report - com.aurea.maven.plugins.sonic.utils.RegexUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
RegexUtil
0%
0/10
0%
0/2
2
 
 1  
 package com.aurea.maven.plugins.sonic.utils;
 2  
 
 3  
 import java.util.regex.Matcher;
 4  
 import java.util.regex.Pattern;
 5  
 
 6  0
 public class RegexUtil {
 7  
 
 8  
 
 9  
   /**
 10  
    * Find #{text} in the string and replaces any occurrences of str in text by replacement. The entire match is then
 11  
    * replaced by the result.
 12  
    * 
 13  
    * @param text
 14  
    * @return string replaced version of string
 15  
    */
 16  
   public static String applyReplaceFunction(String text, String str, String replacement) {
 17  
 
 18  0
     Pattern pattern = Pattern.compile("#\\{([^\\}]*)\\}");
 19  0
     Matcher matcher = pattern.matcher(text);
 20  
 
 21  0
     StringBuffer result = new StringBuffer();
 22  0
     while (matcher.find()) {
 23  0
       String argument = matcher.group(1);
 24  0
       matcher.appendReplacement(result, argument.replace(str, Matcher.quoteReplacement(replacement)));
 25  0
     }
 26  0
     matcher.appendTail(result);
 27  
 
 28  0
     return result.toString();
 29  
   }
 30  
 
 31  
 }