// scan sets z to the natural number corresponding to the longest possible prefix
// read from r representing an unsigned integer in a given conversion base.
// It returns z, the actual conversion base used, and an error, if any. In the
// error case, the value of z is undefined. The syntax follows the syntax of
// unsigned integer literals in Go.
//
// The base argument must be 0 or a value from 2 through MaxBase. If the base
// is 0, the string prefix determines the actual conversion base. A prefix of
// ``0x'' or ``0X'' selects base 16; the ``0'' prefix selects base 8, and a
// ``0b'' or ``0B'' prefix selects base 2. Otherwise the selected base is 10.
//
scan sets z to the natural number corresponding to the longest possible prefix
read from r representing an unsigned integer in a given conversion base.
It returns z, the actual conversion base used, and an error, if any. In the
error case, the value of z is undefined. The syntax follows the syntax of
unsigned integer literals in Go.

The base argument must be 0 or a value from 2 through MaxBase. If the base
is 0, the string prefix determines the actual conversion base. A prefix of
``0x'' or ``0X'' selects base 16; the ``0'' prefix selects base 8, and a
``0b'' or ``0B'' prefix selects base 2. Otherwise the selected base is 10.
// scan sets z to the natural number corresponding to the longest possible prefix // read from r representing an unsigned integer in a given conversion base . // It returns z the actual conversion base used and an error if any . In the // error case the value of z is undefined . The syntax follows the syntax of // unsigned integer literals in Go . // // The base argument must be 0 or a value from 2 through MaxBase . If the base // is 0 the string prefix determines the actual conversion base . A prefix of // ` ` 0x ' ' or ` ` 0X ' ' selects base 16 ; the ` ` 0 ' ' prefix selects base 8 and a // ` ` 0b ' ' or ` ` 0B ' ' prefix selects base 2 . Otherwise the selected base is 10 . //
func (z nat) scan(r io.RuneScanner, base int) (nat, int, error) {
	if base < 0 || base == 1 || MaxBase < base {
		return z, 0, errors.New("illegal number base")
	}
	ch, _, err := r.ReadRune()
	if err != nil {
		return z, 0, err
	}
	b := Word(base)
	if base == 0 {
		b = 10
		if ch == '0' {
			switch ch, _, err = r.ReadRune(); err {
			case nil:
				b = 8
				switch ch {
				case 'x', 'X':
					b = 16
				case 'b', 'B':
					b = 2
				}
				if b == 2 || b == 16 {
					if ch, _, err = r.ReadRune(); err != nil {
						return z, 0, err
					}
				}
			case io.EOF:
				return z.make(0), 10, nil
			default:
				return z, 10, err
			}
		}
	}
	z = z.make(0)
	bb := Word(1)
	dd := Word(0)
	for max := _M / b; ; {
		d := hexValue(ch)
		if d >= b {
			r.UnreadRune() 
			break
		}
		if bb <= max {
			bb *= b
			dd = dd*b + d
		} else {
			z = z.mulAddWW(z, bb, dd)
			bb = b
			dd = d
		}
		if ch, _, err = r.ReadRune(); err != nil {
			if err != io.EOF {
				return z, int(b), err
			}
			break
		}
	}
	switch {
	case bb > 1:
		z = z.mulAddWW(z, bb, dd)
	case base == 0 && b == 8:
		return z, 10, nil
	case base != 0 || b != 8:
		return z, int(b), errors.New("syntax error scanning number")
	}
	return z.norm(), int(b), nil
}
func ( z nat ) scan ( r io . RuneScanner , base int ) ( nat , int , error ) { if base < 0 || base == 1 || MaxBase < base { return z , 0 , errors . New ( " " ) } ch , _ , err := r . ReadRune ( ) if err != nil { return z , 0 , err } b := Word ( base ) if base == 0 { b = 10 if ch == '0' { switch ch , _ , err = r . ReadRune ( ) ; err { case nil : b = 8 switch ch { case 'x' , 'X' : b = 16 case 'b' , 'B' : b = 2 } if b == 2 || b == 16 { if ch , _ , err = r . ReadRune ( ) ; err != nil { return z , 0 , err } } case io . EOF : return z . make ( 0 ) , 10 , nil default : return z , 10 , err } } } z = z . make ( 0 ) bb := Word ( 1 ) dd := Word ( 0 ) for max := _M / b ; ; { d := hexValue ( ch ) if d >= b { r . UnreadRune ( ) break } if bb <= max { bb *= b dd = dd * b + d } else { z = z . mulAddWW ( z , bb , dd ) bb = b dd = d } if ch , _ , err = r . ReadRune ( ) ; err != nil { if err != io . EOF { return z , int ( b ) , err } break } } switch { case bb > 1 : z = z . mulAddWW ( z , bb , dd ) case base == 0 && b == 8 : return z , 10 , nil case base != 0 || b != 8 : return z , int ( b ) , errors . New ( " " ) } return z . norm ( ) , int ( b ) , nil }
scan sets z to the natural number corresponding to the longest possible prefix
read from r representing an unsigned integer in a given conversion base.
scan sets z to the natural number corresponding to the longest possible prefix read from r representing an unsigned integer in a given conversion base .
// reject illegal bases // one char look-ahead // determine base if necessary // convert string // - group as many digits d as possible together into a "super-digit" dd with "super-base" bb // - only when bb does not fit into a word anymore, do a full number mulAddWW using bb and dd // ch does not belong to number anymore // bb * b would overflow // there was at least one mantissa digit // there was only the octal prefix 0 (possibly followed by digits > 7); // return base 10, not 8 // there was neither a mantissa digit nor the octal prefix 0