// lower(c) is a lower-case letter if and only if // c is either that lower-case letter or the equivalent upper-case letter. // Instead of writing c == 'x' || c == 'X' one can write lower(c) == 'x'. // Note that lower of non-letters can produce other non-letters. func lower(c byte) byte { … } var ErrRange … var ErrSyntax … type NumError … func (e *NumError) Error() string { … } func (e *NumError) Unwrap() error { … } func syntaxError(fn, str string) *NumError { … } func rangeError(fn, str string) *NumError { … } func baseError(fn, str string, base int) *NumError { … } func bitSizeError(fn, str string, bitSize int) *NumError { … } const intSize … const IntSize … const maxUint64 … // ParseUint is like [ParseInt] but for unsigned numbers. // // A sign prefix is not permitted. func ParseUint(s string, base int, bitSize int) (uint64, error) { … } // ParseInt interprets a string s in the given base (0, 2 to 36) and // bit size (0 to 64) and returns the corresponding value i. // // The string may begin with a leading sign: "+" or "-". // // If the base argument is 0, the true base is implied by the string's // prefix following the sign (if present): 2 for "0b", 8 for "0" or "0o", // 16 for "0x", and 10 otherwise. Also, for argument base 0 only, // underscore characters are permitted as defined by the Go syntax for // [integer literals]. // // The bitSize argument specifies the integer type // that the result must fit into. Bit sizes 0, 8, 16, 32, and 64 // correspond to int, int8, int16, int32, and int64. // If bitSize is below 0 or above 64, an error is returned. // // The errors that ParseInt returns have concrete type [*NumError] // and include err.Num = s. If s is empty or contains invalid // digits, err.Err = [ErrSyntax] and the returned value is 0; // if the value corresponding to s cannot be represented by a // signed integer of the given size, err.Err = [ErrRange] and the // returned value is the maximum magnitude integer of the // appropriate bitSize and sign. // // [integer literals]: https://go.dev/ref/spec#Integer_literals func ParseInt(s string, base int, bitSize int) (i int64, err error) { … } // Atoi is equivalent to ParseInt(s, 10, 0), converted to type int. func Atoi(s string) (int, error) { … } // underscoreOK reports whether the underscores in s are allowed. // Checking them in this one function lets all the parsers skip over them simply. // Underscore must appear only between digits or between a base prefix and a digit. func underscoreOK(s string) bool { … }