Here you can find the source of wildcardMatch(final String pattern, final int patternIndex, final String value, final int valueIndex)
Parameter | Description |
---|---|
patternIndex | the patternIndex |
tmpIndex | the current index |
value | the value |
valueIndex | the current value |
private static boolean wildcardMatch(final String pattern, final int patternIndex, final String value, final int valueIndex)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); public class Main { /**//ww w .j a va2 s . com * The wildcard for a single character (?) */ public static final char SINGLE_TOKEN = '?'; /** * The wildcard for multiple characters (*) */ public static final char MULTIPLE_TOKEN = '*'; /** * Performs a match operation using wildcards. * * @param patternIndex the patternIndex * @param tmpIndex the current index * @param value the value * @param valueIndex the current value * @return true on match */ //CHECKSTYLE:OFF split not possible private static boolean wildcardMatch(final String pattern, final int patternIndex, final String value, final int valueIndex) { int tmpPatternIndex = patternIndex; int tmpValueIndex = valueIndex; while (tmpPatternIndex < pattern.length()) { if (SINGLE_TOKEN == pattern.charAt(tmpPatternIndex)) { tmpPatternIndex += 1; if (tmpValueIndex < value.length()) { tmpValueIndex += 1; } else { return false; } } else if (MULTIPLE_TOKEN == pattern.charAt(tmpPatternIndex)) { while ((tmpPatternIndex < pattern.length()) && (MULTIPLE_TOKEN == pattern.charAt(tmpPatternIndex))) { tmpPatternIndex += 1; } if (tmpPatternIndex >= pattern.length()) { return true; } while (tmpValueIndex < value.length()) { if (wildcardMatch(pattern, tmpPatternIndex, value, tmpValueIndex)) { return true; } tmpValueIndex += 1; } } else if ((tmpValueIndex < value.length()) && (pattern.charAt(tmpPatternIndex) == value.charAt(tmpValueIndex))) { tmpPatternIndex += 1; tmpValueIndex += 1; } else { return false; } } return ((tmpPatternIndex >= pattern.length()) && (tmpValueIndex >= value.length())); } }