[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] [rfc] regex rewrite

From: Mike Anderson
Subject: Re: [Help-smalltalk] [rfc] regex rewrite
Date: Sat, 28 May 2005 19:31:02 +0000
User-agent: Mozilla Thunderbird 0.7.3 (X11/20040803)

Paolo Bonzini wrote:
I was about to make the #copyReplacingRegex:with: methods use
#bindWithArguments: but I decided that this patch was already big enough.
What do you think about this additional change?

You mean so that you can use backreferences in the replacement string? Emphatically yes. I think that that it's what you want more often than not.

Now, all that remains before this stuff can be made ``more'' official,
is writing some SUnit tests...  I'll get round to it, but if somebody
wants to help, patches are welcome as usual.

I have written some tests as a way of exploring the code, but I have this query:

CRegexRegisters >> #matchBeg and String >> #searchRegex: look like a failed match would return nil, but in practice, you get:

| mr |
mr := 'abc' searchRegex: '[0-9]+'.
mr isNil printNl. "false"
mr from printNl. "0".

Is that intended? My preference is that a failed match should return nil. In some ways, though, always returning a RegexResult, with the additional methods #ifMatched:ifNotMatched: and #isMatched methods, is more elegant.

I also think it would be more useful if =~ returned MatchResult/nil instead of true/false. After all, you can always write:

(myString =~ '[A-Z][a-z]*') notNil


reply via email to

[Prev in Thread] Current Thread [Next in Thread]