1 23 24 package org.enhydra.xml.driver; 25 26 27 30 public class SimpleDiffFilter implements TestDiff.LineFilter { 31 32 private String fPattern; 33 private String fReplace; 34 35 36 39 public SimpleDiffFilter(String pattern, 40 String replace) { 41 fPattern = pattern; 42 fReplace = replace; 43 } 44 45 46 public String filter(String line) { 47 int nextIdx = line.indexOf(fPattern); 48 if (nextIdx < 0) { 49 return line; } 51 52 StringBuffer buf = new StringBuffer (line.length()); 54 int startIdx = 0; 55 int len = fPattern.length(); 56 while (nextIdx >= 0) { 57 buf.append(line.substring(startIdx, nextIdx)); 58 buf.append(fReplace); 59 startIdx = nextIdx + len; 60 nextIdx = line.indexOf(fPattern, startIdx); 61 } 62 if (startIdx < line.length()) { 63 buf.append(line.substring(startIdx)); 64 } 65 return buf.toString(); 66 } 67 } 68 | Popular Tags |