jakarta-oro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From njc...@softhome.net
Subject Re: [ORO][Design Discussion] translate
Date Mon, 07 Jan 2002 22:30:34 GMT

Hi Michael,

First of all, yes, please do this. See my thoughts below...

Michael Davey - Sun UK Support Engineer writes:

> Hi,
> 
> Over the weekend, I was thinking about adding a translate
> method, probably to regex.Util to do tr/// and y///
> string translations.
> 
> Firstly, good idea?
> 
> Secondly, anyone else thinking about or doing such a thing?

Well, a few months ago I had a similar itch to scratch. The result was
"jtr"[1]. This implements a simple tr/// compiler and interpreter, but
doesn't have the nice Perl-like front end that the Perl5Util class
implements in ORO.

> Thirdly, I couldn't decide whether to implement an ORO
> tr compiler and matcher as if it were regex (which tr
> isn't), or rather to hide all the implementation in
> some private class where the code is similar to
> the internals of the tr(1M) Linux/Unix command.

I think the latter is probably the way to go. From what I've seen of the
ORO substitution code, the algorithm is basically:

* Find a matching expression
* Perform a substitution on the part that matched
* Find the next expression, and so on...

This is fine when the cost of finding each match is fairly expensive, and
there are relatively few matches that would normally result. The tr///
semantics can be quite different, though. Finding a match is trivial, and
in most cases you'd want to replace a character at a time. The ORO
machinery here would make this a lot more expensive than it needs to be.

> What are your thoughts?

Have a look at jtr. If you like it, feel free to use it, since its under
the BSD license. My original idea was to merge it with ORO somewhere along
the track, but other things have taken priority since then.

> -- 
> Michael
> 
> http://www.perl.com/language/ppt/v7/tr.1
> http://www.openbsd.org/cgi-bin/man.cgi?query=tr&sektion=1&apropos=0&manpath=OpenBSD+Current
> 

Hope this helps,

Nicholas
run2000@users.sourceforge.net

[1] http://jtr.sourceforge.net/

--
To unsubscribe, e-mail:   <mailto:oro-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:oro-dev-help@jakarta.apache.org>


Mime
View raw message