Thread: Wildcard Finder
View Single Post
  #1  
Old 03-10-2009, 11:53 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Wildcard Finder

I got bored, so I made this simple wildcard finder.

PHP Code:
// Made by Chompy
/* 
   Only supports one wildcard!

   find(str, arr[], bool)

   Syntax defines what to search for.

   Array is a member of all strings to compare with.

   Strict determines if it will use stricter filter rules on output.
   ("foo*" would not return "foo" in the output array for example)

*/
function find(syntax, array, strict) {
  
temp.pos syntax.pos("*");
  if (
pos == -1) {
    return {array[array.
index(syntax)]};
  }
  else {
    
temp.0temp.""temp."";
    if (
pos 1) { // *x
      
1;
      
syntax.substring(1);
    }
    if (!(
pos == syntax.length()-1) && == 0) { // x*x
      
2;
      
syntax.substring(pos+1);
      
syntax.substring(0syntax.length()-1-c.length());
    }
    if (
pos == syntax.length()-1) { // x*
      
3;
      
syntax.substring(0pos);
    }
    if (
0) {
      
temp.out 0;
      
temp.compare syntax.substring(0pos);
      
compare @= syntax.substring(pos+1);
      for(
temp.: array) {
        if (
strict && == compare) continue;
        if (
== 1) {
          if (
i.ends(c)) out.add(i);
        }
        else if (
== 2) {
          if (
i.starts(b) && i.ends(c)) out.add(i);
        }
        else if (
== 3) {
          if (
i.starts(b)) out.add(i);
        }
      }
      return 
out;
    }
  }
  return 
0;

Example:

PHP Code:
function onCreated() { 
  
temp.= {"foo""foo1""bar""barfoo""baroo"};
  
  
temp.find("foo*"a); // foo,foo1
  
temp.find("foo*"atrue); // foo1,
  
  
temp.find("bar*oo"a); // barfoo,baroo
  
temp.find("bar*oo"atrue); // barfoo
  
  
temp.find("*o"a); // foo,barfoo,baroo
  
  
temp.find("*"a); // foo,foo1,bar,barfoo,baroo

Please post any bugs and criticism below I guess.
__________________
Reply With Quote