You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oro-dev@jakarta.apache.org by Michael Davey - Sun UK Support Engineer <mi...@Sun.COM> on 2002/01/07 16:12:25 UTC

[ORO][Design Discussion] translate

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?

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.

What are your thoughts?

-- 
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

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [ORO][Design Discussion] translate

Posted by "Mark F. Murphy" <ma...@tyrell.com>.
At 3:12 PM +0000 1/7/02, Michael Davey - Sun UK Support Engineer wrote:
>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?

I think it's a good idea.

However... (and I'm going from memory here)... isn't tr/// and y/// 
perl extensions?

If so, perhaps they should go into the Perl utils area if they aren't 
a part of normal regular expressions.

mark

-- 
---------------------------------------------------------------------------
  Mark F. Murphy, Director Software Development   <ma...@tyrell.com>
  Tyrell Software Corp                            <http://www.tyrell.com>
  PowerPerl(tm), Add Power To Your Webpage!       <http://www.powerperl.com>
---------------------------------------------------------------------------
  Families Against Internet Censorship:        http://www.netfamilies.org/

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [ORO][Design Discussion] translate

Posted by nj...@softhome.net.
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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>