'From Cuis 5.0 [latest update: #4641] on 26 June 2021 at 2:17:52 pm'!

!Integer class methodsFor: 'instance creation' stamp: 'KenD 6/26/2021 14:17:46'!
xReadFrom: aStream base: base
	"Answer an instance of one of my concrete subclasses. Initial minus sign
	accepted, and bases > 10 use letters A-Z. Embedded radix specifiers not
	allowed--use Number readFrom: for that. Raises an error if
	there are no digits."

	| digit value neg cc atLeastOneDigitRead |
	
	(aStream atEnd) ifTrue: [ self error: 'At least one digit expected here' ].
	
	neg := aStream peekFor: $-.
	neg ifFalse: [aStream peekFor: $+].
	value  := 0.
	atLeastOneDigitRead  := false.
"	Transcript log: 'vvv=========vvv'.
"	[ aStream atEnd ]
		whileFalse: [
			cc  := aStream next.
			digit  := cc digitValue.
			(digit < 0 or: [digit >= base])
				ifTrue: [
					aStream skip: -1.
					atLeastOneDigitRead ifFalse: [self error: 'At least one digit expected here'].
					^neg
						ifTrue: [value negated]
						ifFalse: [value]].
			value  := value * base + digit.
"			Transcript log: '16r', value printStringHex, '  ', value class printString; newLine.
"			atLeastOneDigitRead  := true ].
"	Transcript log: '^^^=========^^^'.
"	neg ifTrue: [^ value negated].
	^ value! !
