Re: 'change'
Re: 'change'
- Subject: Re: 'change'
- From: has <email@hidden>
- Date: Tue, 4 Dec 2001 23:33:36 +0000
Michael Sullivan wrote:
>
> (doesn't it strike others as odd that Apple didn't include even base text
>
> functions like this in a standard library?!?)
>
>
In this case no, because it can be implemented quite easily with TIDs
Mmmm... Might I repectfully disagree here?
There are several differences between Satimage's change and the TID-based
method (hereafter referred to as the "TID-shuffle":):
1. It's one line of code versus 8
2. It doesn't barf if there's more than approximately 4000 matches. (I've
just released a library on AppleMods that avoids this risk, though this
involves additional code so is even longer.)
3. Case-sensitivity is optional. Adding "without case sensitive" makes
replaces case-insensitive. I've yet to figure out a vanilla AS algorithm
for doing case-insensitive searches that doesn't suck for speed.
4. Satimage's "change" also allows regular expressions to be used. Although
it doesn't cover quite everything I'd like to see in my perfect regex, it
does a pretty good job nevertheless. I think that AS's lack of native regex
is one of the things that causes Real Scripters - i.e. those poor misguided
folks who consider stuff such as:
$line =~ s|http://([^w\.]*)|<A HREF="
http://$1">
http://$1</A>|ig;
to be the very model of readability** - to regard AS as "not a serious
language".
[**Perlmonks, please don't hit me...<ouch>;]
i.e. The TID-shuffle may have its uses, but a good find-and-replace osax
with case-sensitivity and regex options blows even the best of them clean
out of the water. No contest. So it's a real shame that there isn't one in
AS as standard. BTW, if you ain't ever used regexes, you're missing some
mightily powerful stuff. You should try 'em.
>
The one thing I can't figure out how to do with TIDs is to break things
>
into words for processing but *remembering* what kind of whitespace
>
delimited them. I keep thinking I'll come up with a clever trick but
>
it's just not happening.
For that sort of messing, you really need to use a scriptable text editor,
I suspect. Unfortunately, there's no way to do stuff like "set theString's
word x to newWord" within AS (you can only "get word x of theString"), and
the vanilla alternatives are all likely to be moderately gruesome. Unless
it's something that could be done with regexes, in which case the Satimage
osax is perhaps your best bet as it's the only one that currently works on
both Classic and X. (One small note: it's currently got a some juicy little
bugs in it which I've passed onto Emmanuel. So you might prefer to use
another until it's fixed.)
Cheers,
has