From 9153efbbbac655936f715001f36ddab9cf73b95d Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Sat, 26 Aug 2017 12:31:46 +0000 Subject: [PATCH] Improved detection of keywords, arguments in a string. --- .../GrafoscopioUtils.class.st | 25 +++++++++++++------ .../GrafoscopioUtilsTest.class.st | 8 ++++++ 2 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 repository/Grafoscopio-Utils/GrafoscopioUtilsTest.class.st diff --git a/repository/Grafoscopio-Utils/GrafoscopioUtils.class.st b/repository/Grafoscopio-Utils/GrafoscopioUtils.class.st index a700e79..83c9d5d 100644 --- a/repository/Grafoscopio-Utils/GrafoscopioUtils.class.st +++ b/repository/Grafoscopio-Utils/GrafoscopioUtils.class.st @@ -78,8 +78,11 @@ GrafoscopioUtils class >> sanitize: url [ { #category : #utilities } GrafoscopioUtils class >> selectorAndArgumentsFrom: aString [ - "I return from aString a symbol that contains a message and an array of arguments used in it" - | msgArray answer | + "I return from aString a dictionary that contains a message and an array of arguments used + 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. msgArray := aString splitOn: ':'. msgArray size = 1 @@ -87,12 +90,18 @@ GrafoscopioUtils class >> selectorAndArgumentsFrom: aString [ ^ answer at: 'selector' put: (msgArray at: 1) asSymbol; yourself ]. - msgArray size = 2 - ifTrue: [ - ^ answer - at: 'selector' put: ((msgArray at: 1),':') asSymbol; - at: 'args' put: (Array with: (msgArray at: 2)); - yourself ]. + selector := ''. + 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 ] { #category : #updating } diff --git a/repository/Grafoscopio-Utils/GrafoscopioUtilsTest.class.st b/repository/Grafoscopio-Utils/GrafoscopioUtilsTest.class.st new file mode 100644 index 0000000..76fcf6e --- /dev/null +++ b/repository/Grafoscopio-Utils/GrafoscopioUtilsTest.class.st @@ -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' +}