diff --git a/packages/wasm-utils/src/wasm.regexp.api.pas b/packages/wasm-utils/src/wasm.regexp.api.pas index ee6f19a1ac..adfe4b9a40 100644 --- a/packages/wasm-utils/src/wasm.regexp.api.pas +++ b/packages/wasm-utils/src/wasm.regexp.api.pas @@ -28,6 +28,7 @@ function __wasm_regexp_test(aExprID : TWasmRegExpID; aString : PByte; aStringLen function __wasm_regexp_get_flags(aExprID : TWasmRegExpID; aFlags : PLongint) : TWasmRegexpResult; external regexpExportName name regexpFN_GetFlags; function __wasm_regexp_get_expression(aExprID : TWasmRegExpID; aExp : PByte; aExpLen : PLongint) : TWasmRegexpResult; external regexpExportName name regexpFN_GetExpression; function __wasm_regexp_get_last_index(aExprID : TWasmRegExpID; aLastIndex : PLongint) : TWasmRegexpResult; external regexpExportName name regexpFN_GetLastIndex; +function __wasm_regexp_set_last_index(aExprID : TWasmRegExpID; aLastIndex : Longint) : TWasmRegexpResult; external regexpExportName name regexpFN_SetLastIndex; function __wasm_regexp_get_result_match(aExprID : TWasmRegExpID; aIndex : Longint; Res : PByte; ResLen : PLongint) : TWasmRegexpResult; external regexpExportName name regexpFN_GetResultMatch; function __wasm_regexp_get_group_count(aExprID : TWasmRegExpID; aCount: PLongint) : TWasmRegexpResult; external regexpExportName name regexpFN_GetGroupCount; function __wasm_regexp_get_group_name(aExprID : TWasmRegExpID; aIndex : Longint; aName : PByte; aNameLen : PLongint) : TWasmRegexpResult; external regexpExportName name regexpFN_GetGroupName; diff --git a/packages/wasm-utils/src/wasm.regexp.objects.pas b/packages/wasm-utils/src/wasm.regexp.objects.pas index 21de517bce..a46d34ba8c 100644 --- a/packages/wasm-utils/src/wasm.regexp.objects.pas +++ b/packages/wasm-utils/src/wasm.regexp.objects.pas @@ -17,6 +17,7 @@ unit wasm.regexp.objects; {$mode ObjFPC}{$H+} {$modeswitch typehelpers} +{$modeswitch advancedrecords} interface @@ -57,9 +58,12 @@ Type Property AsFlags : Longint Read ToFlags Write SetAsFlags; end; + { TRegExpMatch } + TRegExpMatch = record Value : UTF8String; StartIndex, StopIndex : Integer; + function MatchPos(aStartIndex, aStopIndex : Integer) : Boolean; end; TRegExpMatchArray = array of TRegExpMatch; @@ -86,6 +90,7 @@ Type function GetGroups(aCount: Integer): TRegExpGroupArray; function GetLastIndex: Longint; function GetMatches(aCount: Integer): TRegExpMatchArray; + procedure SetLastIndex(AValue: Longint); protected function CheckRegExpResult(Res : TWasmRegexpResult; const aOperation : String; aRaise : Boolean = true) : Boolean; Public @@ -95,7 +100,8 @@ Type destructor Destroy; override; Function Exec(const aString : String) : TRegExpResult; Function Test(const aString : String) : Boolean; - Property LastIndex : Longint Read GetLastIndex; + // 0 - based ! + Property LastIndex : Longint Read GetLastIndex Write SetLastIndex; Property RegexpID : TWasmRegExpID Read FRegexpID; Property FlagsAsInteger : Integer Read FFlags; Property Flags : TRegexpFlags Read GetFlags; @@ -166,6 +172,13 @@ begin Result.AsFlags:=aFlags; end; +{ TRegExpMatch } + +function TRegExpMatch.MatchPos(aStartIndex, aStopIndex: Integer): Boolean; +begin + Result:=(aStartIndex=StartIndex) and (aStopIndex=StopIndex); +end; + { TWasmRegExp } @@ -244,6 +257,11 @@ begin end; end; +procedure TWasmRegExp.SetLastIndex(AValue: Longint); +begin + CheckRegExpResult(__wasm_regexp_set_last_index(FRegexpID,AValue),'set_last_index'); +end; + function TWasmRegExp.GetGroups(aCount: Integer): TRegExpGroupArray; var diff --git a/packages/wasm-utils/src/wasm.regexp.shared.pas b/packages/wasm-utils/src/wasm.regexp.shared.pas index ae7b7a2a47..dabc397d17 100644 --- a/packages/wasm-utils/src/wasm.regexp.shared.pas +++ b/packages/wasm-utils/src/wasm.regexp.shared.pas @@ -67,6 +67,7 @@ Const regexpFN_GetFlags = 'get_flags'; regexpFN_GetExpression = 'get_expression'; regexpFN_GetLastIndex = 'get_last_index'; + regexpFN_SetLastIndex = 'set_last_index'; regexpFN_GetResultMatch = 'get_result_match'; regexpFN_GetGroupCount = 'get_group_count'; regexpFN_GetGroupName = 'get_group_name';