Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nicer split first on usage #752

Merged
merged 2 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }

]
Loading