initial commits

master
Charles Iliya Krempeaux 2023-11-05 00:01:55 -07:00
parent f8b713a160
commit d40fa44b46
2 changed files with 8 additions and 25 deletions

View File

@ -1,19 +0,0 @@
package rfc8259wholenumber
import (
"sourcecode.social/reiver/go-erorr"
)
const (
errNilDestination = erorr.Error("rfc8259: nil destination")
errNilRuneScanner = erorr.Error("rfc8259: nil rune-scanner")
errUnexpectedEndOfFile = erorr.Error("rfc8259: unexpected end-of-file")
)
func errProblemReadingRune(err error) error {
return erorr.Errorf("rfc8259: the JSON parser had a problem — problem reading rune: %w", err)
}
func errProblemUnreadingRune(err error, r rune) error {
return erorr.Errorf("rfc8259: the JSON parser had an internal-error — problem unreading rune %q (%U): %w", r, r, err)
}

View File

@ -4,6 +4,8 @@ import (
"io"
"sourcecode.social/reiver/go-erorr"
"sourcecode.social/reiver/go-rfc8259/errors"
)
// Parse tries to parse the JSON whole-number literal.
@ -37,10 +39,10 @@ import (
// fmt.Printf("dst = %#v\n", dst)
func Parse(runescanner io.RuneScanner, dst *WholeNumber) error {
if nil == runescanner {
return errNilRuneScanner
return rfc8259errors.ErrNilRuneScanner
}
if nil == dst {
return errNilDestination
return rfc8259errors.ErrNilDestination
}
var buffer [256]byte
@ -54,9 +56,9 @@ func Parse(runescanner io.RuneScanner, dst *WholeNumber) error {
r, _, err = runescanner.ReadRune()
if nil != err {
if io.EOF == err {
return errUnexpectedEndOfFile
return rfc8259errors.ErrUnexpectedEndOfFile
}
return errProblemReadingRune(err)
return rfc8259errors.ErrProblemReadingRune(err)
}
}
@ -79,7 +81,7 @@ func Parse(runescanner io.RuneScanner, dst *WholeNumber) error {
r, _, err = runescanner.ReadRune()
if nil != err && io.EOF != err {
return errProblemReadingRune(err)
return rfc8259errors.ErrProblemReadingRune(err)
}
if io.EOF == err {
/////////////////////// BREAK
@ -91,7 +93,7 @@ func Parse(runescanner io.RuneScanner, dst *WholeNumber) error {
p = append(p, string(r)...)
default:
if err := runescanner.UnreadRune(); nil != err {
return errProblemUnreadingRune(err, r)
return rfc8259errors.ErrProblemUnreadingRune(err, r)
}
/////////////////////// BREAK
break loop