EncodedCharSet class>charsetAt:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

EncodedCharSet class>charsetAt:

timrowledge
So far as I can tell, this method cannot return nil (well, unless somebody subverts things) and yet two senders try to handle the result being nil.

EncodedCharSet class>scanSelectorAt: and CompoundTextConvertor>nextPutValue:toStream:withShiftSequenceIfNeededForLeadingChar:

If the intent was that something ought to sometimes happen that actually can't, maybe the code needs checking, just in case. All the other senders rely on the result being non-nil.

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Fractured Idiom:- POSH MORTEM - Death styles of the rich and famous



Reply | Threaded
Open this post in threaded view
|

Re: EncodedCharSet class>charsetAt:

Nicolas Cellier
(1 to: 30) collect: [:i | EncodedCharSet charsetAt: i]
->
{JISX0208 . GB2312 . KSX1001 . JISX0208 . JapaneseEnvironment . SimplifiedChineseEnvironment . KoreanEnvironment . GB2312 . nil . nil . nil . KSX1001 . nil . nil . nil . nil . nil . nil . nil . nil . nil . nil . nil . nil . nil . nil . nil . nil . nil . nil}

So if you manufactured a character with leadingChar 25 for example, that would be nil...


2013/10/1 tim Rowledge <[hidden email]>
So far as I can tell, this method cannot return nil (well, unless somebody subverts things) and yet two senders try to handle the result being nil.

EncodedCharSet class>scanSelectorAt: and CompoundTextConvertor>nextPutValue:toStream:withShiftSequenceIfNeededForLeadingChar:

If the intent was that something ought to sometimes happen that actually can't, maybe the code needs checking, just in case. All the other senders rely on the result being non-nil.

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Fractured Idiom:- POSH MORTEM - Death styles of the rich and famous






Reply | Threaded
Open this post in threaded view
|

Re: EncodedCharSet class>charsetAt:

timrowledge

On 01-10-2013, at 2:19 PM, Nicolas Cellier <[hidden email]> wrote:

> (1 to: 30) collect: [:i | EncodedCharSet charsetAt: i]

Well that is interesting. The code uses at:ifAbsent:, clearly intending to prevent a nil result - and as I mentioned all but two senders rely on a 'proper' answer. Oh, here we are - SequenceableCollection>at:ifAbsent: *only* treats outside the 1..size range as absent, not a nil. I'm thinking the original code was predicated on a Dictionary and then the collection was changed to an Array.

So I'd suggest
charsetAt: encoding

        ^ (EncodedCharSets at: encoding + 1) ifNil: [EncodedCharSets at: 1].
… assuming we prefer

(1 to: 30) collect: [:i | EncodedCharSet charsetAt: i]  
--> {JISX0208 . GB2312 . KSX1001 . JISX0208 . JapaneseEnvironment . SimplifiedChineseEnvironment . KoreanEnvironment . GB2312 . Unicode . Unicode . Unicode . KSX1001 . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode}

At least it isn't {Developers. Developers. Developers. Developers. Developers. Developers. Developers. } ;-)

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Implementation is the sincerest form of flattery.



Reply | Threaded
Open this post in threaded view
|

Re: EncodedCharSet class>charsetAt:

Nicolas Cellier
Good idea, or just ^Unicode.


2013/10/1 tim Rowledge <[hidden email]>

On 01-10-2013, at 2:19 PM, Nicolas Cellier <[hidden email]> wrote:

> (1 to: 30) collect: [:i | EncodedCharSet charsetAt: i]

Well that is interesting. The code uses at:ifAbsent:, clearly intending to prevent a nil result - and as I mentioned all but two senders rely on a 'proper' answer. Oh, here we are - SequenceableCollection>at:ifAbsent: *only* treats outside the 1..size range as absent, not a nil. I'm thinking the original code was predicated on a Dictionary and then the collection was changed to an Array.

So I'd suggest
charsetAt: encoding

        ^ (EncodedCharSets at: encoding + 1) ifNil: [EncodedCharSets at: 1].
… assuming we prefer

(1 to: 30) collect: [:i | EncodedCharSet charsetAt: i]
--> {JISX0208 . GB2312 . KSX1001 . JISX0208 . JapaneseEnvironment . SimplifiedChineseEnvironment . KoreanEnvironment . GB2312 . Unicode . Unicode . Unicode . KSX1001 . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode . Unicode}

At least it isn't {Developers. Developers. Developers. Developers. Developers. Developers. Developers. } ;-)
Implementation is the sincerest form of flattery.