[Newbies] Color>>hex doesn't work ...

Stephen Davies stephen.l.davies at gmail.com
Sat May 6 09:15:13 UTC 2006


Color>>hex in my 3.8 image sends a 'radix indicator not found' error.

This seems to be because SmallInteger>>printStringRadix: puts a "10r"
or "-10r" at the start of the printed value when asked for base 10,
but doesn't put in a "XXr" when asked for other bases.

The relevant bit of code in Color>>hex does this

Here's SmallInteger>>printStringRadix:

printStringRadix: baseInteger
	"Return a string containing a sequence of characters that represents the
	numeric value of the receiver in the radix specified by the argument.
	If the receiver is negative, a minus sign ('-') is prepended to the
	sequence of characters.
	The result is undefined if baseInteger less than 2 or greater than 36."
	| tempString |
	"2000/03/04  Harmon R. Added ANSI <integer> protocol"
	baseInteger = 10
			[tempString := self printStringBase: baseInteger.
			self negative
				ifTrue: [^ '-10r' , (tempString copyFrom: 2 to: tempString size)]
				ifFalse: [^ '10r' , tempString]].
	^ self printStringBase: baseInteger

and printStringBase:

printStringBase: base
	| stream integer next |
	self = 0 ifTrue: [^'0'].
	self negative ifTrue: [^'-', (self negated printStringBase: base)].
	stream := WriteStream on: String new.
	integer := self normalize.
	[integer > 0] whileTrue: [
		next := integer quo: base.
		stream nextPut: (Character digitValue: integer - (next * base)).
		integer := next].
	^stream contents reversed

So - how to fix.  One "low touch" fix is just to get Color>>hex not to
fuss if it can't find the "r" that it thinks should be there.  But
that leaves the strange behaviour of printStringRadix: which can't
make up its mind whether to show the radix or not.  I don't know what
the right behaviour is; the comment in the methd doesn't clarify.

So - what would an experienced Squeaker do?


More information about the Beginners mailing list