moosetechnology / ClassNameAnalyser

MIT License
5 stars 2 forks source link

DMNameTokenizer >> cutWhereCamelCase does nothing #11

Closed olekscode closed 5 years ago

olekscode commented 5 years ago

It just just calls another method. And creates an instance variable for some reason:

cutWhereCamelCase: aName
    "This method is implemented in String"

    | name |
    name := aName.
    ^ name cutWhereCamelCase.

I would just put cutWhereCamelCase method into DMNameTokenizer (not extend the String class). And rename it to tokenize:

DMNameTokenizer >> tokenize: aName
    | word token allTokens resultedTokens|
    word := aName deepCopy.
    token := ''.
    allTokens := OrderedCollection new.
    resultedTokens := OrderedCollection new.
    1 to: word size do: [ :index | (self checkCapitalLetter: (word at: index)) 
        ifTrue: [ 
            allTokens add: token.
            token := (word at: index) asString.
             ] 
        ifFalse: [ token := token , (word at: index) asString  ].
        (index == word size) 
        ifTrue: [ allTokens add: token ]
        ].
    token := ''.
    allTokens do:  [ :each | (each size == 1)
        ifTrue: [ token := token , each asString ]
        ifFalse: [ resultedTokens add: token. 
            token := ''.
            resultedTokens add: each ]
         ].
    resultedTokens add: token.
    ^ resultedTokens reject: [ :each | each size ==0 ]