MantisBT - Doomseeker
View Issue Details
0003809Doomseeker[All Projects] Cleanuppublic2020-06-07 03:542020-06-08 01:04
WubTheCaptain 
 
nonetweaksometimes
confirmedopen 
1.3.1 
 
0003809: Some string literals with escaped characters are not raw string literals (modernize-raw-string-literal)
Ugly escape characters in some source code, impeding readability.
Some examples from a common regex:
$ grep -r "a-z" src/
src/plugins/zandronum/zandronumserver.cpp:const QRegExp ZandronumVersion::versionExpression(R"((\d+).(\d+)(?:.(\d+)(?:.(\d+))?)?(?:-([a-zA-Z]*)?)?(?:-r(\d+)(?:-(\d+))?)?)");

src/plugins/zandronum/zandronumrconprotocol.cpp:        static const QRegExp colorCode(R"(\\c(\[[a-zA-Z0-9]*\]|[a-v+\-!*]))");

src/core/gui/widgets/serverconsole.cpp:         static const QRegExp colorCode("\034(\\[[a-zA-Z0-9]*\\]|[a-v+\\-!*])");

src/core/irc/ircnicknamecompleter.cpp:          const QString NICKNAME_MATCH = R"(\[\]\{\}\-\^\`\|\\A-Za-z0-9_)";

src/core/commandline.cpp:       QRegExp reallySafestCharsIHope = QRegExp("[^a-z0-9/\\_-+]", 
Qt::CaseInsensitive);
src/core/serverapi/serverstructs.cpp:   return name.toLower().remove(QRegExp("[^a-z0-9]"));

Notice serverconsole.cpp and commandline.cpp containing a double backslash (escape characters).

Some of these may be better as raw string literals:
$ grep -r '\\\"' src/ | wc -l
127
'https://clang.llvm.org/extra/clang-tidy/checks/modernize-raw-string-literal.html [^]'
No tags attached.
Issue History
2020-06-07 03:54WubTheCaptainNew Issue
2020-06-07 03:56WubTheCaptainNote Added: 0021362
2020-06-07 19:57Pol MStatusnew => confirmed
2020-06-08 01:04Blzut3Note Added: 0021404

Notes
(0021362)
WubTheCaptain   
2020-06-07 03:56   
Also looking closer, some of those regexes might look suspect while being parsed as raw string literals (instead of just string literals).
(0021404)
Blzut3   
2020-06-08 01:04   
Actually somehow missed that C++ had these raw string literally until a few weeks ago. Converting the escape heavy strings (like the regexps) would be a nice way to tidy things up, but yeah you would definitely need to make sure that they're coming out of the transformation correctly.