From d40fa44b46c6a2a6ec81744daa905f865b47bbe1 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Sun, 5 Nov 2023 00:01:55 -0700 Subject: [PATCH] initial commits --- wholenumber/errors.go | 19 ------------------- wholenumber/parse.go | 14 ++++++++------ 2 files changed, 8 insertions(+), 25 deletions(-) delete mode 100644 wholenumber/errors.go diff --git a/wholenumber/errors.go b/wholenumber/errors.go deleted file mode 100644 index 4b65240..0000000 --- a/wholenumber/errors.go +++ /dev/null @@ -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) -} diff --git a/wholenumber/parse.go b/wholenumber/parse.go index 33dd2e2..f3ef4eb 100644 --- a/wholenumber/parse.go +++ b/wholenumber/parse.go @@ -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