1 21 package proguard.util; 22 23 import java.util.*; 24 25 41 public class BasicListMatcher implements StringMatcher 42 { 43 private static final char REGULAR_EXPRESSION_SEPARATOR = ','; 44 private static final char REGULAR_EXPRESSION_NEGATOR = '!'; 45 46 private StringMatcher[] regularExpressionMatchers; 47 private boolean[] negatedRegularExpressions; 48 49 50 55 public BasicListMatcher(String regularExpression) 56 { 57 this(ListUtil.commaSeparatedList(regularExpression)); 58 } 59 60 61 66 public BasicListMatcher(List regularExpressionList) 67 { 68 int regularExpressionCount = regularExpressionList.size(); 70 71 regularExpressionMatchers = new StringMatcher[regularExpressionCount]; 72 negatedRegularExpressions = new boolean[regularExpressionCount]; 73 74 for (int index = 0; index < regularExpressionCount; index++) 75 { 76 String regularExpression = (String )regularExpressionList.get(index); 77 78 if (regularExpression.length() > 0 && 80 regularExpression.charAt(0) == REGULAR_EXPRESSION_NEGATOR) 81 { 82 regularExpression = regularExpression.substring(1); 84 85 negatedRegularExpressions[index] = true; 87 } 88 89 regularExpressionMatchers[index] = 90 createBasicMatcher(regularExpression); 91 } 92 } 93 94 95 98 protected StringMatcher createBasicMatcher(String regularExpression) 99 { 100 return new BasicMatcher(regularExpression); 101 } 102 103 104 106 public boolean matches(String string) 107 { 108 boolean result = true; 109 110 for (int index = 0; index < regularExpressionMatchers.length; index++) 111 { 112 result = negatedRegularExpressions[index]; 113 114 if (regularExpressionMatchers[index].matches(string)) 115 { 116 return !result; 117 } 118 } 119 120 return result; 121 } 122 123 124 127 public static void main(String [] args) 128 { 129 try 130 { 131 System.out.println("Regular expression ["+args[0]+"]"); 132 BasicListMatcher matcher = 133 new BasicListMatcher(args[0]); 134 135 for (int index = 1; index < args.length; index++) 136 { 137 String string = args[index]; 138 System.out.print("String ["+string+"]"); 139 System.out.println(" -> match = "+matcher.matches(args[index])); 140 } 141 } 142 catch (Exception ex) 143 { 144 ex.printStackTrace(); 145 } 146 } 147 } 148 | Popular Tags |