toString
getNextComponent


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@604 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent e47813570c
commit 4079bf5f57
  1. 66
      jode/jode/obfuscator/WildCard.java

@ -21,23 +21,67 @@ package jode.obfuscator;
public class WildCard {
public static boolean matches(String wildcard, String test) {
int indexWild = wildcard.indexOf('*');
if (indexWild == -1)
String wildcard;
int firstStar;
public WildCard(String wild) {
wildcard = wild;
firstStar = wildcard.indexOf('*');
}
public String getNextComponent(String prefix) {
int lastDot = prefix.length();
if (lastDot < wildcard.length()
|| !wildcard.startsWith(prefix)
|| (lastDot > 0 && wildcard.charAt(lastDot) != '.'))
return null;
if (lastDot > 0)
lastDot++;
int nextDot = wildcard.indexOf('.', lastDot);
if (firstStar == -1) {
if (nextDot == -1)
return wildcard.substring(lastDot);
else
return wildcard.substring(lastDot, nextDot);
} else {
if (nextDot == -1 || nextDot > firstStar) {
return null;
} else {
return wildcard.substring(lastDot, nextDot);
}
}
}
public boolean startsWith(String test) {
if (firstStar == -1 || firstStar >= test.length())
return wildcard.startsWith(test);
return test.startsWith(wildcard.substring(0, firstStar));
}
public boolean matches(String test) {
if (firstStar == -1)
return wildcard.equals(test);
if (!test.startsWith(wildcard.substring(0, indexWild)))
if (!test.startsWith(wildcard.substring(0, firstStar)))
return false;
test = test.substring(indexWild);
test = test.substring(firstStar);
int lastWild = firstStar;
int nextWild;
while ((nextWild = wildcard.indexOf('*', indexWild + 1)) != -1) {
String pattern = wildcard.substring(indexWild+1, nextWild);
while (!test.startsWith(pattern))
while ((nextWild = wildcard.indexOf('*', lastWild + 1)) != -1) {
String pattern = wildcard.substring(lastWild+1, nextWild);
while (!test.startsWith(pattern)) {
if (test.length() == 0)
return false;
test = test.substring(1);
test = test.substring(nextWild - indexWild);
indexWild = nextWild;
}
test = test.substring(nextWild - lastWild);
lastWild = nextWild;
}
return test.endsWith(wildcard.substring(indexWild+1));
return test.endsWith(wildcard.substring(lastWild+1));
}
public String toString() {
return "Wildcard "+wildcard;
}
}

Loading…
Cancel
Save