/**
 * StringMatcher.java
 *
 * Caitlin Ross 
 * 100735219
 */


public class StringMatcher {

    public StringMatcher() {
    }
    
    public boolean matches(String templateString, String dataString){
    	/*If one of the strings is empty:	both template and data are empty
    	 *									template is empty, but data isn't
    	 *									data is empty, but template isn't
    	 */
    	if(templateString.length() == 0 && dataString.length() == 0)
    		return true;
    	if(templateString.length() !=0 && dataString.length()==0)
    		return false;
    	if(templateString.length() == 0 && dataString.length() != 0)
    		return false;
    	/*If first search letter is a star:	star is dropped
    	 *									letter is dropped
    	*/
    	if(templateString.charAt(0) == '*'){
    		if(templateString.length() == 1)
    			return true;
    		if(templateString.substring(1,2).equalsIgnoreCase(dataString.substring(0,1))){
    			if(matches(templateString.substring(1), dataString) == false)
    				return matches(templateString, dataString.substring(1));
    			else
    				return true;
    		}
    		return matches(templateString, dataString.substring(1));
    	}
    	/*otherwise first letter is NOT a star:	the first characters don't match
    	 *										the characters match
    	 */
    	if(!dataString.substring(0,1).equalsIgnoreCase(templateString.substring(0,1)))
    		return false;
    	return matches(templateString.substring(1), dataString.substring(1));
    }
}