1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Disable current RegEx implementation.

POCO switched to pcre2.
This commit is contained in:
Sandu Liviu Catalin 2023-03-23 20:22:12 +02:00
parent aca50cab7c
commit 3cd3320e02
2 changed files with 591 additions and 591 deletions

View File

@ -13,9 +13,9 @@ SQMOD_DECL_TYPENAME(SqRxMatchesTypename, _SC("SqRxMatches"))
SQMOD_DECL_TYPENAME(SqRxInstanceTypename, _SC("SqRxInstance")) SQMOD_DECL_TYPENAME(SqRxInstanceTypename, _SC("SqRxInstance"))
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
bool RxInstance::STUDY = true; // bool RxInstance::STUDY = true;
int RxInstance::OPTIONS = 0; // int RxInstance::OPTIONS = 0;
int RxInstance::STUDY_OPTIONS = 0; // int RxInstance::STUDY_OPTIONS = 0;
// ================================================================================================ // ================================================================================================
void Register_RegEx(HSQUIRRELVM vm) void Register_RegEx(HSQUIRRELVM vm)
@ -61,131 +61,131 @@ void Register_RegEx(HSQUIRRELVM vm)
.Func(_SC("WhileRange"), &RxMatches::WhileRange) .Func(_SC("WhileRange"), &RxMatches::WhileRange)
.Func(_SC("SubStr"), &RxMatches::SubStr) .Func(_SC("SubStr"), &RxMatches::SubStr)
); );
RootTable(vm).Bind(_SC("SqRx"), // RootTable(vm).Bind(_SC("SqRx"),
Class< RxInstance, NoCopy< RxInstance > >(vm, SqRxInstanceTypename::Str) // Class< RxInstance, NoCopy< RxInstance > >(vm, SqRxInstanceTypename::Str)
// Constructors // // Constructors
.Ctor() // .Ctor()
.Ctor< StackStrF & >() // .Ctor< StackStrF & >()
.Ctor< int, StackStrF & >() // .Ctor< int, StackStrF & >()
.Ctor< int, bool, StackStrF & >() // .Ctor< int, bool, StackStrF & >()
// Meta-methods // // Meta-methods
.SquirrelFunc(_SC("_typename"), &SqRxInstanceTypename::Fn) // .SquirrelFunc(_SC("_typename"), &SqRxInstanceTypename::Fn)
//.Func(_SC("_tostring"), &CPlayer::ToString) // //.Func(_SC("_tostring"), &CPlayer::ToString)
// Static Values // // Static Values
.SetStaticValue(_SC("STUDY"), RxInstance::STUDY) // .SetStaticValue(_SC("STUDY"), RxInstance::STUDY)
.SetStaticValue(_SC("OPTIONS"), RxInstance::OPTIONS) // .SetStaticValue(_SC("OPTIONS"), RxInstance::OPTIONS)
.SetStaticValue(_SC("STUDY_OPTIONS"), RxInstance::STUDY_OPTIONS) // .SetStaticValue(_SC("STUDY_OPTIONS"), RxInstance::STUDY_OPTIONS)
// Properties // // Properties
.Prop(_SC("Valid"), &RxInstance::IsValid) // .Prop(_SC("Valid"), &RxInstance::IsValid)
.Prop(_SC("Studied"), &RxInstance::IsStudied) // .Prop(_SC("Studied"), &RxInstance::IsStudied)
// Member Methods // // Member Methods
.FmtFunc(_SC("CompileF"), &RxInstance::Compile1) // .FmtFunc(_SC("CompileF"), &RxInstance::Compile1)
.FmtFunc(_SC("CompileExF"), &RxInstance::Compile2) // .FmtFunc(_SC("CompileExF"), &RxInstance::Compile2)
.FmtFunc(_SC("TryCompileF"), &RxInstance::TryCompile1) // .FmtFunc(_SC("TryCompileF"), &RxInstance::TryCompile1)
.FmtFunc(_SC("TryCompileExF"), &RxInstance::TryCompile2) // .FmtFunc(_SC("TryCompileExF"), &RxInstance::TryCompile2)
.FmtFunc(_SC("MatchFirst"), &RxInstance::MatchFirst) // .FmtFunc(_SC("MatchFirst"), &RxInstance::MatchFirst)
.FmtFunc(_SC("MatchFirstEx"), &RxInstance::MatchFirst_) // .FmtFunc(_SC("MatchFirstEx"), &RxInstance::MatchFirst_)
.FmtFunc(_SC("MatchFirstFrom"), &RxInstance::MatchFirstFrom) // .FmtFunc(_SC("MatchFirstFrom"), &RxInstance::MatchFirstFrom)
.FmtFunc(_SC("MatchFirstFromEx"), &RxInstance::MatchFirstFrom_) // .FmtFunc(_SC("MatchFirstFromEx"), &RxInstance::MatchFirstFrom_)
.FmtFunc(_SC("Match"), &RxInstance::Match) // .FmtFunc(_SC("Match"), &RxInstance::Match)
.FmtFunc(_SC("MatchEx"), &RxInstance::Match_) // .FmtFunc(_SC("MatchEx"), &RxInstance::Match_)
.FmtFunc(_SC("MatchFrom"), &RxInstance::MatchFrom) // .FmtFunc(_SC("MatchFrom"), &RxInstance::MatchFrom)
.FmtFunc(_SC("MatchFromEx"), &RxInstance::MatchFrom_) // .FmtFunc(_SC("MatchFromEx"), &RxInstance::MatchFrom_)
.FmtFunc(_SC("Matches"), &RxInstance::Matches) // .FmtFunc(_SC("Matches"), &RxInstance::Matches)
.FmtFunc(_SC("MatchesEx"), &RxInstance::Matches_) // .FmtFunc(_SC("MatchesEx"), &RxInstance::Matches_)
.FmtFunc(_SC("MatchesEx2"), &RxInstance::MatchesEx) // .FmtFunc(_SC("MatchesEx2"), &RxInstance::MatchesEx)
// Member Overloads // // Member Overloads
.Overload(_SC("Compile"), &RxInstance::Compile1) // .Overload(_SC("Compile"), &RxInstance::Compile1)
.Overload(_SC("Compile"), &RxInstance::Compile2) // .Overload(_SC("Compile"), &RxInstance::Compile2)
.Overload(_SC("TryCompile"), &RxInstance::TryCompile1) // .Overload(_SC("TryCompile"), &RxInstance::TryCompile1)
.Overload(_SC("TryCompile"), &RxInstance::TryCompile2) // .Overload(_SC("TryCompile"), &RxInstance::TryCompile2)
.Overload(_SC("Study"), &RxInstance::Study0) // .Overload(_SC("Study"), &RxInstance::Study0)
.Overload(_SC("Study"), &RxInstance::Study1) // .Overload(_SC("Study"), &RxInstance::Study1)
); // );
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
ConstTable(vm).Enum(_SC("SqRxOption"), Enumeration(vm) // ConstTable(vm).Enum(_SC("SqRxOption"), Enumeration(vm)
.Const(_SC("Caseless"), static_cast< SQInteger >(PCRE_CASELESS)) // .Const(_SC("Caseless"), static_cast< SQInteger >(PCRE_CASELESS))
.Const(_SC("Multiline"), static_cast< SQInteger >(PCRE_MULTILINE)) // .Const(_SC("Multiline"), static_cast< SQInteger >(PCRE_MULTILINE))
.Const(_SC("Dotall"), static_cast< SQInteger >(PCRE_DOTALL)) // .Const(_SC("Dotall"), static_cast< SQInteger >(PCRE_DOTALL))
.Const(_SC("Extended"), static_cast< SQInteger >(PCRE_EXTENDED)) // .Const(_SC("Extended"), static_cast< SQInteger >(PCRE_EXTENDED))
.Const(_SC("Anchored"), static_cast< SQInteger >(PCRE_ANCHORED)) // .Const(_SC("Anchored"), static_cast< SQInteger >(PCRE_ANCHORED))
.Const(_SC("DollarEndOnly"), static_cast< SQInteger >(PCRE_DOLLAR_ENDONLY)) // .Const(_SC("DollarEndOnly"), static_cast< SQInteger >(PCRE_DOLLAR_ENDONLY))
.Const(_SC("Extra"), static_cast< SQInteger >(PCRE_EXTRA)) // .Const(_SC("Extra"), static_cast< SQInteger >(PCRE_EXTRA))
.Const(_SC("NotBOL"), static_cast< SQInteger >(PCRE_NOTBOL)) // .Const(_SC("NotBOL"), static_cast< SQInteger >(PCRE_NOTBOL))
.Const(_SC("NotEOL"), static_cast< SQInteger >(PCRE_NOTEOL)) // .Const(_SC("NotEOL"), static_cast< SQInteger >(PCRE_NOTEOL))
.Const(_SC("UnGreedy"), static_cast< SQInteger >(PCRE_UNGREEDY)) // .Const(_SC("UnGreedy"), static_cast< SQInteger >(PCRE_UNGREEDY))
.Const(_SC("NotEmpty"), static_cast< SQInteger >(PCRE_NOTEMPTY)) // .Const(_SC("NotEmpty"), static_cast< SQInteger >(PCRE_NOTEMPTY))
.Const(_SC("UTF8"), static_cast< SQInteger >(PCRE_UTF8)) // .Const(_SC("UTF8"), static_cast< SQInteger >(PCRE_UTF8))
.Const(_SC("UTF16"), static_cast< SQInteger >(PCRE_UTF16)) // .Const(_SC("UTF16"), static_cast< SQInteger >(PCRE_UTF16))
.Const(_SC("UTF32"), static_cast< SQInteger >(PCRE_UTF32)) // .Const(_SC("UTF32"), static_cast< SQInteger >(PCRE_UTF32))
.Const(_SC("NoAutoCapture"), static_cast< SQInteger >(PCRE_NO_AUTO_CAPTURE)) // .Const(_SC("NoAutoCapture"), static_cast< SQInteger >(PCRE_NO_AUTO_CAPTURE))
.Const(_SC("NoUTF8Check"), static_cast< SQInteger >(PCRE_NO_UTF8_CHECK)) // .Const(_SC("NoUTF8Check"), static_cast< SQInteger >(PCRE_NO_UTF8_CHECK))
.Const(_SC("NoUTF16Check"), static_cast< SQInteger >(PCRE_NO_UTF16_CHECK)) // .Const(_SC("NoUTF16Check"), static_cast< SQInteger >(PCRE_NO_UTF16_CHECK))
.Const(_SC("NoUTF32Check"), static_cast< SQInteger >(PCRE_NO_UTF32_CHECK)) // .Const(_SC("NoUTF32Check"), static_cast< SQInteger >(PCRE_NO_UTF32_CHECK))
.Const(_SC("AutoCallout"), static_cast< SQInteger >(PCRE_AUTO_CALLOUT)) // .Const(_SC("AutoCallout"), static_cast< SQInteger >(PCRE_AUTO_CALLOUT))
.Const(_SC("PartialSoft"), static_cast< SQInteger >(PCRE_PARTIAL_SOFT)) // .Const(_SC("PartialSoft"), static_cast< SQInteger >(PCRE_PARTIAL_SOFT))
.Const(_SC("Partial"), static_cast< SQInteger >(PCRE_PARTIAL)) // .Const(_SC("Partial"), static_cast< SQInteger >(PCRE_PARTIAL))
.Const(_SC("NeverUTF"), static_cast< SQInteger >(PCRE_NEVER_UTF)) // .Const(_SC("NeverUTF"), static_cast< SQInteger >(PCRE_NEVER_UTF))
.Const(_SC("DfaShortest"), static_cast< SQInteger >(PCRE_DFA_SHORTEST)) // .Const(_SC("DfaShortest"), static_cast< SQInteger >(PCRE_DFA_SHORTEST))
.Const(_SC("NoAutoPossess"), static_cast< SQInteger >(PCRE_NO_AUTO_POSSESS)) // .Const(_SC("NoAutoPossess"), static_cast< SQInteger >(PCRE_NO_AUTO_POSSESS))
.Const(_SC("DfaRestart"), static_cast< SQInteger >(PCRE_DFA_RESTART)) // .Const(_SC("DfaRestart"), static_cast< SQInteger >(PCRE_DFA_RESTART))
.Const(_SC("FirstLine"), static_cast< SQInteger >(PCRE_FIRSTLINE)) // .Const(_SC("FirstLine"), static_cast< SQInteger >(PCRE_FIRSTLINE))
.Const(_SC("DupNames"), static_cast< SQInteger >(PCRE_DUPNAMES)) // .Const(_SC("DupNames"), static_cast< SQInteger >(PCRE_DUPNAMES))
.Const(_SC("NewLineCR"), static_cast< SQInteger >(PCRE_NEWLINE_CR)) // .Const(_SC("NewLineCR"), static_cast< SQInteger >(PCRE_NEWLINE_CR))
.Const(_SC("NewLineLF"), static_cast< SQInteger >(PCRE_NEWLINE_LF)) // .Const(_SC("NewLineLF"), static_cast< SQInteger >(PCRE_NEWLINE_LF))
.Const(_SC("NewLineCRLF"), static_cast< SQInteger >(PCRE_NEWLINE_CRLF)) // .Const(_SC("NewLineCRLF"), static_cast< SQInteger >(PCRE_NEWLINE_CRLF))
.Const(_SC("NewLineAny"), static_cast< SQInteger >(PCRE_NEWLINE_ANY)) // .Const(_SC("NewLineAny"), static_cast< SQInteger >(PCRE_NEWLINE_ANY))
.Const(_SC("NewLineAnyCRLF"), static_cast< SQInteger >(PCRE_NEWLINE_ANYCRLF)) // .Const(_SC("NewLineAnyCRLF"), static_cast< SQInteger >(PCRE_NEWLINE_ANYCRLF))
.Const(_SC("BsrAnyCRLF"), static_cast< SQInteger >(PCRE_BSR_ANYCRLF)) // .Const(_SC("BsrAnyCRLF"), static_cast< SQInteger >(PCRE_BSR_ANYCRLF))
.Const(_SC("BsrUnicode"), static_cast< SQInteger >(PCRE_BSR_UNICODE)) // .Const(_SC("BsrUnicode"), static_cast< SQInteger >(PCRE_BSR_UNICODE))
.Const(_SC("JavaScriptCompat"), static_cast< SQInteger >(PCRE_JAVASCRIPT_COMPAT)) // .Const(_SC("JavaScriptCompat"), static_cast< SQInteger >(PCRE_JAVASCRIPT_COMPAT))
.Const(_SC("NoStartOptimize"), static_cast< SQInteger >(PCRE_NO_START_OPTIMIZE)) // .Const(_SC("NoStartOptimize"), static_cast< SQInteger >(PCRE_NO_START_OPTIMIZE))
.Const(_SC("NoStartOptimise"), static_cast< SQInteger >(PCRE_NO_START_OPTIMISE)) // .Const(_SC("NoStartOptimise"), static_cast< SQInteger >(PCRE_NO_START_OPTIMISE))
.Const(_SC("PartialHard"), static_cast< SQInteger >(PCRE_PARTIAL_HARD)) // .Const(_SC("PartialHard"), static_cast< SQInteger >(PCRE_PARTIAL_HARD))
.Const(_SC("NotEmptyAtStart"), static_cast< SQInteger >(PCRE_NOTEMPTY_ATSTART)) // .Const(_SC("NotEmptyAtStart"), static_cast< SQInteger >(PCRE_NOTEMPTY_ATSTART))
.Const(_SC("UCP"), static_cast< SQInteger >(PCRE_UCP)) // .Const(_SC("UCP"), static_cast< SQInteger >(PCRE_UCP))
); // );
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
ConstTable(vm).Enum(_SC("SqRxError"), Enumeration(vm) // ConstTable(vm).Enum(_SC("SqRxError"), Enumeration(vm)
.Const(_SC("NoMatch"), static_cast< SQInteger >(PCRE_ERROR_NOMATCH)) // .Const(_SC("NoMatch"), static_cast< SQInteger >(PCRE_ERROR_NOMATCH))
.Const(_SC("Null"), static_cast< SQInteger >(PCRE_ERROR_NULL)) // .Const(_SC("Null"), static_cast< SQInteger >(PCRE_ERROR_NULL))
.Const(_SC("BadOption"), static_cast< SQInteger >(PCRE_ERROR_BADOPTION)) // .Const(_SC("BadOption"), static_cast< SQInteger >(PCRE_ERROR_BADOPTION))
.Const(_SC("BadMagic"), static_cast< SQInteger >(PCRE_ERROR_BADMAGIC)) // .Const(_SC("BadMagic"), static_cast< SQInteger >(PCRE_ERROR_BADMAGIC))
.Const(_SC("UnknownOpCode"), static_cast< SQInteger >(PCRE_ERROR_UNKNOWN_OPCODE)) // .Const(_SC("UnknownOpCode"), static_cast< SQInteger >(PCRE_ERROR_UNKNOWN_OPCODE))
.Const(_SC("UnknownNode"), static_cast< SQInteger >(PCRE_ERROR_UNKNOWN_NODE)) // .Const(_SC("UnknownNode"), static_cast< SQInteger >(PCRE_ERROR_UNKNOWN_NODE))
.Const(_SC("NoMemory"), static_cast< SQInteger >(PCRE_ERROR_NOMEMORY)) // .Const(_SC("NoMemory"), static_cast< SQInteger >(PCRE_ERROR_NOMEMORY))
.Const(_SC("NoSubstring"), static_cast< SQInteger >(PCRE_ERROR_NOSUBSTRING)) // .Const(_SC("NoSubstring"), static_cast< SQInteger >(PCRE_ERROR_NOSUBSTRING))
.Const(_SC("MatchLimit"), static_cast< SQInteger >(PCRE_ERROR_MATCHLIMIT)) // .Const(_SC("MatchLimit"), static_cast< SQInteger >(PCRE_ERROR_MATCHLIMIT))
.Const(_SC("Callout"), static_cast< SQInteger >(PCRE_ERROR_CALLOUT)) // .Const(_SC("Callout"), static_cast< SQInteger >(PCRE_ERROR_CALLOUT))
.Const(_SC("BadUTF8"), static_cast< SQInteger >(PCRE_ERROR_BADUTF8)) // .Const(_SC("BadUTF8"), static_cast< SQInteger >(PCRE_ERROR_BADUTF8))
.Const(_SC("BadUTF16"), static_cast< SQInteger >(PCRE_ERROR_BADUTF16)) // .Const(_SC("BadUTF16"), static_cast< SQInteger >(PCRE_ERROR_BADUTF16))
.Const(_SC("BadUTF32"), static_cast< SQInteger >(PCRE_ERROR_BADUTF32)) // .Const(_SC("BadUTF32"), static_cast< SQInteger >(PCRE_ERROR_BADUTF32))
.Const(_SC("BadUTF8Offset"), static_cast< SQInteger >(PCRE_ERROR_BADUTF8_OFFSET)) // .Const(_SC("BadUTF8Offset"), static_cast< SQInteger >(PCRE_ERROR_BADUTF8_OFFSET))
.Const(_SC("BadUTF16Offset"), static_cast< SQInteger >(PCRE_ERROR_BADUTF16_OFFSET)) // .Const(_SC("BadUTF16Offset"), static_cast< SQInteger >(PCRE_ERROR_BADUTF16_OFFSET))
.Const(_SC("Partial"), static_cast< SQInteger >(PCRE_ERROR_PARTIAL)) // .Const(_SC("Partial"), static_cast< SQInteger >(PCRE_ERROR_PARTIAL))
.Const(_SC("BadPartial"), static_cast< SQInteger >(PCRE_ERROR_BADPARTIAL)) // .Const(_SC("BadPartial"), static_cast< SQInteger >(PCRE_ERROR_BADPARTIAL))
.Const(_SC("Internal"), static_cast< SQInteger >(PCRE_ERROR_INTERNAL)) // .Const(_SC("Internal"), static_cast< SQInteger >(PCRE_ERROR_INTERNAL))
.Const(_SC("BadCount"), static_cast< SQInteger >(PCRE_ERROR_BADCOUNT)) // .Const(_SC("BadCount"), static_cast< SQInteger >(PCRE_ERROR_BADCOUNT))
.Const(_SC("DfaUitem"), static_cast< SQInteger >(PCRE_ERROR_DFA_UITEM)) // .Const(_SC("DfaUitem"), static_cast< SQInteger >(PCRE_ERROR_DFA_UITEM))
.Const(_SC("DfaUcond"), static_cast< SQInteger >(PCRE_ERROR_DFA_UCOND)) // .Const(_SC("DfaUcond"), static_cast< SQInteger >(PCRE_ERROR_DFA_UCOND))
.Const(_SC("DfaUmLimit"), static_cast< SQInteger >(PCRE_ERROR_DFA_UMLIMIT)) // .Const(_SC("DfaUmLimit"), static_cast< SQInteger >(PCRE_ERROR_DFA_UMLIMIT))
.Const(_SC("DfaWsSize"), static_cast< SQInteger >(PCRE_ERROR_DFA_WSSIZE)) // .Const(_SC("DfaWsSize"), static_cast< SQInteger >(PCRE_ERROR_DFA_WSSIZE))
.Const(_SC("DfaRecurse"), static_cast< SQInteger >(PCRE_ERROR_DFA_RECURSE)) // .Const(_SC("DfaRecurse"), static_cast< SQInteger >(PCRE_ERROR_DFA_RECURSE))
.Const(_SC("RecursionLimit"), static_cast< SQInteger >(PCRE_ERROR_RECURSIONLIMIT)) // .Const(_SC("RecursionLimit"), static_cast< SQInteger >(PCRE_ERROR_RECURSIONLIMIT))
.Const(_SC("NullWsLimit"), static_cast< SQInteger >(PCRE_ERROR_NULLWSLIMIT)) // .Const(_SC("NullWsLimit"), static_cast< SQInteger >(PCRE_ERROR_NULLWSLIMIT))
.Const(_SC("BadNewLine"), static_cast< SQInteger >(PCRE_ERROR_BADNEWLINE)) // .Const(_SC("BadNewLine"), static_cast< SQInteger >(PCRE_ERROR_BADNEWLINE))
.Const(_SC("BadOffset"), static_cast< SQInteger >(PCRE_ERROR_BADOFFSET)) // .Const(_SC("BadOffset"), static_cast< SQInteger >(PCRE_ERROR_BADOFFSET))
.Const(_SC("ShortUTF8"), static_cast< SQInteger >(PCRE_ERROR_SHORTUTF8)) // .Const(_SC("ShortUTF8"), static_cast< SQInteger >(PCRE_ERROR_SHORTUTF8))
.Const(_SC("ShortUTF16"), static_cast< SQInteger >(PCRE_ERROR_SHORTUTF16)) // .Const(_SC("ShortUTF16"), static_cast< SQInteger >(PCRE_ERROR_SHORTUTF16))
.Const(_SC("RecurseLoop"), static_cast< SQInteger >(PCRE_ERROR_RECURSELOOP)) // .Const(_SC("RecurseLoop"), static_cast< SQInteger >(PCRE_ERROR_RECURSELOOP))
.Const(_SC("JitStackLimit"), static_cast< SQInteger >(PCRE_ERROR_JIT_STACKLIMIT)) // .Const(_SC("JitStackLimit"), static_cast< SQInteger >(PCRE_ERROR_JIT_STACKLIMIT))
.Const(_SC("BadMode"), static_cast< SQInteger >(PCRE_ERROR_BADMODE)) // .Const(_SC("BadMode"), static_cast< SQInteger >(PCRE_ERROR_BADMODE))
.Const(_SC("BadEndianness"), static_cast< SQInteger >(PCRE_ERROR_BADENDIANNESS)) // .Const(_SC("BadEndianness"), static_cast< SQInteger >(PCRE_ERROR_BADENDIANNESS))
.Const(_SC("DfaBadRestart"), static_cast< SQInteger >(PCRE_ERROR_DFA_BADRESTART)) // .Const(_SC("DfaBadRestart"), static_cast< SQInteger >(PCRE_ERROR_DFA_BADRESTART))
.Const(_SC("JitBadOption"), static_cast< SQInteger >(PCRE_ERROR_JIT_BADOPTION)) // .Const(_SC("JitBadOption"), static_cast< SQInteger >(PCRE_ERROR_JIT_BADOPTION))
.Const(_SC("BadLength"), static_cast< SQInteger >(PCRE_ERROR_BADLENGTH)) // .Const(_SC("BadLength"), static_cast< SQInteger >(PCRE_ERROR_BADLENGTH))
.Const(_SC("Unset"), static_cast< SQInteger >(PCRE_ERROR_UNSET)) // .Const(_SC("Unset"), static_cast< SQInteger >(PCRE_ERROR_UNSET))
); // );
} }
} // Namespace:: SqMod } // Namespace:: SqMod

