Menu

#2338 regex About REGEX_MULTILINE and CXX11_REGEX in Document.cxx

Bug
closed-fixed
4
2022-08-27
2022-06-30
jacky yang
No

regex About REGEX_MULTILINE and CXX11_REGEX in Document.cxx

When you build scintilla with gcc 12.1 or llvm 14,
using -DREGEX_MULTILINE
But "^" and "$" doesn't work as expected.

So you will add some code in Sci::Position Cxx11RegexFindText()

if (!caseSensitive)
    flagsRe = flagsRe | std::regex::icase;

#ifdef REGEX_MULTILINE
flagsRe = flagsRe | std::regex::multiline;
#endif

// Clear the RESearch so can fill in matches
search.Clear();

Now it work.

Replacement with regular expressions allow \1..9

But "$&", "$`", "$'" and "$1..." doesn't work.

May be something would be done in const BuiltinRegex::SubstituteByPosition() ...

Discussion

  • Neil Hodgson

    Neil Hodgson - 2022-07-01
    • Priority: 5 --> 4
     
  • Neil Hodgson

    Neil Hodgson - 2022-07-01

    MSVC 2022 still doesn't define std::regex::multiline:

    1>C:\u\hg\scintilla\src\Document.cxx(3218,35): error C2039: 'multiline': is not a member of 'std::basic_regex<char,std::regex_traits<char>>'
    1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\regex(2047): message : see declaration of 'std::basic_regex<char,std::regex_traits<char>>'
    

    Using the preprocessor to avoid the Visual C++ compiler like following causes problems when using Clang for Windows which uses the Microsoft runtime:

    #if defined(REGEX_MULTILINE) && !defined(_MSC_VER)
            flagsRe = flagsRe | std::regex::multiline;
    #endif
    

    Couldn't find a way to detect the Microsoft C++ headers but it may be possible to detect the libc++ and libstdc++ headers. Another possibility may be some C++ trickery to discover if std::regex::multiline is defined.


    The "$" based captures wouldn't be compatible with the builtin regex and current behaviour. "$`" and "$'" would be referring to the document text before / after the match which doesn't sound very useful. You probably want the contents of the line before / after the match but the code isn't really oriented towards that.

    This should really be a separate issue so that one or the other part can be implemented without leaving behind an partly completed issue.

     
    • Zufu Liu

      Zufu Liu - 2022-07-01

      clang for MSVC target (clang-cl.exe or --target=x86_64-pc-windows-msvc) defined _MSC_VER (so does Intel C++ compiler for Visual Studio).

      clang for mingw target (e.g. --target=x86_64-w64-windows-gnu) doesn't define _MSC_VER.

       
  • Neil Hodgson

    Neil Hodgson - 2022-07-17

    With https://nuwen.net/mingw.html g++ 11.2.0 and #if defined(REGEX_MULTILINE) && !defined(_MSC_VER) I see:

    g++ -DREGEX_MULTILINE -DNDEBUG -I ../include -I ../src --std=c++17 -Wpedantic -Wall -Os  -c ../src/Document.cxx -o Document.o
    ../src/Document.cxx: In function 'Sci::Position {anonymous}::Cxx11RegexFindText(const Scintilla::Internal::Document*, Sci::Position, Sci::Position, const char*, bool, Sci::Position*, Scintilla::Internal::RESearch&)':
    ../src/Document.cxx:3166:49: error: 'multiline' is not a member of 'std::__cxx11::regex' {aka 'std::__cxx11::basic_regex<char>'}
     3166 |                 flagsRe = flagsRe | std::regex::multiline;
          |                                                 ^~~~~~~~~
    make: *** [makefile:77: Document.o] Error 1
    
     
  • Neil Hodgson

    Neil Hodgson - 2022-07-17

    Committed with [562afc].

    Earlier gcc and clang releases failing on regex::multiline can be treated as informative and means that REGEX_MULTILINE should not be turned on.

     

    Related

    Commit: [562afc]

  • Neil Hodgson

    Neil Hodgson - 2022-07-18
    • labels: regex, Regular Expression, Find, Replacemen --> regex, Regular Expression, Find, Replacemen, scintilla
    • status: open --> open-fixed
     
  • Neil Hodgson

    Neil Hodgson - 2022-08-27
    • status: open-fixed --> closed-fixed
     

Log in to post a comment.