help-smalltalk
[Top][All Lists]
Advanced

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

Re: [Help-smalltalk] [bug] (a RegexResults) at: n throws error if captur


From: Sergio
Subject: Re: [Help-smalltalk] [bug] (a RegexResults) at: n throws error if captured at n is empty string
Date: Mon, 09 Dec 2013 20:05:03 +0400

08.12.2013, 23:30, "Holger Hans Peter Freyther" <address@hidden>:
> On Sat, Dec 07, 2013 at 10:32:58PM +0100, Holger Hans Peter Freyther wrote:
>
> Attached is a work-around + test-case. Could you have a look and give it
> a try?

I guess I need a version from git to try it? As for 3.2.5 only kernel/Regex.st 
part of patch can be applied to. Yes, it works.


But I still think the empty string as return is more consistent design.

Here is an example code demonstrating when captured sub-matches contain nils:

  'Mary Jane Emily' =~ '(\w+)( \w+)?( \w+)?( \w+)?( \w+)?' ifMatched: [ :mm |
    Transcript show: 'Matches size: ' , mm size asString ;  nl.
    1 to: mm size do: [ :n | Transcript show: 'Matches at: ' , n asString , ' 
is: ' , (mm at: n) printString ;  nl ] ].

Here all the groups in braces except the first one are "optional". 2nd and 3rd 
match to Jane and Emily, 4th and 5th stay "unused".
Output:

Matches size: 5
Matches at: 1 is: 'Mary'
Matches at: 2 is: ' Jane'
Matches at: 3 is: ' Emily'
Matches at: 4 is: nil
Matches at: 5 is: nil

That is difference. For "optional catcher" that has NO match and stay unused 
nil is returned. If empty sequence is successfully matched empty sequence is 
returned. It's just my vision though.

-- 
/sergio



reply via email to

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