RE: :Text::FindAndReplaceAll()

"Greg London" <[email protected]>
Newsgroups gmane.comp.lang.perl.tk
Message-ID <[email protected]>
>>Seems like a bug in the FindNext subroutine of Tk::Text. Basically using (.)
>>or (.*) doesn't seem to work properly.
>
>Someone (Greg London?) re-wrote this bit of TextUndo and I am not sure
>I know how it is supposed to work.

Yeah, that was me, in a previous life.
 
When you hit "ReplaceAll", it calls FindAndReplaceAll in  Tk::Text.
that is a very short routine which looks like this:
 
sub FindAndReplaceAll
{
   my ($w, $mode, $case, $find, $replace)=@_;
   $w->markSet('insert', '1.0');
   $w->unselectAll;
   while($w->FindNext('-forward', $mode, $case, $find))
      {
      $w->ReplaceSelectionWith($replace);
      }
}
 
The FindNext method uses the "search" method,
(not sure where it is defined, I'm a little rusty)
which takes in 
($direction, $mode, $case, count, "--",  $pattern, 'insert').
 
I think search is a low level function somewhere, 
but I don't remember.
 
Apparently, the while loop is stuck for some reason.
 
The FindNext method has a bit that says
 
$start_index = $w->search(
   $direction,
   $mode,
   -count ...
   "--",
   $pattern,
  'insert')
 
and then returns if start_index is not defined
of if its length as a string is 0.
 
apparently, it isn't returning 0, so the while loop never
exits.   
 
As I said, I'm a little rusty, it feels like its been several
years since I looked at this code.  Hopefully the above
will point someone in the right location to look, though.
 
I can look at it when I get some tuits.
 
Greg London
 

________________________________

From: [email protected] on behalf of Nick Ing-Simmons
Sent: Thu 3/9/2006 4:10 PM
To: [email protected]
Cc: [email protected]; [email protected]
Subject: RE: :Text::FindAndReplaceAll()



Jack D. <[email protected]> writes:
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[email protected]] On
>> Behalf Of ????? ????????
>> Sent: December 16, 2005 7:34 AM
>> To: [email protected]
>> Subject: Tk::Text::FindAndReplaceAll()
>>
>> I have a Tk::TextUndo widget. It has context menu which also
>> holds Replace option.
>> I put a single word 'gallo' as a text. Than choose Replace
>> (Direction: any, Mode: regexp, Case: any), put '.*' as a
>> pattern and whatever as a replacement. Push "ReplaceAll". Works fine.
>> Now I put as a text 'gallo' and from the next line 'ballo'.
>> Than choose Replace (Direction: any, Mode: regexp, Case:
>> any), put '.*' as a pattern and non-empty replacement. Push
>> "ReplaceAll". The result - application is hanged (100% CPU
>> consumption). Works fine however if replacement is empty.
>>
>> This wouldn't be the issue if
>> $text_undo->FindAndReplaceAll('-regexp', '-case', qr/.*/,
>> 'whatever'); didn't behave the same nasty way.

The Menu is just sugar for calling that code or something very like it,
so I am _glad_ they behave the same.

>>
>> Is it something I missed or is there a bug in Tk (ActivePerl
>> 5.8.7.813)?
>
>Seems like a bug in the FindNext subroutine of Tk::Text. Basically using (.)
>or (.*) doesn't seem to work properly.

Someone (Greg London?) re-wrote this bit of TextUndo and I am not sure
I know how it is supposed to work.


/./ or /.*/ are supposed to map to perl's normal regular expressions.
So /./ will NOT match the "\n" at end of the line, and /.*/ is allowed
to match nothing. This might surprise the Text code someway.

I seem to recall by original had to do some messy adding of \G and
adding (effect of) /cg to regexp and then manipulate pos().

Also perl/Tk is calling perl's re C code in a devious manner which may
well not be robust as perl's regexp engine changes over time.
If I haven't got the "make a copy" flags right then when length of string
changes it may re-start from wrong place.


>i.e. the program gets stuck in a while loop because the $saved_insert never
>matches the $compared_index in the source code. I have cc'd the ptk mailing
>list for their thoughts.

Will try and decipher what I have imported.

>
>Jack
>_______________________________________________
>Perl-Win32-Users mailing list
>[email protected]
>To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>-++**==--++**==--++**==--++**==--++**==--++**==--++**==
>This message was posted through the Stanford campus mailing list
>server.  If you wish to unsubscribe from this mailing list, send the
>message body of "unsubscribe ptk" to [email protected]


-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.