Improved detection of keywords, arguments in a string.
This commit is contained in:
parent
0495319170
commit
9153efbbba
@ -78,8 +78,11 @@ GrafoscopioUtils class >> sanitize: url [
|
|||||||
|
|
||||||
{ #category : #utilities }
|
{ #category : #utilities }
|
||||||
GrafoscopioUtils class >> selectorAndArgumentsFrom: aString [
|
GrafoscopioUtils class >> selectorAndArgumentsFrom: aString [
|
||||||
"I return from aString a symbol that contains a message and an array of arguments used in it"
|
"I return from aString a dictionary that contains a message and an array of arguments used
|
||||||
| msgArray answer |
|
in such string. Notice that the keyword message must contain spaces between the ':' and its
|
||||||
|
respective argument.
|
||||||
|
See GrafoscopioUtilsTest for examples"
|
||||||
|
| msgArray answer keywords selector args |
|
||||||
answer := OrderedDictionary new.
|
answer := OrderedDictionary new.
|
||||||
msgArray := aString splitOn: ':'.
|
msgArray := aString splitOn: ':'.
|
||||||
msgArray size = 1
|
msgArray size = 1
|
||||||
@ -87,12 +90,18 @@ GrafoscopioUtils class >> selectorAndArgumentsFrom: aString [
|
|||||||
^ answer
|
^ answer
|
||||||
at: 'selector' put: (msgArray at: 1) asSymbol;
|
at: 'selector' put: (msgArray at: 1) asSymbol;
|
||||||
yourself ].
|
yourself ].
|
||||||
msgArray size = 2
|
selector := ''.
|
||||||
ifTrue: [
|
args := OrderedCollection new.
|
||||||
|
aString
|
||||||
|
splitOn: Character space
|
||||||
|
do: [ :part |
|
||||||
|
part endsWithAColon
|
||||||
|
ifTrue: [ selector := selector, part ]
|
||||||
|
ifFalse: [ args add: part ] ].
|
||||||
|
answer
|
||||||
|
at: 'selector' put: selector asSymbol;
|
||||||
|
at: 'args' put: args asArray.
|
||||||
^ answer
|
^ answer
|
||||||
at: 'selector' put: ((msgArray at: 1),':') asSymbol;
|
|
||||||
at: 'args' put: (Array with: (msgArray at: 2));
|
|
||||||
yourself ].
|
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #updating }
|
{ #category : #updating }
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
"
|
||||||
|
A GrafoscopioUtilsTest is a test class for testing the behavior of GrafoscopioUtils
|
||||||
|
"
|
||||||
|
Class {
|
||||||
|
#name : #GrafoscopioUtilsTest,
|
||||||
|
#superclass : #TestCase,
|
||||||
|
#category : #'Grafoscopio-Utils-Tests'
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user