This project is read-only.

Regex instance methods

Jul 4, 2013 at 4:28 PM
I would like to suggest to add the following definitions to (ironscheme regex):
(clr-using System.Text.RegularExpressions)
(define/contract (regex-compiled-match? input:string regex:regex)
    (clr-call Regex IsMatch regex input))
(define/contract (regex-compiled-match input:string regex:regex)
    (clr-call Regex Match regex input))
Background: I am analyzing big logfiles and the use of compiled Regex objects really saves some time there.


P.S: Feel free to choose another name for regex-compiled-* if you like.
Jul 4, 2013 at 4:39 PM
It seems I was already setting it for compiled, but forgot to change it to proper casing (this might or might not indicate a bug in the enum conversions.

But yes, I will add those overloads to the existing methods :)

Jul 4, 2013 at 4:53 PM
It seems for enums I did not goto the case-sensitive route (should I?).

I will commit the following after running tests, but it should cater for your requirements. You can now just pass the options to the constructor, and use the usual match procedures. Making an additional constructor for compiled regex's seems a bit redundant.

What do you think?
  (define/contract make-regex
        (clr-new Regex pattern)]
      [(pattern:string options:symbol)
        (clr-new Regex pattern options)]))
  (define/contract (regex-match input:string pattern/re)
      [(regex? pattern/re)
        (clr-call Regex Match pattern/re input)]
      [(string? pattern/re) 
        (clr-static-call Regex Match input pattern/re)]
        (assertion-violation 'regex-match "not a string or regex" pattern/re)]))

  (define/contract (regex-matches input:string pattern/re)
    (clr-static-call IronScheme.Runtime.Cons FromList
        [(regex? pattern/re)
          (clr-call Regex Matches pattern/re input)]
        [(string? pattern/re)
          (clr-static-call Regex Matches input pattern/re)]
          (assertion-violation 'regex-match "not a string or regex" pattern/re)])))
Jul 4, 2013 at 5:04 PM
Jul 5, 2013 at 9:01 AM

that works for me! Using overloaded functions and a single constructor is definetely the better option.

I'm not sure that I followed your thoughts on enum cases, correctly. For me it looks like that
(make-regex "test" 'compiled)
(make-regex "test" 'Compiled) both generates compiled Regex instances.

Jul 5, 2013 at 12:03 PM
Cool :)

At one stage I allowed for types and methods for CLR to be case-insensitive, but that was changed a long time ago ;p