>to "capitalize" is writing a word with its first letter.

The Smalltalk String is not neccessarily just a word, it could be something 
else so the current implementation makes no assumptions of what the string is.

---------------------------------------------------------------------------------------------

| newClass |

newClass := Object subclass: #AbcSomeClass
instanceVariableNames: 'errorCodeName referencePosition instanceVariable'.
newClass instanceVariableNamesDo: [ :aString | | code |
code := String streamContents: [ :aStream | | prefix cap |
prefix := aString first isVowel ifTrue: ['an'] ifFalse: ['a'].
cap := aString capitalized.
aStream
<< aString; << ':'; space; << prefix; << cap;
cr; cr; tab;
<< aString; << ' := '; << prefix; << cap.
].
newClass compile: code classified: 'accessing'
].

newClass browse
--------------------------------------------------------------------------------------------


>Should we fix this? Do not know about any side effects...

I think it would be better and more clear to then implement a new method called 
something like #onlyCapitalized that removes all other uppercase letters.


Best regards,

Henrik


________________________________
Fra: Pharo-dev <[email protected]> på vegne av Torsten Bergmann 
<[email protected]>
Sendt: 15. mars 2017 11:33:35
Til: Pharo Development List
Emne: [Pharo-dev] Capitalized

According to https://en.wikipedia.org/wiki/Capitalization

to "capitalize" is writing a word with its first letter as a capital letter 
(upper-case letter)
AND THE REMAINING LETTERS IN LOWER CASE writing systems.

So

  'SOMETHING' capitalized

currently returns "SOMETHING" in Pharo but should return "Something" according 
to the definition to end up with lowercase.
If we fix this I guess we would also align Pharo with other languages, like C# 
for example [1].

Could be easily changed by replacing "copy" with "asLowercase" in #capitalized:

 capitalized
        "Return a copy with the first letter capitalized"
        | cap |
        self isEmpty ifTrue: [ ^self copy ].
        cap := self asLowercase.
        cap at: 1 put: (cap at: 1) asUppercase.
        ^ cap

Should we fix this? Do not know about any side effects...


Note: a) Squeak has the same issue
      b) it fits for #uncapitalized, see [2]
      c) Dont know about ANSI standard or any other ST dialect

Thx
T.


[1] 
https://github.com/srkirkland/Inflector/blob/master/Inflector.Tests/CapitalizeTests.cs
[2] 
https://github.com/srkirkland/Inflector/blob/master/Inflector.Tests/UncapitalizeTests.cs

Reply via email to