Skip to content

Commit

Permalink
Merge pull request #752 from pillar-markup/nicerSplitFirstOnUsage
Browse files Browse the repository at this point in the history
Nicer split first on usage
  • Loading branch information
Ducasse authored May 26, 2024
2 parents 7641d44 + dbdb9ba commit d782fc7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
5 changes: 3 additions & 2 deletions src/Microdown/MicArgumentList.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ MicArgumentList >> setNoDefaultButArguments: string [
"string is assumed to be on the form key=value&key=value"
| pairs |
pairs := string splitOn: $&.
pairs do: [ :p | |keyValue|
keyValue := p splitOnFirst: $=.
pairs do: [ :p |
| keyValue |
keyValue := p splitOnFirst: $= noneValue: nil.
self at: keyValue first trim asSymbol put: keyValue second ]

]
Expand Down
14 changes: 6 additions & 8 deletions src/Microdown/MicInlineBlockWithUrl.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,14 @@ MicInlineBlockWithUrl >> children: anObject [

{ #category : 'visiting' }
MicInlineBlockWithUrl >> closeMe [
"the link url - ![alt text](url) - url is allowed to have title in quotes
(url ""title"") "

| split title |
split := url splitOnFirst: Character space.
| split |
split := url splitOnFirst: Character space noneValue: nil.
self reference: (MicResourceReference fromUri: split first).
self arguments ifNil: [
title := (split second ifNil: [ '' ])
trimBoth: [:char | {$". Character space} includes: char].
self arguments: (MicArgumentList withString: title)]
self arguments
ifNil: [ | title |
title := split second ifNotNil: [ :s | s] ifNil: [ '' ].
self arguments: (MicArgumentList withString: title) ]
]

{ #category : 'utilities' }
Expand Down
25 changes: 20 additions & 5 deletions src/Microdown/SequenceableCollection.extension.st
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 }

]

0 comments on commit d782fc7

Please sign in to comment.