[squeak-dev] The Inbox: Collections-mt.1018.mcz

Eliot Miranda eliot.miranda at gmail.com
Tue Jul 12 14:11:18 UTC 2022


+1 for moving to trunk…

_,,,^..^,,,_ (phone)

> On Jul 12, 2022, at 6:27 AM, commits at source.squeak.org wrote:
> 
> A new version of Collections was added to project The Inbox:
> http://source.squeak.org/inbox/Collections-mt.1018.mcz
> 
> ==================== Summary ====================
> 
> Name: Collections-mt.1018
> Author: mt
> Time: 12 July 2022, 3:27:38.665003 pm
> UUID: e638fd0a-45c9-594f-b984-6d5e3ab1d882
> Ancestors: Collections-cmm.1017
> 
> Propose #match:ignoringCase: akin to #matchesRegexIgnoringCase: but with that other algorithm.
> 
> Note that the message #match:ignoreCase: is present in VisualWorks.
> 
> =============== Diff against Collections-cmm.1017 ===============
> 
> Item was changed:
>  ----- Method: String>>match: (in category 'comparing') -----
>  match: text
>      "Answer whether text matches the pattern in this string.
>      Matching ignores upper/lower case differences.
>      Where this string contains #, text may contain any character.
>      Where this string contains *, text may contain any sequence of characters."
> 
> +    ^ self startingAt: 1 match: text startingAt: 1 ignoringCase: true
> -    ^ self startingAt: 1 match: text startingAt: 1
>  "
>      '*'            match: 'zort' true
>      '*baz'        match: 'mobaz' true
>      '*baz'        match: 'mobazo' false
>      '*baz*'        match: 'mobazo' true
>      '*baz*'        match: 'mozo' false
>      'foo*'        match: 'foozo' true
>      'foo*'        match: 'bozo' false
>      'foo*baz'    match: 'foo23baz' true
>      'foo*baz'    match: 'foobaz' true
>      'foo*baz'    match: 'foo23bazo' false
>      'foo'        match: 'Foo' true
>      'foo*baz*zort' match: 'foobazort' false
>      'foo*baz*zort' match: 'foobazzort' true
>      '*foo#zort'    match: 'afoo3zortthenfoo3zort' true
>      '*foo*zort'    match: 'afoodezortorfoo3zort' true
>  "!
> 
> Item was added:
> + ----- Method: String>>match:ignoringCase: (in category 'comparing') -----
> + match: text ignoringCase: aBool
> + 
> +    ^ self startingAt: 1 match: text startingAt: 1 ignoringCase: aBool!
> 
> Item was changed:
>  ----- Method: String>>startingAt:match:startingAt: (in category 'comparing') -----
>  startingAt: keyStart match: text startingAt: textStart
> -    "Answer whether text matches the pattern in this string.
> -    Matching ignores upper/lower case differences.
> -    Where this string contains #, text may contain any character.
> -    Where this string contains *, text may contain any sequence of characters."
> -    
> -    | anyMatch matchStart matchEnd i matchStr j ii jj |
> -    i := keyStart.
> -    j := textStart.
> -    
> -    "Process consecutive *s and #s at the beginning."
> -    anyMatch := false.
> -    [ i <= self size and: [
> -        (self at: i)
> -            caseOf: {
> -                [ $* ] -> [ 
> -                    anyMatch := true.
> -                    i := i + 1.
> -                    true ].
> -                [ $# ] -> [
> -                    i := i + 1.
> -                    j := j + 1.
> -                    true ] }
> -            otherwise: [ false ] ] ] whileTrue.
> -    i > self size ifTrue: [
> -        ^j - 1 = text size or: [ "We reached the end by matching the character with a #."
> -            anyMatch and: [ j <= text size ] "Or there was a * before the end." ] ].
> -    matchStart := i.
> 
> +    ^ self startingAt: keyStart match: text startingAt: textStart ignoringCase: true!
> -    "Now determine the match string"
> -    matchEnd := self size.
> -    (ii := self indexOf: $* startingAt: matchStart) > 0 ifTrue: [ matchEnd := ii-1 ].
> -    (ii := self indexOf: $# startingAt: matchStart) > 0 ifTrue: [ matchEnd := matchEnd min: ii-1 ].
> -    matchStr := self copyFrom: matchStart to: matchEnd.
> - 
> -    "Now look for the match string"
> -    [jj := text findString: matchStr startingAt: j caseSensitive: false.
> -    anyMatch ifTrue: [jj > 0] ifFalse: [jj = j]]
> -        whileTrue:
> -        ["Found matchStr at jj.  See if the rest matches..."
> -        (self startingAt: matchEnd+1 match: text startingAt: jj + matchStr size) ifTrue:
> -            [^ true "the rest matches -- success"].
> -        "The rest did not match."
> -        anyMatch ifFalse: [^ false].
> -        "Preceded by * -- try for a later match"
> -        j := j+1].
> -    ^ false "Failed to find the match string"!
> 
> Item was added:
> + ----- Method: String>>startingAt:match:startingAt:ignoringCase: (in category 'comparing') -----
> + startingAt: keyStart match: text startingAt: textStart ignoringCase: ignoreCase
> +    "Answer whether text matches the pattern in this string.
> +    Matching ignores upper/lower case differences if ignoreCase is true.
> +    Where this string contains #, text may contain any character.
> +    Where this string contains *, text may contain any sequence of characters."
> +    
> +    | anyMatch matchStart matchEnd i matchStr j ii jj |
> +    i := keyStart.
> +    j := textStart.
> +    
> +    "Process consecutive *s and #s at the beginning."
> +    anyMatch := false.
> +    [ i <= self size and: [
> +        (self at: i)
> +            caseOf: {
> +                [ $* ] -> [ 
> +                    anyMatch := true.
> +                    i := i + 1.
> +                    true ].
> +                [ $# ] -> [
> +                    i := i + 1.
> +                    j := j + 1.
> +                    true ] }
> +            otherwise: [ false ] ] ] whileTrue.
> +    i > self size ifTrue: [
> +        ^j - 1 = text size or: [ "We reached the end by matching the character with a #."
> +            anyMatch and: [ j <= text size ] "Or there was a * before the end." ] ].
> +    matchStart := i.
> + 
> +    "Now determine the match string"
> +    matchEnd := self size.
> +    (ii := self indexOf: $* startingAt: matchStart) > 0 ifTrue: [ matchEnd := ii-1 ].
> +    (ii := self indexOf: $# startingAt: matchStart) > 0 ifTrue: [ matchEnd := matchEnd min: ii-1 ].
> +    matchStr := self copyFrom: matchStart to: matchEnd.
> + 
> +    "Now look for the match string"
> +    [jj := text findString: matchStr startingAt: j caseSensitive: ignoreCase not.
> +    anyMatch ifTrue: [jj > 0] ifFalse: [jj = j]]
> +        whileTrue:
> +        ["Found matchStr at jj.  See if the rest matches..."
> +        (self startingAt: matchEnd+1 match: text startingAt: jj + matchStr size ignoringCase: ignoreCase) ifTrue:
> +            [^ true "the rest matches -- success"].
> +        "The rest did not match."
> +        anyMatch ifFalse: [^ false].
> +        "Preceded by * -- try for a later match"
> +        j := j+1].
> +    ^ false "Failed to find the match string"!
> 
> 


More information about the Squeak-dev mailing list