SlickEdit Community

SlickEdit Product Discussion => SlickEdit® => Topic started by: jporkkahtc on February 09, 2021, 01:06:03 am

Title: Find & Replace & prompting
Post by: jporkkahtc on February 09, 2021, 01:06:03 am
Given this text in a file:
Code: [Select]
javax.persistence:persistence-api:1.0
com.google.guava:guava:28.0-jre
com.fasterxml.jackson.core:jackson-annotations:2.5.1
com.fasterxml.jackson.datatype:jackson-datatype-joda:2.0.4

If I do F&R and click Replace All
SearchFor: "^[^\r\n:]*:"
ReplaceWith: ""
Code: [Select]
PerlRE
I get:
persistence-api:1.0
guava:28.0-jre
jackson-annotations:2.5.1
jackson-datatype-joda:2.0.4

But, if I do "Replace" and click "Y" on each prompt, then I get:
Code: [Select]
1.0
28.0-jre
2.5.1
2.0.4
because with prompting it replaces more than once per line.
Title: Re: Find & Replace & prompting
Post by: Clark on February 09, 2021, 05:11:35 pm
Replace All has a hack in it to pre-check for a match right after the replaced text. If there isn't a match, then the next search skips one extra character which allows the next regex begin line check to fail. It's specifically written for your test case. I think SlickEdit could perform the same hack for the prompted case. Maybe this can be added for the next release.
Title: Re: Find & Replace & prompting
Post by: jporkkahtc on February 09, 2021, 06:52:01 pm
I could see either behavior being good ... in this case the prompted behavior was surprising and not desired.
Either way, they should behave consistently.
BTW, prompted backwards replacing behaves like ReplaceAll.


Oh ... interesting -- more cases.
Original Text
Code: [Select]
javax.persistence:persistence-api:1.0
com.google.guava:guava:28.0-jre
com.fasterxml.jackson.core:jackson-annotations:2.5.1
com.fasterxml.jackson.datatype:jackson-datatype-joda:2.0.4




------------------------------------------------
Case 1
ReplaceAll "^[^\r\n:]*:" --> "", Search Forwards
As expected, removes the first token from each line
===================
Code: [Select]
persistence-api:1.0
guava:28.0-jre
jackson-annotations:2.5.1
jackson-datatype-joda:2.0.4




------------------------------------------------
Case 2
ReplaceAll "^[^\r\n:]*:" --> "", Search Backwards
Bug
The line the cursor starts on (3) is different than the other results - two tokens removed.
===================
Code: [Select]
persistence-api:1.0
guava:28.0-jre
2.5.1
jackson-datatype-joda:2.0.4




------------------------------------------------
Case 3
Using "$" instead of "^"
ReplaceAll ":[^\r\n:]*$" --> "", Search Backwards
Bug
Same results, forwards and backwards, two tokens removed - expected only one.
===================
Code: [Select]
javax.persistence
com.google.guava
com.fasterxml.jackson.core
com.fasterxml.jackson.datatype




------------------------------------------------
Case 4
Prompted Replace ":[^\r\n:]*$" --> "", Search Forwards
Bug
The line the cursor starts on (2) is different than the other results - two tokens removed.
===================
Code: [Select]
javax.persistence:persistence-api
com.google.guava
com.fasterxml.jackson.core:jackson-annotations
com.fasterxml.jackson.datatype:jackson-datatype-joda
Title: Re: Find & Replace & prompting
Post by: Clark on February 09, 2021, 07:05:23 pm
Backwards search has no special hacks.

I couldn't reproduce case 2 or case 4.
Title: Re: Find & Replace & prompting
Post by: jporkkahtc on February 09, 2021, 07:50:10 pm
Case 2, place you cursor at the start of line 3.
F&R "^[^\r\n:]*:" --> ""
Replace all - Backwards
replace_buffer_text('^[^\r\n:]*:',"LI-P*",'','0','0','0','0','0','0','1');

Case 4, place you cursor at the start of line 2.
F&R ":[^\r\n:]*$" --> ""
Replace all - Forwards
replace_buffer_text(':[^\r\n:]*$',"LIP*",'','0','0','0','0','0','0','1');
Hm... Actually in this case I get the same results with Prompt or ReplaceAll.
Title: Re: Find & Replace & prompting
Post by: Clark on February 09, 2021, 09:05:55 pm
Case #4 is an issue with wrapped search and replace. I'll see if this can be fixed. This one is more important than prompted search and replace since you might not see the problem happen.

Reproduced case #2

I'm not surprised though since there is no special case code for backward searching.
Title: Re: Find & Replace & prompting
Post by: Clark on February 14, 2021, 08:40:37 pm
Case #4 is very different. A simple hack isn’t possible. This case requires that all matches be found before replaces are performed. That can potentially require a lot of memory and a two pass algorithm. This would be bad for large files. It would be weird for SlickEdit to handle large files and small files differently for this case. Its just not worth doing.