@Test public void testReplace2() throws Throwable { String[] src = new String[8]; src[0] = "testString"; src[1] = "abcdefghisklmnopqrstuvwxyz"; src[2] = "testString"; src[3] = "testString"; src[4] = "\u53AF\u656B\u53B5\u30E0\u4AB3\u98BF$\uF51B\u7D75\u141A\u4FC6\uB213\uD2B1\uBD90"; src[5] = "testString"; src[6] = "testString"; src[7] = "testString"; String[] patterns = new String[1]; patterns[0] = "testString"; String[] to = new String[1]; String[] result = BSHLogListener.replace(src, patterns, to); assertEquals(8, result.length, "result.length"); assertEquals("testString", result[0], "result[0]"); }
protected static String[] replace(String[] src, String[] patterns, String[] to){ String[] ret = new String[src.length]; for(int i=0; i<src.length; i++){ StringBuilder buff = new StringBuilder(2*src[i].length()); int begin, end=0; while ((begin = src[i].indexOf('$',end))>=0 && begin<src[i].length()){ buff.append(src[i].substring(end, begin)); boolean patternFound = false; for(int k=0; k<patterns.length && !patternFound ; k++){ if(patternFound = src[i].indexOf(patterns[k], begin) == begin+1){ buff.append(to[k]); end = begin + patterns[k].length() + 1; } } if(!patternFound) end = begin + 1; } buff.append(src[i].substring(end)); ret[i] = buff.toString(); } return ret; }
BSHLogListener implements org.jpos.util.LogListener, org.jpos.core.Configurable { protected static String[] replace(String[] src, String[] patterns, String[] to){ String[] ret = new String[src.length]; for(int i=0; i<src.length; i++){ StringBuilder buff = new StringBuilder(2*src[i].length()); int begin, end=0; while ((begin = src[i].indexOf('$',end))>=0 && begin<src[i].length()){ buff.append(src[i].substring(end, begin)); boolean patternFound = false; for(int k=0; k<patterns.length && !patternFound ; k++){ if(patternFound = src[i].indexOf(patterns[k], begin) == begin+1){ buff.append(to[k]); end = begin + patterns[k].length() + 1; } } if(!patternFound) end = begin + 1; } buff.append(src[i].substring(end)); ret[i] = buff.toString(); } return ret; } }
BSHLogListener implements org.jpos.util.LogListener, org.jpos.core.Configurable { protected static String[] replace(String[] src, String[] patterns, String[] to){ String[] ret = new String[src.length]; for(int i=0; i<src.length; i++){ StringBuilder buff = new StringBuilder(2*src[i].length()); int begin, end=0; while ((begin = src[i].indexOf('$',end))>=0 && begin<src[i].length()){ buff.append(src[i].substring(end, begin)); boolean patternFound = false; for(int k=0; k<patterns.length && !patternFound ; k++){ if(patternFound = src[i].indexOf(patterns[k], begin) == begin+1){ buff.append(to[k]); end = begin + patterns[k].length() + 1; } } if(!patternFound) end = begin + 1; } buff.append(src[i].substring(end)); ret[i] = buff.toString(); } return ret; } BSHLogListener(); }
BSHLogListener implements org.jpos.util.LogListener, org.jpos.core.Configurable { protected static String[] replace(String[] src, String[] patterns, String[] to){ String[] ret = new String[src.length]; for(int i=0; i<src.length; i++){ StringBuilder buff = new StringBuilder(2*src[i].length()); int begin, end=0; while ((begin = src[i].indexOf('$',end))>=0 && begin<src[i].length()){ buff.append(src[i].substring(end, begin)); boolean patternFound = false; for(int k=0; k<patterns.length && !patternFound ; k++){ if(patternFound = src[i].indexOf(patterns[k], begin) == begin+1){ buff.append(to[k]); end = begin + patterns[k].length() + 1; } } if(!patternFound) end = begin + 1; } buff.append(src[i].substring(end)); ret[i] = buff.toString(); } return ret; } BSHLogListener(); @Override void setConfiguration(org.jpos.core.Configuration cfg); @Override LogEvent log(LogEvent ev); }
BSHLogListener implements org.jpos.util.LogListener, org.jpos.core.Configurable { protected static String[] replace(String[] src, String[] patterns, String[] to){ String[] ret = new String[src.length]; for(int i=0; i<src.length; i++){ StringBuilder buff = new StringBuilder(2*src[i].length()); int begin, end=0; while ((begin = src[i].indexOf('$',end))>=0 && begin<src[i].length()){ buff.append(src[i].substring(end, begin)); boolean patternFound = false; for(int k=0; k<patterns.length && !patternFound ; k++){ if(patternFound = src[i].indexOf(patterns[k], begin) == begin+1){ buff.append(to[k]); end = begin + patterns[k].length() + 1; } } if(!patternFound) end = begin + 1; } buff.append(src[i].substring(end)); ret[i] = buff.toString(); } return ret; } BSHLogListener(); @Override void setConfiguration(org.jpos.core.Configuration cfg); @Override LogEvent log(LogEvent ev);  }