Comments (10)
It seems like we'd need to change that behaviour no matter which Regex implementation we used to fix the problem.
That is partially correct. If I recall if you use something like re2
(which I believe QRegularExpression
uses) then there are more flags you can pass it to tell it that the beginning of the string you are providing isn't actually the start. But that was a while ago...so maybe I'm misremembering. QRegularExpression
doesn't provide that fine of control.
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 :)
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 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.
from notepadnext.
Yeah, the docs point towards that being quite limited (no ?, or lookaheads/behinds etc)
That is it's own very basic implementation of a regex engine. But it can also use
std::regex
which I'm not sure how well it matches up to something like boost.
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
from notepadnext.
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 (.*)
Replace $1
This will also loop forever
from notepadnext.
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:
- Stick with QRegularExpression and try to deal with all the intricacies and hope there's no "show stoppers".
- Use Scintilla's built in regular expression engine (this has quite a few limitations though, e.g. no multiline matches)
- Or...probably the best option...is try to implement the boost regex engine that Notepad++ uses. It uses boost but it also has to provide an implementation to scintilla so that it can work with that regex engine. I've glanced through Notepad++'s code that does that...and it's not immediately easy to figure out.
from notepadnext.
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 .captured()
returning a non-zero length string. If you use the QRegularExpression in a more direct manner to do the replacements it seems to work, Example:
#include <QtGlobal>
#include <QtCore>
#include <QDebug>
#include <QTextStream>
#include <QRegularExpression>
#include <iostream>
int main(int argc, char *argv[])
{
QTextStream qout(stdout);
auto options = QRegularExpression::MultilineOption | QRegularExpression::UseUnicodePropertiesOption;
QRegularExpression re("^", options);
QString replacement = "//";
QString inputString = "1\n2\n3\n";
QRegularExpressionMatch match = re.match(inputString, 0, QRegularExpression::NormalMatch, QRegularExpression::NoMatchOption);
qDebug() << "input string: ";
qDebug() << inputString;
QString newString = inputString.replace(match.regularExpression(), replacement);
qDebug() << " --------------------- ";
qDebug() << newString;
qDebug() << " --------------------- ";
}
Outputs the following:
input string:
"1\n2\n3\n"
---------------------
"//1\n//2\n//3\n"
---------------------
Which (unless I'm missing something entirely) suggests that the library is fine for this case (tested under QT 5.15 on Debian 12)
from notepadnext.
@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 .replace()
on a string.
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 ^
always matches the beginning of the string, no matter where the search is "started" in the document. Even if you do replace the first valid ^
match with //
then when the search starts again after the previously replaced //
it then finds another match...and gets stuck.
from notepadnext.
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
^
always matches the beginning of the string, no matter where the search is "started" in the document. Even if you do replace the first valid^
match with//
then when the search starts again after the previously replaced//
it then finds another match...and gets stuck.
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?
from notepadnext.
On a side note, Scintilla by default supports the standard library regex std::regex
but I recall looking into that at one time and found some limitations...not sure if things have improved since then.
from notepadnext.
On a side note, Scintilla by default supports the standard library regex
std::regex
but I recall looking into that at one time and found some limitations...not sure if things have improved since then.
Yeah, the docs point towards that being quite limited (no ?
, or lookaheads/behinds etc); I think that's actually the regex engine that Notepad++ used to have about 10 years ago, I remember it was very very limited for a while
from notepadnext.
Yeah, the docs point towards that being quite limited (no ?, or lookaheads/behinds etc)
That is it's own very basic implementation of a regex engine. But it can also use std::regex
which I'm not sure how well it matches up to something like boost.
from notepadnext.
Related Issues (20)
- Multi Session / Instances Support
- Add shortcut for expand and collapse function
- Add command-line argument to open to a line number in a file like notepad++ HOT 5
- Error: CreateDXGIFactory2 at dxgi.dll HOT 4
- Can't open large txt files (~100GiB) HOT 1
- fetch-pack: unexpected disconnect while reading sideband packet HOT 1
- Find/Replace dialog UI arrangement issues for Mac Version HOT 7
- [Bug] When show status bar is set to false, does not take effect after application restart HOT 1
- Exit the Application when the last tab closed HOT 2
- [MAC OS] Close the [New 1] tab after a file opened HOT 1
- Opening a file when another instance is already is running sometimes fails HOT 6
- [MAC] Double-click to open a file and cannot activate the minimized NN window HOT 5
- would you please support edit code styles by user HOT 3
- Better Linux Screenshot HOT 4
- [Feature request] Find index match count HOT 1
- [feature request] temporarily store files when close 'x' button for window is pressed HOT 1
- Notepad++ autosave feature HOT 1
- flatpak runtime end of life HOT 13
- can't type in the macOS HOT 3
- MacOS Dark Mode HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from notepadnext.