-
-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace with regex cause stucks #500
Comments
I would guess this is related to #192 It is probably restarting the search after the replace in the incorrect spot, thus an infinite loop. The regex implementation is...quite rough to be honest, and I figured there were quite a few corner cases. My gut feeling is that the QRegularExpression class is not a long term solution. Currently there are 3 options:
|
I think the problem here (and with #192) is actually not QRegularExpression itself; it handles this case fine. I think the issue is with the way it is used with NotepadNext as it seems to be relying on the
Outputs the following:
Which (unless I'm missing something entirely) suggests that the library is fine for this case (tested under QT 5.15 on Debian 12) |
@mintsoft Thanks for the info. You are correct that purely using QRegularExpression does work. However to integrate with the editing component you can't simply just call Each search/replace needs a starting location and ending location. Since the substring is pulled out of the editor and turned into a QString, then |
Ahh I see. It seems like we'd need to change that behaviour no matter which Regex implementation we used to fix the problem. I assume it's implemented like that so that we are able to dynamically update the document as it goes-along and avoid converting the entire document into QString and duplicating everything? |
That is partially correct. If I recall if you use something like That's the whole reason why in the long run I suspect Notepad++'s implementation might be worth while since it uses boostregex and they've already worked out all the corner cases :)
That is a big part of it. The other part is to let Scintilla properly know about each individual change so that it can properly manage the undo stack along with other internals. |
On a side note, Scintilla by default supports the standard library regex |
Yeah, the docs point towards that being quite limited (no |
That is it's own very basic implementation of a regex engine. But it can also use |
It's probably on-par than Scintilla's one, however if you want PCRE (i.e. "proper regex") then the Boost library is the best bet certainly |
Another reproduction of this bug is any find/replace that does not change the actual content or that the replaced string still matches the "find" i.e.: Find This will also loop forever |
|
Notepad++ has used an implementation of the boost regex library with the Scintilla editor and it has been proven to be quite robust over the years (not saying it doesn't have issues). I've looked at the code a little bit before but it is not just a drop-in replacement since it was made for Windows and Win32 https://github.com/notepad-plus-plus/notepad-plus-plus/tree/master/boostregex |
txt file
Replace
^
=>//
Notepad Next CPU load 5%~8%
Memory usage: rise slowly
When debug with WinDbg
I see those lines repeat forever:
const char *__cdecl QRegexSearch::SubstituteByPosition(class Scintilla::Internal::Document *,const char *,__int64 *)
Full log
The text was updated successfully, but these errors were encountered: