Bug 75806 - SearchWords in ReplaceDescriptor
Summary: SearchWords in ReplaceDescriptor
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Andreas Heinisch
URL:
Whiteboard: target:6.5.0
Keywords:
: 107916 133084 (view as bug list)
Depends on:
Blocks: Macro-UNOAPI
  Show dependency treegraph
 
Reported: 2014-03-05 16:38 UTC by Goff
Modified: 2020-05-20 06:57 UTC (History)
8 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Goff 2014-03-05 16:38:31 UTC
Let say, we have text and we need to replace all words "he" with "his". Also, we keep in mind that "he" may be beginning with capital - "He". 

Dim oDocument As Object
Dim oReplace As Object

oDocument = ThisComponent
	
oReplace = oDocument.createReplaceDescriptor
oReplace.searchAll=True

oReplace.SearchString = "(h)e"
oReplace.ReplaceString = "$1is"
oReplace.SearchRegularExpression = true
oReplace.SearchCaseSensitive = false
oReplace.SearchWords = true
oDocument.replaceAll(oReplace)

This macro replaces all "he/He" with "his/His", but all "she" will be replaced with "shis" as well.

"oReplace.SearchWords = true" does not work.

This bug is relevant to all versions of LibreOffice and OpenOffice.
Comment 1 Joel Madero 2014-03-07 03:23:28 UTC
Noel - thoughts on this one?
Comment 2 Goff 2014-03-11 19:47:23 UTC
Nobody is interesting?
Comment 3 Goff 2014-04-01 19:40:10 UTC
Looking for workaround for this bug, I found a next one.

Dim oDocument As Object
Dim oReplace As Object

oDocument = ThisComponent
	
oReplace = oDocument.createReplaceDescriptor
oReplace.searchAll=True

oReplace.SearchString = "\<(h)e\>"
oReplace.ReplaceString = "$1is"
oReplace.SearchRegularExpression = true
oReplace.SearchCaseSensitive = false
oDocument.replaceAll(oReplace)

Expected - he/He replaced with his/His and she will not be replaced

Current - all he/He replaced with $1is

Any ideas?
Comment 4 Joel Madero 2014-04-01 20:11:52 UTC
Please don't up the priority of your own bugs
Comment 5 Goff 2014-04-01 20:27:47 UTC
I will not.
Comment 6 Joel Madero 2014-04-01 21:30:59 UTC
Goff - are you trying to find someone to mentor you so you can make a patch or are you asking for workarounds?

If you're looking for a mentor I'll try to help - if you're asking for "user advice" on how to proceed given the problem - I suggest going to the ask.libreoffice.org site or the mailing list.
Comment 7 Goff 2014-04-03 14:15:29 UTC
Thank you Joel!

Unfortunately, I'm not able to patch this bug even supported by your help. And I've found a workaround, so it is not a bug that is crucial for me personally. I just want to tell - there are two bugs and this bugs exist since years, and LibreOffice will be better without this bugs because workaround looks not pretty. That is all.

Workaround (if someone has same problems):

Dim oDocument As Object
Dim oReplace As Object

oDocument = ThisComponent
	
oReplace = oDocument.createReplaceDescriptor
oReplace.searchAll=True

oReplace.SearchString = "([^A-Za-z]h|^h)e\>"
oReplace.ReplaceString = "$1is"
oReplace.SearchRegularExpression = true
oReplace.SearchCaseSensitive = false
oDocument.replaceAll(oReplace)

Thank you for your offer))
Comment 8 QA Administrators 2015-06-08 14:43:18 UTC Comment hidden (obsolete)
Comment 9 goff@rg-rb.de 2015-10-30 17:50:26 UTC
Confirmed in LO 5.0.2
Comment 10 Daveo 2016-01-29 21:12:06 UTC
It might not apply to this issue, but I was encountering a similar error with the "Alternative Searching 1.4.1" extension reporting "SearchCaseSensitive" in object  Desc = ThisComponent.createSearchDescriptor"
My issue appears to have been resolved in today's RC 5.1.0.3
Comment 11 QA Administrators 2017-03-06 14:13:17 UTC Comment hidden (obsolete)
Comment 12 goff@rg-rb.de 2017-03-07 22:46:21 UTC
Both bugs are still here. LibreOffice 5.3.0
Comment 13 QA Administrators 2018-03-08 03:44:38 UTC Comment hidden (obsolete)
Comment 14 Andreas Heinisch 2019-12-02 13:05:06 UTC
I investigated the bug and for me the behaviour of LO is partially correct, because the replaceDescriptor does not support the SearchWords flag, if we search using regular expressions, because they itself have the word boundary capturing group, i.e., \b. So the example should work using:

oReplace.SearchString = "\b(h)e\b"
oReplace.ReplaceString = "$1is"
oReplace.SearchRegularExpression = true

This example indeed works in the search and replace dialog in Writer, but it replaces all the he/He with $1is. I think this is the main bug.

Any thoughts?
Comment 15 goff@rg-rb.de 2019-12-02 17:15:12 UTC
Updt. First appearance of He replaced with His, all following - with $1is
Comment 16 Andreas Heinisch 2019-12-02 18:21:21 UTC
ReplaceAll replaces all he/He with $1is and a simple replace does nothing and jumps to the next he/He. However, if the \b is omitted, all occurences of he/He will be found.
Comment 17 Mike Kaganski 2019-12-18 09:28:36 UTC
FTR, steps:

1. In a new text document, insert dummy text using dt<F3>, which gives a text starting with "He ..."
2. Ctrl+H
3. Use regular expressions; search for `\b(h)e\b`, replace with `$1is`
4. Try using Replace
5. Try Replace All

Result of #4 is nothing happens for all but first [Hh]e; result of #5 is all but 1st [Hh]e turn into $1is.
Comment 18 Commit Notification 2019-12-19 04:30:38 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/eb973a46ba0e34026db2d2929f2aa10505623872

tdf#75806: use actual string leading characters for correct precondition match

It will be available in 6.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 19 Commit Notification 2019-12-19 08:17:33 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/fd8f926b0e409d49d235409daaf8f7aa8532cc40

tdf#75806: extend SwUiWriterTest::testTextSearch to test relevant regexes

It will be available in 6.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 20 Mike Kaganski 2019-12-19 09:45:10 UTC
*** Bug 107916 has been marked as a duplicate of this bug. ***
Comment 21 Dieter 2020-05-20 06:57:52 UTC
*** Bug 133084 has been marked as a duplicate of this bug. ***