Carsten Th�nges wrote:

> * George Mitchell <[EMAIL PROTECTED]> writes:

>> Just for giggles, I decided to write a QT to reverse a string. 

>> %If:"%_Rev_Init"="":"%-
>> %___%If:'%_Rev_Src'='':'%_Rev_Src(%Clipboard)'%-
>> %___%SetPattRegExp('(?s)(.)(.*)')%-
>> %___%_Rev_Out('')%-
>> %___%_Rev_Init('T')":""%-
>> %-
>> %RegExpBlindMatch(%_Rev_Src)%-
>> %_Rev_Out("%Subpatt(1)%_Rev_Out")%-
>> %_Rev_Src(%Subpatt(2))%-
>> %-
>> %If:"%_Rev_Src"<>"":"%Qinclude(rev)":"%_Rev_Out"%-

> Two things you could do to harden your QT:

> a) Check for the length of the input string (here %CLIPBOARD) and
>    cut it to a reasonalbe length or print an error message.

I'd have no idea what to limit it to.  Anyone know if the limit is
based on available memory, or an internal limitation of TB!?

That said, it's an interesting problem.  The following code checks to
see if the clipboard contains more than three characters:

%SetPattRegExp("(?s).{0,3}")%-
%If:"%RegExpMatch(%Clipboard)"="%Clipboard":"<=3":">3"%-

Is there a better way to do that with TB!'s macros?  I sometimes miss
the obvious.

> b) Reduce the number of recursive calls. You just have to modify two
>    lines to speed up the QT and increase the maximum size of your
>    input string:

>    | [...]
>    | %_Rev_Out("%Subpatt(3)%Subpatt(2)%Subpatt(1)%_Rev_Out")%-
>    | %_Rev_Src(%Subpatt(4))%-
>    | [...]

With the regex I used only subpatterns 0-2 would ever contain
anything.  Are you suggesting something like "(?s)(.)(.?)(.?)(.*)"?
I guess that could be extended to n terms.  Pretty clever.

If the recursion limit was knowable to any reasonable degree, a
combination of your two suggestions might make for a useable QT.

> (BTW: you should add this one to Marcks QT Library)

If it can be made to not crash TB!, perhaps.  I'm not sure how much
practical application it has though.  :-P

Thanks for looking at this.  This stuff is pretty fun, but I have a
long way to go...

-- 
George

Using TB! 2.02.3 CE on Windows XP Pro 5.1, Build 2600, Service Pack 1.


________________________________________________________

http://www.silverstones.com/thebat/TBUDLInfo.html

Reply via email to