Thread: Wildcard Finder
View Single Post
  #6  
Old 03-12-2009, 12:34 AM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
This was a bit rushed but here is my version of the Wildcard Finder I hope it works as you want it to work.

PHP Code:
function onCreated() {
  
temp.= {"foo1231594","foo437793","bar1234","bar4321","moo4567"};
  
temp.findWildcard("foo*3*9*",temp.a); // foo1231594,foo437793

PHP Code:
function findWildcard(syntax,array) {
  if (
temp.syntax == "*")
    return 
temp.array;
  if (
temp.syntax.pos("*") == - 1)
    return (
temp.array.index(temp.syntax) > - temp.array[temp.array.index(temp.syntax)] : false);
  
  
temp.newsyntax = {};  
  
this.syntaxend = !temp.syntax.ends("*");  
  while (
temp.syntax.pos("*") > - 1) {
    if (!(
temp.syntax.pos("*"in {0,temp.syntax.length()}))
      
temp.newsyntax.add(temp.syntax.substring(0,temp.syntax.pos("*")));
    
temp.syntax temp.syntax.substring(temp.syntax.pos("*") + 1);
  }
  if (
temp.syntax != "")
    
temp.newsyntax.add(temp.syntax);
    
  
temp.copysyntax = {};
  for (
temp.stemp.newsyntax) {
    
temp."";
    for (
temp.0temp.temp.s.length(); temp.++)
      
temp.@= "*";
    
temp.copysyntax.add(temp.r);
  }
  
  
this.syntax temp.newsyntax;
  
this.syntaxcopy temp.copysyntax;
  
  
temp.result = {};
  for (
temp.checktexttemp.array) {
    
temp.check checkText(temp.checktext);
    if (
temp.check != false)
      
temp.result.add(temp.check);
  }
  return (
temp.result.size() > temp.result false);
}

function 
checkText(realtext) {
  if (
this.syntaxend && !temp.realtext.ends(this.syntax[this.syntax.size() - 1]))
    return 
false;
  
temp.highest = - 1;
  
temp.checktext temp.realtext;
  for (
temp.0temp.this.syntax.size(); temp.++) {
    
temp.checkpart this.syntax[temp.c];
    if (
temp.checktext.pos(temp.checkpart) == - 1)
      return 
false;
    
    if (
temp.checktext.pos(temp.checkpart) > temp.highest) {
      
temp.checkpos temp.checktext.pos(temp.checkpart);
      
temp.checktext temp.checktext.substring(0,temp.checkpos) @ 
                       
this.syntaxcopy[temp.c] @ 
                       
temp.checktext.substring(temp.checkpos this.syntaxcopy[temp.c].length());
                       
      
temp.highest temp.checkpos;
    }
    else
      return 
false;
  }    
  return 
temp.realtext;

__________________
Reply With Quote