jpbro / vbpcre2 Goto Github PK
View Code? Open in Web Editor NEWPCRE2 Wrapper for VB6
License: Other
PCRE2 Wrapper for VB6
License: Other
I'm relatively inexperienced with Open Source licenses - I wanted the VBPCRE2 license to be as permissive as possible, and GitHub recommended the MIT license when I created the repository. Any opinions on whether or not this was the right choice? Should I/can I change it if there's a consensus on a better choice?
Thanks in advance for any feedback!
"Invalid procedure call or argument".
ma_Ovector returns -1, when:
l_SubjectText = "Wyzo"
l_Regex = "(Manager)|^((copy of )?(" & "MX5|Wyzo" & "))$"
VBPCRE2 needs documentation.
It seems when you uploaded a project, your Git somehow replaced CrLf by Lf in all source files.
My VB6 IDE refuse loading this project.
I found "infinite" loop in SubMatches method, when you are executing TestRegex2() with l_Regex = ".*$"
Just a last one (I think) VBS-like feature request to Pcre: to add 'FirstIndex' property to 'CPcreMatch'. It have to point to position in original string of match that was found.
Something like pa_OvectorArray() for SubMatches, but for Match.
I didn't see is it can be done easily, so it is still a subject of discussion.
Anyway, I would like to know how to add this feature myself.
I imagine this is probably a bitness issue? I downloaded the vbpcre2.dll and put it in C:\windows\syswow64 (also tried system32) and registered the dll.
DLL shows up as a reference in VBA and intellisense picks up on it just fine, but trying to run any code gives me a class not registered message even just trying to set .options.compile.casesensitive = false
Example code:
Public Function Rx(p As String, s As String) As Boolean
Dim r As New cPcre2
Dim x As cPcre2Matches
With r.Options.Compile
.CaseSensitive = False
End With
Set x = r.Match(s, p)
Debug.Print x.text
End Function
This is mostly a note to self - I'd like to create a front-end UI with a bunch of tests that can be run and possibly compared to VBScript Regex results - ideally we'd have a single method that can take either a VBScript Regex object or a CPcre object and run the exactly same regex matches/substitutions and compare the results, alerting the user of any differences.
Just discovered a bug with how the wrapper is handling sub-matches (none are being added to the Matches collection). This will need some work ASAP.
Before finalizing the object model and compiling as a DLL with Binary Compatibility set a decision needs to be made regarding the class names.
Right now things follow a CPcre* naming convention, but would it be preferable to match the object names of the VBScript library (e.g. CPcre = Regexp, CPcreMatches = Matches, CPcreMatch = Match)? This will make it easier to use the library as a drop-in replacement for VBScript.
I'd appreciate any thoughts on this from the community before making a decision one way or another.
Subject line says it all. :) Running the current bin/VBPCRE2Test.exe instance throws an error.
Manually rebuilding VBPCRE2Test.exe using the latest source, then manually copying the .exe into the /bin folder and trying again works as expected.
Thank you for your continued work on this!
Note to self - add descriptive messages for the full PCRE2 error code list.
I like your prefixes naming style.
I noticed:
m_
mo_
lo_
so_
ma_
...
2-nd letter is a type of variable (o - object, a - array).
1-st is a vision.
I curious, how do you call these abbreviations: m - module? And other s, m, l ?
How about global (public in module) ?
I just liked such style, and want to know more, before (and if) I plan to use it in my projects too.
Thank you for explanations.
In the latest build, I've tried to finish work with pcre2_set_callout
, but I've encountered a show stopper.
I'm passing ObjPtr(Me)
for the third parameter of pcre2_set_callout
, but the value I'm receiving in my callback function is completely different, meaning I can't convert it back to an object instance. The strange thing is that the same approach works fine in pcre2_callout_enumerate
. Not sure what is going on.
The PCRE2 API declares the two methods as follows:
int pcre2_set_callout(pcre2_match_context *mcontext, int (*callout_function)(pcre2_callout_block *), void *callout_data);
int pcre2_callout_enumerate(const pcre2_code *code, int (*callback)(pcre2_callout_enumerate_block *, void *), void *callout_data);
As you can see they both take a third parameter void *callout_data
.
I've declared the 2 functions in VB as follows:
Private Declare Function pcre2_callout_enumerate Lib "pcre2-16.dll" Alias "_pcre2_callout_enumerate_16@12" (ByVal p_CompiledRegexHandle As Long, ByVal p_CalloutAddress As Long, ByRef p_CalloutDataPointer As Long) As Long
Private Declare Function pcre2_set_callout Lib "pcre2-16.dll" Alias "_pcre2_set_callout_16@12" (ByVal p_MatchContextHandle As Long, ByVal p_CalloutAddress As Long, ByRef p_CalloutDataPointer As Long) As Long
So as you can see, both declares take a final ByRef Long to which I pass ObjPtr(Me).
In my enumerate callout callback function, the ObJPtr value arrives correctly, and I can create an object reference from it without issue.
In my match callout callback, the value comes back completely different, so an attempt to create an object reference crashes the program.
Anyone have any idea what I am doing wrong?
I know that [ ] used when you want to use reserved keyword in enum.
_PCRE_RC_ERROR_FIRST is not reserved ?
What is a benefit here:
Private Enum PCRE_ReturnCode
...
[_PCRE_RC_ERROR_FIRST] = -1
[_PCRE_RC_ERROR_LAST] = -62
End Enum
P.S. Do you not mind that I am asking theoreticall question here?
This is non-practical situation.
However,
if p_TextToSearch = "", other arguments is any.
'Replace' method enters the infinite loop in:
Loop While l_ReplaceResult = PCRE_RC_ERROR_NOMEMORY
Currently some PCRE2 constants are scattered around the various classes. I think they should all be moved into enums in modPcre2 to keep them all in one place and allow them to be re-used in various classes while remaining hidden from the host.
Please update a method description here:
Public Function Execute(ByVal p_TextToSearch As String, Optional ByVal p_RegexToMatch As String) As CPcreMatches
' Return TRUE if any match found
Found in CPcreOptionsReplace.cls:
Private m_MatchedEventEnabled As Boolean
Private m_SubstitutionCacheSize As Long
Not sure, is it not implemented or superfluous.
When Multiline = TRUE and Global = True (for VbScript/NA for my wrapper) consider the following subject:
"File1.zip.exe" & vbCrLf & "File2.com" & vbCrLf & "File 3"
And the following regex:
.*$
VBScript returns 6 matches, but my wrapper returns only 2. Who is right?
@wqweto brought up a point that I think deserves some public discussion
The main question is: why are pcre-16.dll and VBPCRE2.dll separate, and would there be an advantage to statically linking them?
Personally, I don't think there's a huge advantage to linking them since we already have to ship one external DLL (so what's the problem with shipping two). That said, I'm not against linking them if the community disagrees with me and would prefer to have a single DLL.
The issues as I see it are:
How do we link the two DLLs? I've never done this, so I would appreciate some input.
If we can link them, can we automate this so I don't have to manually perform a bunch of steps to link them every time I rebuild one of the DLLs?
PCRE2 is BSD licensed, while VBPCRE2 is MIT licensed - is there any conflict linking libraries with those 2 different licenses, or are there any special steps I'd have to take re: releasing source/configuration files that perform the link?
I appreciate any input!
As per discussion in this issue: [link][https://github.com//issues/6]
The VBPCRE2 Object and Method names should be updated to more closely match PCRE2.
For example, all class names currently start with CPcre*, but these should be changed to CPcre2*
Public methods like Execute and Replace should more closely match the PCRE2 method names (so Match and Substitute would be more appropriate).
I haven't done a lot of testing with "callout" features, but the newest DLL appears to work with callouts if the following VB6 changes are made:
pcreCalloutProc()
, change the CopyMemory
line to this:CopyMemory ByVal VarPtr(lt_CalloutBlock), ByVal p_CalloutBlockPointer, LenB(lt_CalloutBlock)
The following Debug.Print lt_CalloutBlock.Version
line should now produce 0, as expected.
CPCre.cls
:Private Declare Function pcre2_callout_enumerate Lib "pcre2-16.dll" Alias "_pcre2_callout_enumerate_16@12" (ByVal p_CompiledPattern As Long, ByVal pCalloutAddress As Long, ByRef p_CalloutDataPointer As Long) As Long
...and inside the Execute()
function, replace this line:
Debug.Print "Callout: " & pcre2_set_callout(l_MatchData, AddressOf pcreCalloutProc, ObjPtr(Me))
...with this:
pcre2_callout_enumerate l_CompiledRegex, AddressOf pcreCalloutProc, ObjPtr(Me)
The callout function is now invoked successfully!
pcre2_set_callout()
should also hypothetically work, however it needs a match context to be passed, so we'd need to add a declaration for pcre2_match_context_create()
and of course invoke it prior to using pcre2_set_callout
.
Thank you again for your work on this! I am far from an expert in regex, so I'll test where I can, but I may leave the complicated stuff to the experts... ;)
A quick check shows that pcre2 has updated since the last build provided in this repo:
Would new VB6-compatible binaries be useful/desirable?
The cPcre2* classes should all be moved to an ActiveX DLL as it appears that public object/method names have stabilized.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.