Author Topic: Find & Replace & prompting  (Read 1286 times)

jporkkahtc

  • Senior Community Member
  • Posts: 2620
  • Hero Points: 210
  • Text
Find & Replace & prompting
« 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.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6884
  • Hero Points: 530
Re: Find & Replace & prompting
« Reply #1 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.

jporkkahtc

  • Senior Community Member
  • Posts: 2620
  • Hero Points: 210
  • Text
Re: Find & Replace & prompting
« Reply #2 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

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6884
  • Hero Points: 530
Re: Find & Replace & prompting
« Reply #3 on: February 09, 2021, 07:05:23 PM »
Backwards search has no special hacks.

I couldn't reproduce case 2 or case 4.

jporkkahtc

  • Senior Community Member
  • Posts: 2620
  • Hero Points: 210
  • Text
Re: Find & Replace & prompting
« Reply #4 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.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6884
  • Hero Points: 530
Re: Find & Replace & prompting
« Reply #5 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.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6884
  • Hero Points: 530
Re: Find & Replace & prompting
« Reply #6 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.