View File

@ -7,8 +7,8 @@
#ifdef POCO_UNBUNDLED #ifdef POCO_UNBUNDLED
#include <pcre.h> #include <pcre.h>
#else #else
#include "pcre_config.h" #include "pcre2_config.h"
#include "pcre.h" #include "pcre2.h"
#endif #endif
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -31,6 +31,7 @@ struct RxMatch
* *
*/ */
SQInteger mLength{0}; SQInteger mLength{0};
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Default constructor. * Default constructor.
*/ */
@ -386,500 +387,499 @@ struct RxMatches
} }
}; };
/* ------------------------------------------------------------------------------------------------ // /* ------------------------------------------------------------------------------------------------
* // *
*/ // */
struct RxInstance // struct RxInstance
{ // {
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Whether to analyze and optimize the pattern by default for evey new instance (true). // * Whether to analyze and optimize the pattern by default for evey new instance (true).
*/ // */
static bool STUDY; // static bool STUDY;
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Default options for every new instance (0). // * Default options for every new instance (0).
*/ // */
static int OPTIONS; // static int OPTIONS;
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Default study options for every new instance (0). // * Default study options for every new instance (0).
*/ // */
static int STUDY_OPTIONS; // static int STUDY_OPTIONS;
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Default offset vector size (must be multiple of 3). // * Default offset vector size (must be multiple of 3).
*/ // */
static constexpr int OVEC_SIZE = 63; // static constexpr int OVEC_SIZE = 63;
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Internal vector type used for offsets buffer. // * Internal vector type used for offsets buffer.
*/ // */
using OVEC_t = std::vector< int >; // using OVEC_t = std::vector< int >;
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Internal RegularExpression instance. // * Internal RegularExpression instance.
*/ // */
pcre * mPCRE{nullptr}; // pcre * mPCRE{nullptr};
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Internal RegularExpression instance. // * Internal RegularExpression instance.
*/ // */
pcre_extra * mExtra{nullptr}; // pcre_extra * mExtra{nullptr};
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Internal buffer used for offsets. // * Internal buffer used for offsets.
*/ // */
OVEC_t mOVEC{}; // OVEC_t mOVEC{};
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Default constructor. // * Default constructor.
*/ // */
RxInstance() noexcept = default; // RxInstance() noexcept = default;
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Copy constructor (disabled). // * Copy constructor (disabled).
*/ // */
RxInstance(const RxInstance &) = delete; // RxInstance(const RxInstance &) = delete;
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Move constructor. // * Move constructor.
*/ // */
RxInstance(RxInstance && o) noexcept // RxInstance(RxInstance && o) noexcept
: mPCRE(o.mPCRE), mExtra(o.mExtra), mOVEC(std::move(o.mOVEC)) // Replicate it // : mPCRE(o.mPCRE), mExtra(o.mExtra), mOVEC(std::move(o.mOVEC)) // Replicate it
{ // {
o.mPCRE = nullptr; // Take ownership // o.mPCRE = nullptr; // Take ownership
o.mExtra = nullptr; // Take ownership // o.mExtra = nullptr; // Take ownership
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Basic constructor. // * Basic constructor.
*/ // */
explicit RxInstance(StackStrF & pattern) // explicit RxInstance(StackStrF & pattern)
: RxInstance(OPTIONS, STUDY, pattern) // : RxInstance(OPTIONS, STUDY, pattern)
{ // {
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Basic constructor. With specific options. // * Basic constructor. With specific options.
*/ // */
explicit RxInstance(int options, StackStrF & pattern) // explicit RxInstance(int options, StackStrF & pattern)
: RxInstance(options, STUDY, pattern) // : RxInstance(options, STUDY, pattern)
{ // {
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Basic constructor. With specific options. // * Basic constructor. With specific options.
*/ // */
explicit RxInstance(int options, bool study, StackStrF & pattern) // explicit RxInstance(int options, bool study, StackStrF & pattern)
: mPCRE(Compile_(pattern.mPtr, options)), mExtra(nullptr) // : mPCRE(Compile_(pattern.mPtr, options)), mExtra(nullptr)
{ // {
if (study) // if (study)
{ // {
Study0(); // Study0();
} // }
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Internal constructor. // * Internal constructor.
*/ // */
RxInstance(const char * pattern, int options, bool study) // RxInstance(const char * pattern, int options, bool study)
: mPCRE(Compile_(pattern, options)), mExtra(nullptr) // : mPCRE(Compile_(pattern, options)), mExtra(nullptr)
{ // {
if (study) // if (study)
{ // {
Study0(); // Study0();
} // }
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Destructor. // * Destructor.
*/ // */
~RxInstance() // ~RxInstance()
{ // {
Destroy(); // Destroy();
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Copy assignment operator (disabled). // * Copy assignment operator (disabled).
*/ // */
RxInstance & operator = (const RxInstance &) = delete; // RxInstance & operator = (const RxInstance &) = delete;
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Move assignment operator. // * Move assignment operator.
*/ // */
RxInstance & operator = (RxInstance && o) noexcept // RxInstance & operator = (RxInstance && o) noexcept
{ // {
// Prevent self assignment // // Prevent self assignment
if (this != &o) // if (this != &o)
{ // {
// Release current instance, if any // // Release current instance, if any
Destroy(); // Destroy();
// Replicate it // // Replicate it
mPCRE = o.mPCRE; // mPCRE = o.mPCRE;
mExtra = o.mExtra; // mExtra = o.mExtra;
mOVEC = std::move(o.mOVEC); // mOVEC = std::move(o.mOVEC);
// Take ownership // // Take ownership
o.mPCRE = nullptr; // o.mPCRE = nullptr;
o.mExtra = nullptr; // o.mExtra = nullptr;
} // }
return *this; // return *this;
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Estimate the size necessary for the offsets vector buffer. // * Estimate the size necessary for the offsets vector buffer.
*/ // */
void EstimateOVEC(bool force = false) // void EstimateOVEC(bool force = false)
{ // {
if (mOVEC.empty() || force) // if (mOVEC.empty() || force)
{ // {
int size = 0; // int size = 0;
// Attempt to estimate the size of the offsets vector buffer // // Attempt to estimate the size of the offsets vector buffer
const int r = pcre_fullinfo(ValidPCRE(), mExtra, PCRE_INFO_CAPTURECOUNT, &size); // const int r = pcre_fullinfo(ValidPCRE(), mExtra, PCRE_INFO_CAPTURECOUNT, &size);
// Check for errors // // Check for errors
if (r != 0) // if (r != 0)
{ // {
STHROWF("Rx: Offsets vector buffer estimation failed ({})", r); // STHROWF("Rx: Offsets vector buffer estimation failed ({})", r);
} // }
// Attempt to scale the vector (must be multiple of 3) // // Attempt to scale the vector (must be multiple of 3)
mOVEC.resize((size + 1) * 3); // mOVEC.resize((size + 1) * 3);
} // }
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Return a valid `pcre` instance pointer or throw an exception. // * Return a valid `pcre` instance pointer or throw an exception.
*/ // */
SQMOD_NODISCARD pcre * ValidPCRE() const // SQMOD_NODISCARD pcre * ValidPCRE() const
{ // {
// Do we manage a valid instance? // // Do we manage a valid instance?
if (mPCRE == nullptr) // if (mPCRE == nullptr)
{ // {
STHROWF("Uninitialized Regular Expression instance."); // STHROWF("Uninitialized Regular Expression instance.");
} // }
// Return it // // Return it
return mPCRE; // return mPCRE;
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Return a valid `pcre_extra` instance pointer or throw an exception. // * Return a valid `pcre_extra` instance pointer or throw an exception.
*/ // */
SQMOD_NODISCARD pcre_extra * ValidExtra() const // SQMOD_NODISCARD pcre_extra * ValidExtra() const
{ // {
// Do we manage a valid instance? // // Do we manage a valid instance?
if (mExtra == nullptr) // if (mExtra == nullptr)
{ // {
STHROWF("Regular Expression was not studied and optimized."); // STHROWF("Regular Expression was not studied and optimized.");
} // }
// Return it // // Return it
return mExtra; // return mExtra;
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Compile the specified pattern. // * Compile the specified pattern.
*/ // */
SQMOD_NODISCARD static pcre * Compile_(const char * pattern, int options = OPTIONS) // SQMOD_NODISCARD static pcre * Compile_(const char * pattern, int options = OPTIONS)
{ // {
const char * error_msg = nullptr; // const char * error_msg = nullptr;
int error_code, error_offset = 0; // int error_code, error_offset = 0;
// Attempt to compile the specified pattern // // Attempt to compile the specified pattern
pcre * ptr = pcre_compile2(pattern, options, &error_code, &error_msg, &error_offset, nullptr); // pcre * ptr = pcre_compile2(pattern, options, &error_code, &error_msg, &error_offset, nullptr);
// Did the compilation failed? // // Did the compilation failed?
if (ptr == nullptr) // if (ptr == nullptr)
{ // {
STHROWF("Rx: {s} (code {}) (at offset {})", error_msg, error_code, error_offset); // STHROWF("Rx: {s} (code {}) (at offset {})", error_msg, error_code, error_offset);
} // }
// Return the `pcre` instance // // Return the `pcre` instance
return ptr; // return ptr;
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Attempt to compile the specified pattern. Error information is returned instead of thrown. // * Attempt to compile the specified pattern. Error information is returned instead of thrown.
*/ // */
SQMOD_NODISCARD static std::pair< pcre *, Table > TryCompile_(const char * pattern, int options = OPTIONS) // SQMOD_NODISCARD static std::pair< pcre *, Table > TryCompile_(const char * pattern, int options = OPTIONS)
{ // {
const char * error_msg = nullptr; // const char * error_msg = nullptr;
int error_code, error_offset = 0; // int error_code, error_offset = 0;
// Attempt to compile the specified pattern // // Attempt to compile the specified pattern
pcre * ptr = pcre_compile2(pattern, options, &error_code, &error_msg, &error_offset, nullptr); // pcre * ptr = pcre_compile2(pattern, options, &error_code, &error_msg, &error_offset, nullptr);
// Did the compilation failed? // // Did the compilation failed?
if (ptr == nullptr) // if (ptr == nullptr)
{ // {
Table t; // Table t;
t.SetValue("message", error_msg); // t.SetValue("message", error_msg);
t.SetValue("code", error_code); // t.SetValue("code", error_code);
t.SetValue("offset", error_offset); // t.SetValue("offset", error_offset);
// Return the table with error information // // Return the table with error information
return std::make_pair(ptr, std::move(t)); // return std::make_pair(ptr, std::move(t));
} // }
// Return the `pcre` instance with no error information // // Return the `pcre` instance with no error information
return std::make_pair(ptr, Table{}); // return std::make_pair(ptr, Table{});
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Compile the specified pattern. // * Compile the specified pattern.
*/ // */
RxInstance & Compile1(StackStrF & pattern) // RxInstance & Compile1(StackStrF & pattern)
{ // {
return Compile2(OPTIONS, pattern); // return Compile2(OPTIONS, pattern);
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Compile the specified pattern. With specific options. // * Compile the specified pattern. With specific options.
*/ // */
RxInstance & Compile2(int options, StackStrF & pattern) // RxInstance & Compile2(int options, StackStrF & pattern)
{ // {
// Release current instance, if any // // Release current instance, if any
Destroy(); // Destroy();
// Attempt to compile // // Attempt to compile
mPCRE = Compile_(pattern.mPtr, options); // mPCRE = Compile_(pattern.mPtr, options);
// Allocate offsets vector buffer // // Allocate offsets vector buffer
EstimateOVEC(); // EstimateOVEC();
// Allow chaining // // Allow chaining
return *this; // return *this;
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Compile the specified pattern. // * Compile the specified pattern.
*/ // */
Table TryCompile1(StackStrF & pattern) // Table TryCompile1(StackStrF & pattern)
{ // {
return TryCompile2(OPTIONS, pattern); // return TryCompile2(OPTIONS, pattern);
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Compile the specified pattern. With specific options. // * Compile the specified pattern. With specific options.
*/ // */
Table TryCompile2(int options, StackStrF & pattern) // Table TryCompile2(int options, StackStrF & pattern)
{ // {
// Release current instance, if any // // Release current instance, if any
Destroy(); // Destroy();
// Attempt to compile // // Attempt to compile
auto p = TryCompile_(pattern.mPtr, options); // auto p = TryCompile_(pattern.mPtr, options);
// Were there any compilation errors? // // Were there any compilation errors?
if (p.first != nullptr) // if (p.first != nullptr)
{ // {
mPCRE = p.first; // mPCRE = p.first;
} // }
// Return compilation info // // Return compilation info
return p.second; // return p.second;
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Analyze the managed pattern and optimized it. // * Analyze the managed pattern and optimized it.
*/ // */
RxInstance & Study0() // RxInstance & Study0()
{ // {
return Study1(STUDY_OPTIONS); // return Study1(STUDY_OPTIONS);
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Analyze the managed pattern and optimized it. With specific options. // * Analyze the managed pattern and optimized it. With specific options.
*/ // */
RxInstance & Study1(int options) // RxInstance & Study1(int options)
{ // {
if (mExtra != nullptr) // if (mExtra != nullptr)
{ // {
STHROWF("Regular Expression was already analyzed and optimized"); // STHROWF("Regular Expression was already analyzed and optimized");
} // }
const char * error = nullptr; // const char * error = nullptr;
// Study and optimize the expression // // Study and optimize the expression
mExtra = pcre_study(ValidPCRE(), options, &error); // mExtra = pcre_study(ValidPCRE(), options, &error);
// If there was an error studying the expression then throw it // // If there was an error studying the expression then throw it
if (mExtra == nullptr && error != nullptr) // if (mExtra == nullptr && error != nullptr)
{ // {
STHROWF("Rx: {s}", error); // STHROWF("Rx: {s}", error);
} // }
// Allow chaining // // Allow chaining
return *this; // return *this;
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Release managed resources and revert to uninitialized instance. // * Release managed resources and revert to uninitialized instance.
*/ // */
SQMOD_NODISCARD bool IsValid() const // SQMOD_NODISCARD bool IsValid() const
{ // {
return (mPCRE != nullptr); // return (mPCRE != nullptr);
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Release managed resources and revert to uninitialized instance. // * Release managed resources and revert to uninitialized instance.
*/ // */
SQMOD_NODISCARD bool IsStudied() const // SQMOD_NODISCARD bool IsStudied() const
{ // {
return (mExtra != nullptr); // return (mExtra != nullptr);
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Release managed resources and revert to uninitialized instance. // * Release managed resources and revert to uninitialized instance.
*/ // */
void Destroy() // void Destroy()
{ // {
// Do we manage any instance? // // Do we manage any instance?
if (mPCRE != nullptr) // if (mPCRE != nullptr)
{ // {
pcre_free(mPCRE); // pcre_free(mPCRE);
mPCRE = nullptr; // mPCRE = nullptr;
} // }
// Is the expression optimized? // // Is the expression optimized?
if (mExtra != nullptr) // if (mExtra != nullptr)
{ // {
pcre_free(mExtra); // pcre_free(mExtra);
mExtra = nullptr; // mExtra = nullptr;
} // }
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Matches the given subject string against the pattern. // * Matches the given subject string against the pattern.
* Returns the position of the first captured sub-string in m. // * Returns the position of the first captured sub-string in m.
* If no part of the subject matches the pattern, m.mOffset is -1 and m.mLength is 0. // * If no part of the subject matches the pattern, m.mOffset is -1 and m.mLength is 0.
* Returns the number of matches. Throws a exception in case of an error. // * Returns the number of matches. Throws a exception in case of an error.
*/ // */
SQMOD_NODISCARD int MatchFirstFrom(SQInteger o, RxMatch & m, StackStrF & s) // SQMOD_NODISCARD int MatchFirstFrom(SQInteger o, RxMatch & m, StackStrF & s)
{ // {
return MatchFirstFrom_(OPTIONS, o, m, s); // return MatchFirstFrom_(OPTIONS, o, m, s);
} // }
SQMOD_NODISCARD int MatchFirstFrom_(int f, SQInteger o, RxMatch & m, StackStrF & s) // SQMOD_NODISCARD int MatchFirstFrom_(int f, SQInteger o, RxMatch & m, StackStrF & s)
{ // {
if (o > s.mLen) // if (o > s.mLen)
{ // {
STHROWF("Rx: Offset is out of range"); // STHROWF("Rx: Offset is out of range");
} // }
EstimateOVEC(); // EstimateOVEC();
// Attempt to execute the expression on the specified subject // // Attempt to execute the expression on the specified subject
const int rc = pcre_exec(ValidPCRE(), mExtra, s.mPtr, static_cast< int >(s.mLen), static_cast< int >(o), f & 0xFFFF, mOVEC.data(), static_cast< int >(mOVEC.size())); // const int rc = pcre_exec(ValidPCRE(), mExtra, s.mPtr, static_cast< int >(s.mLen), static_cast< int >(o), f & 0xFFFF, mOVEC.data(), static_cast< int >(mOVEC.size()));
// Was there a match? // // Was there a match?
if (rc == PCRE_ERROR_NOMATCH) // if (rc == PCRE_ERROR_NOMATCH)
{ // {
m.mOffset = -1; // m.mOffset = -1;
m.mLength = 0; // m.mLength = 0;
// No match found // // No match found
return 0; // return 0;
} // }
// Bad options/flags? // // Bad options/flags?
else if (rc == PCRE_ERROR_BADOPTION) // else if (rc == PCRE_ERROR_BADOPTION)
{ // {
STHROWF("Rx: Bad option"); // STHROWF("Rx: Bad option");
} // }
// Overflow? // // Overflow?
else if (rc == 0) // else if (rc == 0)
{ // {
STHROWF("Rx: too many captured sub-strings"); // STHROWF("Rx: too many captured sub-strings");
} // }
// Some other error? // // Some other error?
else if (rc < 0) // else if (rc < 0)
{ // {
STHROWF("Rx: error {}", rc); // STHROWF("Rx: error {}", rc);
} // }
// Store match // // Store match
m.mOffset = mOVEC[0]; // m.mOffset = mOVEC[0];
m.mLength = mOVEC[1] - mOVEC[0]; // m.mLength = mOVEC[1] - mOVEC[0];
// Yield result back to script // // Yield result back to script
return rc; // return rc;
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Matches the given subject string against the pattern. // * Matches the given subject string against the pattern.
* Returns the position of the first captured sub-string in m. // * Returns the position of the first captured sub-string in m.
* If no part of the subject matches the pattern, m.mOffset is -1 and m.mLength is 0. // * If no part of the subject matches the pattern, m.mOffset is -1 and m.mLength is 0.
* Returns the number of matches. Throws a exception in case of an error. // * Returns the number of matches. Throws a exception in case of an error.
*/ // */
SQMOD_NODISCARD int MatchFirst(RxMatch & m, StackStrF & s) // SQMOD_NODISCARD int MatchFirst(RxMatch & m, StackStrF & s)
{ // {
return MatchFirstFrom_(OPTIONS, 0, m, s); // return MatchFirstFrom_(OPTIONS, 0, m, s);
} // }
SQMOD_NODISCARD int MatchFirst_(int f, RxMatch & m, StackStrF & s) // SQMOD_NODISCARD int MatchFirst_(int f, RxMatch & m, StackStrF & s)
{ // {
return MatchFirstFrom_(f, 0, m, s); // return MatchFirstFrom_(f, 0, m, s);
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Matches the given subject string against the pattern. // * Matches the given subject string against the pattern.
* The first entry in m contains the position of the captured sub-string. // * The first entry in m contains the position of the captured sub-string.
* The following entries identify matching sub-patterns. See the PCRE documentation for a more detailed explanation. // * The following entries identify matching sub-patterns. See the PCRE documentation for a more detailed explanation.
* If no part of the subject matches the pattern, m is empty. // * If no part of the subject matches the pattern, m is empty.
* Returns the number of matches. Throws an exception in case of an error. // * Returns the number of matches. Throws an exception in case of an error.
*/ // */
SQMOD_NODISCARD int MatchFrom(SQInteger o, RxMatches & m, StackStrF & s) // SQMOD_NODISCARD int MatchFrom(SQInteger o, RxMatches & m, StackStrF & s)
{ // {
return MatchFrom_(OPTIONS, o, m, s); // return MatchFrom_(OPTIONS, o, m, s);
} // }
SQMOD_NODISCARD int MatchFrom_(int f, SQInteger o, RxMatches & m, StackStrF & s) // SQMOD_NODISCARD int MatchFrom_(int f, SQInteger o, RxMatches & m, StackStrF & s)
{ // {
if (o > s.mLen) // if (o > s.mLen)
{ // {
STHROWF("Rx: Offset is out of range"); // STHROWF("Rx: Offset is out of range");
} // }
EstimateOVEC(); // EstimateOVEC();
// Clear previous matches, if any // // Clear previous matches, if any
m.mList.clear(); // m.mList.clear();
// Attempt to execute the expression on the specified subject // // Attempt to execute the expression on the specified subject
const int rc = pcre_exec(ValidPCRE(), mExtra, s.mPtr, static_cast< int >(s.mLen), static_cast< int >(o), f & 0xFFFF, mOVEC.data(), static_cast< int >(mOVEC.size())); // const int rc = pcre_exec(ValidPCRE(), mExtra, s.mPtr, static_cast< int >(s.mLen), static_cast< int >(o), f & 0xFFFF, mOVEC.data(), static_cast< int >(mOVEC.size()));
// Was there a match? // // Was there a match?
if (rc == PCRE_ERROR_NOMATCH) // if (rc == PCRE_ERROR_NOMATCH)
{ // {
return 0; // No match found // return 0; // No match found
} // }
// Bad options/flags? // // Bad options/flags?
else if (rc == PCRE_ERROR_BADOPTION) // else if (rc == PCRE_ERROR_BADOPTION)
{ // {
STHROWF("Rx: Bad option"); // STHROWF("Rx: Bad option");
} // }
// Overflow? // // Overflow?
else if (rc == 0) // else if (rc == 0)
{ // {
STHROWF("Rx: too many captured sub-strings"); // STHROWF("Rx: too many captured sub-strings");
} // }
// Some other error? // // Some other error?
else if (rc < 0) // else if (rc < 0)
{ // {
STHROWF("Rx: error {}", rc); // STHROWF("Rx: error {}", rc);
} // }
// Reserve space in advance // // Reserve space in advance
m.mList.reserve(static_cast< size_t >(rc)); // m.mList.reserve(static_cast< size_t >(rc));
// Transfer matches to match-list // // Transfer matches to match-list
for (int i = 0; i < rc; ++i) // for (int i = 0; i < rc; ++i)
{ // {
m.mList.emplace_back(mOVEC[i*2], mOVEC[i*2+1] - mOVEC[i*2]); // m.mList.emplace_back(mOVEC[i*2], mOVEC[i*2+1] - mOVEC[i*2]);
} // }
// Yield result back to script // // Yield result back to script
return rc; // return rc;
} // }
/* -------------------------------------------------------------------------------------------- // /* --------------------------------------------------------------------------------------------
* Matches the given subject string against the pattern. // * Matches the given subject string against the pattern.
* The first entry in m contains the position of the captured sub-string. // * The first entry in m contains the position of the captured sub-string.
* The following entries identify matching sub-patterns. See the PCRE documentation for a more detailed explanation. // * The following entries identify matching sub-patterns. See the PCRE documentation for a more detailed explanation.
* If no part of the subject matches the pattern, m is empty. // * If no part of the subject matches the pattern, m is empty.
* Returns the number of matches. Throws an exception in case of an error. // * Returns the number of matches. Throws an exception in case of an error.
*/ // */
SQMOD_NODISCARD int Match(RxMatches & m, StackStrF & s) // SQMOD_NODISCARD int Match(RxMatches & m, StackStrF & s)
{ // {
return MatchFrom_(OPTIONS, 0, m, s); // return MatchFrom_(OPTIONS, 0, m, s);
} // }
SQMOD_NODISCARD int Match_(int f, RxMatches & m, StackStrF & s) // SQMOD_NODISCARD int Match_(int f, RxMatches & m, StackStrF & s)
{ // {
return MatchFrom_(f, 0, m, s); // return MatchFrom_(f, 0, m, s);
} // }
/* --------------------------------------------------------------------------------------------
* Returns true if and only if the subject matches the regular expression.
* Internally, this method sets the RE_ANCHORED and RE_NOTEMPTY options for matching,
* which means that the empty string will never match and the pattern is treated as if it starts with a ^.
*/
SQMOD_NODISCARD bool Matches(StackStrF & s)
{
return Matches_(PCRE_ANCHORED | PCRE_NOTEMPTY, s);
}
SQMOD_NODISCARD bool Matches_(SQInteger o, StackStrF & s)
{
return MatchesEx(PCRE_ANCHORED | PCRE_NOTEMPTY, 0, s);
}
SQMOD_NODISCARD bool MatchesEx(int f, SQInteger o, StackStrF & s)
{
RxMatch m;
const int rc = MatchFirstFrom_(f, o, m, s);
return (rc > 0) && (m.mOffset == o) && (m.mLength == (s.mLen - o));
}
};
// /* --------------------------------------------------------------------------------------------
// * Returns true if and only if the subject matches the regular expression.
// * Internally, this method sets the RE_ANCHORED and RE_NOTEMPTY options for matching,
// * which means that the empty string will never match and the pattern is treated as if it starts with a ^.
// */
// SQMOD_NODISCARD bool Matches(StackStrF & s)
// {
// return Matches_(PCRE_ANCHORED | PCRE_NOTEMPTY, s);
// }
// SQMOD_NODISCARD bool Matches_(SQInteger o, StackStrF & s)
// {
// return MatchesEx(PCRE_ANCHORED | PCRE_NOTEMPTY, 0, s);
// }
// SQMOD_NODISCARD bool MatchesEx(int f, SQInteger o, StackStrF & s)
// {
// RxMatch m;
// const int rc = MatchFirstFrom_(f, o, m, s);
// return (rc > 0) && (m.mOffset == o) && (m.mLength == (s.mLen - o));
// }
// };
} // Namespace:: SqMod } // Namespace:: SqMod