package strconv
-import "errors"
+import (
+ "errors"
+ "internal/stringslite"
+)
// lower(c) is a lower-case letter if and only if
// c is either that lower-case letter or the equivalent upper-case letter.
func (e *NumError) Unwrap() error { return e.Err }
-// cloneString returns a string copy of x.
-//
// All ParseXXX functions allow the input string to escape to the error value.
// This hurts strconv.ParseXXX(string(b)) calls where b is []byte since
// the conversion from []byte must allocate a string on the heap.
// back to the output by copying it first. This allows the compiler to call
// strconv.ParseXXX without a heap allocation for most []byte to string
// conversions, since it can now prove that the string cannot escape Parse.
-//
-// TODO: Use strings.Clone instead? However, we cannot depend on "strings"
-// since it incurs a transitive dependency on "unicode".
-// Either move strings.Clone to an internal/bytealg or make the
-// "strings" to "unicode" dependency lighter (see https://go.dev/issue/54098).
-func cloneString(x string) string { return string([]byte(x)) }
func syntaxError(fn, str string) *NumError {
- return &NumError{fn, cloneString(str), ErrSyntax}
+ return &NumError{fn, stringslite.Clone(str), ErrSyntax}
}
func rangeError(fn, str string) *NumError {
- return &NumError{fn, cloneString(str), ErrRange}
+ return &NumError{fn, stringslite.Clone(str), ErrRange}
}
func baseError(fn, str string, base int) *NumError {
- return &NumError{fn, cloneString(str), errors.New("invalid base " + Itoa(base))}
+ return &NumError{fn, stringslite.Clone(str), errors.New("invalid base " + Itoa(base))}
}
func bitSizeError(fn, str string, bitSize int) *NumError {
- return &NumError{fn, cloneString(str), errors.New("invalid bit size " + Itoa(bitSize))}
+ return &NumError{fn, stringslite.Clone(str), errors.New("invalid bit size " + Itoa(bitSize))}
}
const intSize = 32 << (^uint(0) >> 63)
un, err = ParseUint(s, base, bitSize)
if err != nil && err.(*NumError).Err != ErrRange {
err.(*NumError).Func = fnParseInt
- err.(*NumError).Num = cloneString(s0)
+ err.(*NumError).Num = stringslite.Clone(s0)
return 0, err
}