Community
    • Login

    Using std::regex causes plugin loading to fail — is there an alternative?

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    5 Posts 4 Posters 693 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • CoisesC
      Coises
      last edited by

      While working on a plugin using Visual Studio 2022, I noticed that when I added some std::regex code, the plugin build was successful but Notepad++ could not load it. Removing the std::regex code made it work again.

      I’m guessing this has something to do with the statement in build . md of Notepad++ that “Notepad++ is always built with Boost regex PCRE support instead of default c++11 regex ECMAScript used by plain Scintilla.” But the implications of that are beyond my understanding of C++ linkage and libraries.

      Is there a way to use regular expressions in a C++ plugin for Notepad++? For my purposes, it probably doesn’t have to be std::regex, though I’ve never used the Boost libraries and have no idea how they work.

      rdipardoR 1 Reply Last reply Reply Quote 0
      • rdipardoR
        rdipardo @Coises
        last edited by rdipardo

        I’m guessing this has something to do with the statement in build . md of Notepad++ that “Notepad++ is always built with Boost regex PCRE support instead of default c++11 regex ECMAScript used by plain Scintilla.”

        Boost is just the regex engine for the editor’s find & replace capabilities. There’s no requirement to use any Boost APIs in a plugin. (You would have to copy the Boost header files into your own project to make that possible).

        Removing the std::regex code made it work again.

        The reason why is basically what you quoted from BUILD.md. Notepad++ “turns off” C++11’s builtin regex support in favour of Boost, as explained here:

        The C++11 <regex> support may be disabled by compiling Scintilla with NO_CXX11_REGEX defined.

        and here:

        A simple interface provides support for switching the Regular Expressions engine at compile time.
        . . .

        Preprocessors affect building

        Preprocessor Description
        NO_CXX11_REGEX Build Scintilla without C++11 std::regex.

        Is there a way to use regular expressions in a C++ plugin for Notepad++?

        Scintilla’s APIs may be enough to get the job done, even if they are “limited and should only be used for simple cases and initial development”.

        1 Reply Last reply Reply Quote 2
        • Derek BrownD
          Derek Brown
          last edited by Derek Brown

          You could try using re2, which is a regex engine by Google, much faster than std::regex, and is available in vcpkg. I have used it in a plugin myself.

          All of Boost is also available in vcpkg, so if you’re unsure how to install Boost that is the best way to go.

          It is pretty easy to set up vcpkg for use with Visual Studio, if you haven’t already. If you have trouble, I can provide some help, but give it a try first.

          Alan KilbornA 1 Reply Last reply Reply Quote 2
          • Alan KilbornA
            Alan Kilborn @Derek Brown
            last edited by

            @Derek-Brown said in Using std::regex causes plugin loading to fail — is there an alternative?:

            easy to set up vcpkg for use with Visual Studio, if you haven’t already. If you have trouble, I can provide some help

            I’d think there might be better, more on-topic, forums for that, but let’s see how it goes.

            1 Reply Last reply Reply Quote 0
            • CoisesC
              Coises
              last edited by

              The problem was not at all what I thought. It turned out to be ordinary user error. There was a fault in the syntax of my regular expression. Having never used C++ regular expressions before, I didn’t know that even when the expression is coded as a character literal, Visual Studio compiles code containing invalid regular expressions without complaint and then throws a run-time error. Because it was in a plug-in dll and it was a static constant (hence, processed on loading), the dll failed to load at all.

              There is no problem loading a plugin that uses std::regex, so long as the expression doesn’t cause an exception.

              Thanks to those who replied.

              1 Reply Last reply Reply Quote 2
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors