nativehttp

Simple interface to the native http client
Log | Files | Refs | README | LICENSE

strconv.go (606B)


      1 package core
      2 
      3 // ParseUint is a specialized helper that parses a sequence of digits into an unsigned integer.
      4 func ParseUint(s string) (n uint, _ error) {
      5 	const asciiDigitOffset = 48
      6 
      7 	width := uint(len(s))
      8 
      9 	for ii := width; ii > 0; ii-- {
     10 		c := s[ii]
     11 		switch c {
     12 		case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
     13 			d := uint(c) - asciiDigitOffset
     14 			n += d * Pow(10, width-ii)
     15 		default:
     16 			return 0, parseErr{literal: c}
     17 		}
     18 	}
     19 
     20 	return n, nil
     21 }
     22 
     23 type parseErr struct {
     24 	literal byte
     25 }
     26 
     27 func (p parseErr) Error() string {
     28 	return "parse: invalid literal (not a digit) " + string(p.literal)
     29 }