Coverage Report - net.sf.statsvn.util.StringUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
StringUtils
94%
15/16
100%
12/12
6
 
 1  
 package net.sf.statsvn.util;
 2  
 
 3  0
 public class StringUtils {
 4  
     /**
 5  
      * This method is a 1.4 replacement of the String.replace(CharSequence, CharSequence) found in 1.5.
 6  
      * @param originalPattern
 7  
      * @param newPattern
 8  
      * @param originalString
 9  
      * @return
 10  
      */
 11  
     public static String replace(final String originalPattern, final String newPattern, final String originalString) {
 12  11
         if ((originalPattern == null) || (originalPattern.length() == 0) || (originalString == null)) {
 13  3
             return originalString;
 14  
         }
 15  
 
 16  8
         final StringBuffer newString = new StringBuffer(originalString.length());
 17  8
         int index = 0;
 18  8
         final int originalLength = originalPattern.length();
 19  8
         int previousIndex = 0;
 20  
 
 21  29
         while ((index = originalString.indexOf(originalPattern, index)) != -1) {
 22  21
             newString.append(originalString.substring(previousIndex, index)).append(newPattern);
 23  21
             index += originalLength;
 24  21
             previousIndex = index;
 25  
         }
 26  
 
 27  8
         if (previousIndex == 0) {
 28  2
             newString.append(originalString);
 29  6
         } else if (previousIndex != originalString.length()) {
 30  5
             newString.append(originalString.substring(previousIndex));
 31  
         }
 32  
 
 33  8
         return newString.toString();
 34  
     }
 35  
 }