package jsonnum

Import Path
	github.com/goccy/go-json/internal/jsonnum (on go.dev)

Dependency Relation
	imports 3 packages, and imported by 3 packages

Involved Source Files Package jsonnum reads JSON numbers by the grammar of RFC 8259, section 6, for the encoder and the decoder of encoding/json and for jsontext. The callers write their own errors from where a number is invalid. parse.go pow10.go pow10_table.go
Package-Level Type Names (only one)
/* sort by: | */
Place is where Scan found a number invalid. func Scan(b []byte) (int, Place) const Exponent const Fraction const Start const Valid
Package-Level Functions (total 12)
End returns the end of the valid JSON number which starts b, if a byte which ends it follows it in b, or -1: at an error, and at a number which may continue after b. It is the fast check of a scanner which reads its input by parts.
GatherTops gathers the top bits of the bytes of m, which has no other bits, into a byte: of the byte i in the bit i.
IsFloatContinuation reports whether c continues an integer as a number which is not an integer.
IsValid reports whether b is one JSON number, without anything before or after it. It takes a byte at a time by one lookup in a table of the states of the grammar, nearly as cheap as a check of the bytes alone, for the short numbers which a json.Number has: the state is the index of its row, which the byte is added to.
NonDigitTops has the top bit of each byte of w which is not a digit. It is small enough to be inlined, as GatherTops is.
ParseDigits reads the digits at cursor, which starts a number after its sign, in a terminated buffer, and returns their value, the position after them and their number. A number which starts with 0 has no other digit: the digit after it, if any, is not read. The value is exact for up to MaxUint64Digits digits; the value of more may wrap around, and be any value, 0 too, which only their number tells.
ParseFloat is ParseFloatTerminated of b, which is a JSON number and nothing else: it is copied to a terminated buffer of its own. It returns false where strconv parses the number.
ParseFloatTerminated parses the number at cursor of a terminated buffer, as the JSON grammar has it, when its mantissa has at most 19 digits: the float64 of a mantissa of at most 53 bits times or divided by a power of ten which a float64 holds exactly is correctly rounded as it is ( Clinger's fast path ), and any other is multiplied by the power of ten from a table ( mulPow10 ). The result is the one of strconv.ParseFloat, and the position after the number. It returns false for a number which is not decided so, or anything which is not a number by the grammar, which the caller parses as it did before.
ParseUint is the value of b, which is the digits of an integer without a sign and nothing else, and true; or false if b is not one, as an integer which starts with 0 and has more digits, or its value overflows a uint64.
Scan returns the length of the longest JSON number which b starts with, and Valid; or, if the number is invalid, the position of the byte where it is, which is len(b) if b ends there, and the place of that byte. The byte after a valid number is not looked at: it may be anything, which the caller checks.
ScanDigits returns the position of the first byte of b from i which is not a digit, or len(b). Long runs of digits, as the fractions of floats have, are looked at 8 bytes at a time.
TwentyDigits is the value of the 20 digits at start, which ParseDigits doesn't take exactly, and true if it fits a uint64: the value of the first 19 is exact, and the last one fits if the whole is less than 1<<64.
Package-Level Constants (total 5)
const Exponent Place = 3 // the first digit of the exponent, after its sign if any
const Fraction Place = 2 // the first digit after the decimal point
MaxUint64Digits is the number of the digits which a uint64 holds whatever they are: 19 nines are less than 1<<64.
const Start Place = 1 // the first digit, after the sign if any
const Valid Place = 0 // the number is valid