1 package com.ubermq.jms.common.routing.impl; 2 3 6 public class RegexpHelper 7 { 8 37 public static String xlat(String friendly) 38 { 39 if (friendly.length() > 0 && friendly.charAt(0) == '~') 41 return friendly.substring(1); 42 43 StringBuffer regexp = new StringBuffer (friendly); 44 replaceChar(regexp, '$', "\\$"); 45 replaceChar(regexp, '.', "\\."); 46 replaceChar(regexp, '*', "[^\\.]*"); 47 replaceChar(regexp, '#', "[^\\.].*"); 48 49 return regexp.toString(); 50 } 51 52 56 public static void replaceChar(StringBuffer regexp, char ch, String repl) 57 { 58 for(int i=0;i < regexp.length();i++) 59 { 60 if (regexp.charAt(i) == ch) 61 { 62 regexp.replace(i, i+1, repl); 63 i += repl.length(); 64 } 65 } 66 } 67 } 68 | Popular Tags |