Regex instance methods

Jul 4, 2013 at 3: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.

Cheers,
Kay-Uwe

P.S: Feel free to choose another name for regex-compiled-* if you like.
Coordinator
Jul 4, 2013 at 3: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 :)

Thanks
Coordinator
Jul 4, 2013 at 3: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
    (case-lambda
      [(pattern:string)
        (clr-new Regex pattern)]
      [(pattern:string options:symbol)
        (clr-new Regex pattern options)]))
    
  (define/contract (regex-match input:string pattern/re)
    (cond 
      [(regex? pattern/re)
        (clr-call Regex Match pattern/re input)]
      [(string? pattern/re) 
        (clr-static-call Regex Match input pattern/re)]
      [else
        (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
      (cond 
        [(regex? pattern/re)
          (clr-call Regex Matches pattern/re input)]
        [(string? pattern/re)
          (clr-static-call Regex Matches input pattern/re)]
        [else
          (assertion-violation 'regex-match "not a string or regex" pattern/re)])))
Coordinator
Jul 4, 2013 at 4:04 PM
Jul 5, 2013 at 8:01 AM
Great,

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)
and
(make-regex "test" 'Compiled) both generates compiled Regex instances.

Thanks,
Kay-Uwe
Coordinator
Jul 5, 2013 at 11:03 AM
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