Code Monkey home page Code Monkey logo

vbpcre2's Introduction

VbPcre2

PCRE2 Regular Expression (Regex) Library Wrapper for Visual Basic 6 (VB6)

Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.

https://groups.google.com/forum/#!msg/alt.religion.emacs/DR057Srw5-c/Co-2L2BKn7UJ

Some people when confronted with a problem, a regular expression library, and a need for access to said library in VB6 think "I know I'll write a wrapper for PCRE2 in VB6". Now they have three problems :)

The primary goal of this project is to have a comprehensive wrapper for PCRE2 in an ActiveX DLL for use in VB6 or other COM supporting languages.

The secondary goal of this project is to be a drop-in replacement for the VBSscript RegExp object.

vbpcre2's People

Contributors

jpbro avatar tannerhelland avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vbpcre2's Issues

Move all PCRE2 constants into enums in modPcre

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.

Should we match VBScript Object Names?

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.

Error checking in SubMatchValue()

"Invalid procedure call or argument".

ma_Ovector returns -1, when:

l_SubjectText = "Wyzo"
l_Regex = "(Manager)|^((copy of )?(" & "MX5|Wyzo" & "))$"

Should/can we statically link pcre-16.dll and VBPCRE2.dll?

@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!

Correction to code comments

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

Infinite loop in 'Replace' of empty line

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

Was MIT the right license for VBPCRE2?

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!

Pre-built VBPCRE2Test.exe in /bin folder is out-of-date

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!

Bad Submatch Handling Discovered

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.

Office 365 64-bit. "Class not Registered"

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

Brackets [] in enum

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?

Different Results vs. VBScript?

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?

Feature: FirstIndex of CPcreMatch

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.

Callout testing

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:

  1. Inside 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.

  1. To test, add this declaration to 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... ;)

Unused variables

Found in CPcreOptionsReplace.cls:

Private m_MatchedEventEnabled As Boolean
Private m_SubstitutionCacheSize As Long

Not sure, is it not implemented or superfluous.

Create Tests Front-end

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.

Pointer problem with pcre2_set_callout

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?

Bad line breaks

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.

Object and Method Names Should More Closely Match PCRE2 Names

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).

Variable names prefixes

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.