-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #752 from pillar-markup/nicerSplitFirstOnUsage
Nicer split first on usage
- Loading branch information
Showing
3 changed files
with
29 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,25 @@ | ||
Extension { #name : 'SequenceableCollection' } | ||
|
||
{ #category : '*Microdown' } | ||
SequenceableCollection >> splitOnFirst: char [ | ||
| indexOfChar | | ||
indexOfChar := self indexOf: char. | ||
indexOfChar = 0 ifTrue: [ ^{self. nil} ]. | ||
^{self copyFrom: 1 to: indexOfChar -1. self copyFrom: indexOfChar +1 to: self size} | ||
SequenceableCollection >> splitOnFirst: anObject [ | ||
"Split the receiver on the first element that match anObject, returns two sequenceable." | ||
|
||
"#(1 2 3 0 4 5 6 0 7) splitOnFirst: 0 >> #(#(1 2 3) #(4 5 6 0 7)) " | ||
"#(1 2 3 0 4 5 6 0 7) splitOnFirst: 99 >> #(#(1 2 3 04 5 6 0 7) #() " | ||
|
||
^ self splitOnFirst: anObject noneValue: #() | ||
] | ||
|
||
{ #category : '*Microdown' } | ||
SequenceableCollection >> splitOnFirst: anObject noneValue: aValue [ | ||
"Split the receiver on the first element that match anObject" | ||
|
||
"#(1 2 3 0 4 5 6 0 7) splitOnFirst: 0 noneValue: 33>> #(#(1 2 3) #(4 5 6 0 7)) " | ||
"#(1 2 3 0 4 5 6 0 7) splitOnFirst: 99 noneValue: #()>> #(#(1 2 3 04 5 6 0 7) #() " | ||
|
||
| element | | ||
element := self indexOf: anObject. | ||
element = 0 ifTrue: [ ^ { self. aValue } ]. | ||
^ { self copyFrom: 1 to: element -1 . self copyFrom: element + 1 to: self size } | ||
|
||
] |