From 4079bf5f571c6d3e0797add56544c25a88eadbe2 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 14 Apr 1999 20:23:32 +0000 Subject: [PATCH] startsWith toString getNextComponent git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@604 379699f6-c40d-0410-875b-85095c16579e --- jode/jode/obfuscator/WildCard.java | 66 +++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/jode/jode/obfuscator/WildCard.java b/jode/jode/obfuscator/WildCard.java index f3637d6..cc3fbd3 100644 --- a/jode/jode/obfuscator/WildCard.java +++ b/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; } }