[ANN] Joker -- Wildcards for Ruby

  • Thread starter Fabian Streitel
  • Start date
F

Fabian Streitel

[Note: parts of this message were removed to make it a legal post.]

Hi folks,
I'm proudly presenting:

# Joker #

http://karottenreibe.github.com/joker

Joker is a Wildcard implementation for Ruby.

## Features ##

* Behaves much like Regexp
* ` * ` and ` ? ` as wildcard characters
* ` \ ` for escaping
* `\a` matches `\a`, but not `a`
* Wildcards must always match whole string
* Wildcards can be case insensitive

Visit the website to see a small example etc.

Greetz!
 
J

James Edward Gray II

I'm proudly presenting:

# Joker #

http://karottenreibe.github.com/joker

Joker is a Wildcard implementation for Ruby.

## Features ##

* Behaves much like Regexp
* ` * ` and ` ? ` as wildcard characters
* ` \ ` for escaping
* `\a` matches `\a`, but not `a`
* Wildcards must always match whole string
* Wildcards can be case insensitive

Can you suggest why someone would use this instead of a regular
expression?

James Edward Gray II
 
F

Fabian Streitel

[Note: parts of this message were removed to make it a legal post.]

because "non-computer people" :)-) might find wildcards more easily
understandable than regular expressions.

This is of course not meant as a replacement for regexps when you're
writing code but rather as a way to interface with people who don't
know about regexps

think directory listings, search queries etc.

Greetz!
 
F

Fabian Streitel

[Note: parts of this message were removed to make it a legal post.]
Note that these are known as "glob patterns" -- you might want to update
your documentation accordingly (http://en.wikipedia.org/wiki/Glob_pattern)

Ah, thx, I've been searching for the correct name of these but couldn't find
it.
The only thing I've ever heard was "Wildcard".

Also, your rdocs seem to be missing a few backslashes:

* '?' matches a single character
* '*' matches any number of characters, including 0
(1) * '*' matches a literal '*'
* '\?' matches a literal '?'
(2) * '\' matches a literal '\'

1 should be: '\*' matches a literal '*'
2 should be: '\\' matches a literal '\'

You could generalize by saying:
* '\x' matches the literal character 'x', even if 'x' is a wildcard
character.

I'll do that.

You haven't implemented bracket expressions: '[cb]at*' should match
'catch' and 'batch' but not 'match'

I'll look into that.

Thanks for the feedback!
 
F

Fabian Streitel

[Note: parts of this message were removed to make it a legal post.]

Whoops overlooked one:

You could generalize by saying:
* '\x' matches the literal character 'x', even if 'x' is a wildcard
character.
That's exactly not what my implementation does. Since I had the library in
mind as
a way to interact with users who don't know about Regular Expressions, I
wanted
to keep it as simple as possible.

Thus, the Ruby String "fo\\o" fed to the Wildcard class would be equivalent
to /^fo\\o$/
but I'm not sure if that was a wise decision. The reasoning behind it was,
that users woudn't
have to type things like
C:\\foo\\bar\\goo
but rather only
C:\foo\bar\goo
since f b and g are no special characters.

Does that make sense? What do you think? Which approach to take or should
there be an option
and if so what's the wiser default?
Greetz!
 
J

Joel VanderWerf

Just a thought... ruby already has globbing functions in dir.c, but they
apparently work only on dirs. Maybe they could be abstracted in to a
library that works on strings or arrays of strings.
 
F

Fabian Streitel

[Note: parts of this message were removed to make it a legal post.]
Just a thought... ruby already has globbing functions in dir.c, but they
apparently work only on dirs. Maybe they could be abstracted in to a library
that works on strings or arrays of strings.

Honestly: I have no idea what's going on in that file...
That's just too complicated C magic whuzzing around in there.

But a problem with that approach -- as far as I can tell -- is that
matching a glob against a string and matching it against the
file system are 2 different things. Especially since "/" or "\" have
special meaning in file systems and allow for splitting of the glob
string into small subsections, whose matching against files is much
easier.
Also dir.c has the special "**" glob, which doesn't make and sense
in string matching.

Greetz!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top