Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Wildcard Finder (https://forums.graalonline.com/forums/showthread.php?t=84614)

Chompy 03-10-2009 11:53 PM

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.

cbk1994 03-11-2009 12:08 AM

Very nice, I like it.

Codein 03-11-2009 12:39 AM

Nice work man :D

Chompy 03-11-2009 07:52 AM

Thanks guys.

I'll probably release a new version soon though, which will support more then one wildcard :]

MiniOne 03-11-2009 08:10 AM

Seems right :)
Good work keep it up.

Dan 03-12-2009 12:34 AM

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;



Chompy 03-12-2009 12:53 AM

Nice script Dan ^^

Tigairius 03-12-2009 01:00 AM

Nice work guys :)

MiniOne 03-12-2009 07:53 AM

Nice Dan :)
OMGG That gives me a great idea for a zone event, I'd like to discuss it with you :D
reply my emails...

Dan 03-12-2009 07:08 PM

Thanks for the comments :) My script doesn't have the "strict" stuff yet but that shouldn't be hard.


All times are GMT +2. The time now is 10:18 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.