From 865002c06c802952c64449001cd785b1da8aa5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Sat, 28 Oct 2023 02:00:48 +0200 Subject: [PATCH] RegExp[].Length is a new property that returns the length of a submatch. [GB.PCRE] * NEW: RegExp[].Length is a new property that returns the length of a submatch. --- gb.pcre/src/regexp.c | 7 +++++++ gb.pcre/src/regexp2.c | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/gb.pcre/src/regexp.c b/gb.pcre/src/regexp.c index c9bfa4343..4e4e4db0c 100644 --- a/gb.pcre/src/regexp.c +++ b/gb.pcre/src/regexp.c @@ -349,6 +349,12 @@ BEGIN_PROPERTY(RegExp_Submatch_Offset) END_PROPERTY +BEGIN_PROPERTY(RegExp_Submatch_Length) + + GB.ReturnInteger(THIS->ovector[2 * THIS->_submatch + 1] - THIS->ovector[2 * THIS->_submatch]); + +END_PROPERTY + #include "regexp_common.h" //--------------------------------------------------------------------------- @@ -428,6 +434,7 @@ GB_DESC CRegexpSubmatchDesc[] = GB_PROPERTY_READ("Offset", "i", RegExp_Submatch_Offset), GB_PROPERTY_READ("Text", "s", RegExp_Submatch_Text), + GB_PROPERTY_READ("Length", "i", RegExp_Submatch_Length), GB_END_DECLARE }; diff --git a/gb.pcre/src/regexp2.c b/gb.pcre/src/regexp2.c index 35223bc43..b99ace349 100644 --- a/gb.pcre/src/regexp2.c +++ b/gb.pcre/src/regexp2.c @@ -320,6 +320,13 @@ BEGIN_PROPERTY(RegExp_Submatch_Offset) END_PROPERTY +BEGIN_PROPERTY(RegExp_Submatch_Length) + + GB.ReturnInteger(THIS->ovector ? THIS->ovector[2 * THIS->_submatch + 1] - THIS->ovector[2 * THIS->_submatch] : 0); + +END_PROPERTY + + #include "regexp_common.h" //--------------------------------------------------------------------------- @@ -396,6 +403,7 @@ GB_DESC CRegexpSubmatchDesc[] = GB_PROPERTY_READ("Offset", "i", RegExp_Submatch_Offset), GB_PROPERTY_READ("Text", "s", RegExp_Submatch_Text), + GB_PROPERTY_READ("Length", "i", RegExp_Submatch_Length), GB_END_DECLARE };