2023-11-03 23:21:12 +00:00
package rfc8259boolean
2023-11-03 21:00:32 +00:00
import (
"io"
"sourcecode.social/reiver/go-erorr"
2023-11-05 07:16:31 +00:00
"sourcecode.social/reiver/go-rfc8259/errors"
2023-11-03 21:00:32 +00:00
)
func errProblemParsingBooleanFalse ( expected rune , actual rune ) error {
return erorr . Errorf ( "rfc8259: problem when trying to parse JSON boolean literal 'false' — expected a %q (%U) but actually got a %q (%U)" , expected , expected , actual , actual )
}
// ParseFalse tries to parse the JSON boolean literal 'false'.
// If it succeeds, then it return nil.
// If it failed, it returns an error.
//
// Example usage:
//
2023-11-05 07:16:31 +00:00
// var runescanner io.RuneScanner
2023-11-03 21:00:32 +00:00
//
// // ...
//
2023-11-05 07:16:31 +00:00
// err := rfc8259.ParseFalse(runescanner)
2023-11-03 21:00:32 +00:00
//
// if nil != err {
// fmt.Printf("We did NOT have a 'false', but instead got the error: %s\n", err)
// } else {
// fmt.Print("We had a 'false'\n")
// }
2023-11-05 07:16:31 +00:00
func parseFalse ( runescanner io . RuneScanner ) error {
if nil == runescanner {
return rfc8259errors . ErrNilRuneScanner
2023-11-03 21:00:32 +00:00
}
{
const expected rune = 'f'
2023-11-05 07:16:31 +00:00
r , _ , err := runescanner . ReadRune ( )
2023-11-03 21:00:32 +00:00
if nil != err {
if io . EOF == err {
2023-11-05 07:16:31 +00:00
return rfc8259errors . ErrUnexpectedEndOfFile
2023-11-03 21:00:32 +00:00
}
2023-11-05 07:16:31 +00:00
return rfc8259errors . ErrProblemReadingRune ( err )
2023-11-03 21:00:32 +00:00
}
if expected != r {
return errProblemParsingBooleanFalse ( expected , r )
}
}
{
const expected rune = 'a'
2023-11-05 07:16:31 +00:00
r , _ , err := runescanner . ReadRune ( )
2023-11-03 21:00:32 +00:00
if nil != err {
if io . EOF == err {
2023-11-05 07:16:31 +00:00
return rfc8259errors . ErrUnexpectedEndOfFile
2023-11-03 21:00:32 +00:00
}
2023-11-05 07:16:31 +00:00
return rfc8259errors . ErrProblemReadingRune ( err )
2023-11-03 21:00:32 +00:00
}
if expected != r {
return errProblemParsingBooleanFalse ( expected , r )
}
}
{
const expected rune = 'l'
2023-11-05 07:16:31 +00:00
r , _ , err := runescanner . ReadRune ( )
2023-11-03 21:00:32 +00:00
if nil != err {
if io . EOF == err {
2023-11-05 07:16:31 +00:00
return rfc8259errors . ErrUnexpectedEndOfFile
2023-11-03 21:00:32 +00:00
}
2023-11-05 07:16:31 +00:00
return rfc8259errors . ErrProblemReadingRune ( err )
2023-11-03 21:00:32 +00:00
}
if expected != r {
return errProblemParsingBooleanFalse ( expected , r )
}
}
{
const expected rune = 's'
2023-11-05 07:16:31 +00:00
r , _ , err := runescanner . ReadRune ( )
2023-11-03 21:00:32 +00:00
if nil != err {
if io . EOF == err {
2023-11-05 07:16:31 +00:00
return rfc8259errors . ErrUnexpectedEndOfFile
2023-11-03 21:00:32 +00:00
}
2023-11-05 07:16:31 +00:00
return rfc8259errors . ErrProblemReadingRune ( err )
2023-11-03 21:00:32 +00:00
}
if expected != r {
return errProblemParsingBooleanFalse ( expected , r )
}
}
{
const expected rune = 'e'
2023-11-05 07:16:31 +00:00
r , _ , err := runescanner . ReadRune ( )
2023-11-03 21:00:32 +00:00
if nil != err {
if io . EOF == err {
2023-11-05 07:16:31 +00:00
return rfc8259errors . ErrUnexpectedEndOfFile
2023-11-03 21:00:32 +00:00
}
2023-11-05 07:16:31 +00:00
return rfc8259errors . ErrProblemReadingRune ( err )
2023-11-03 21:00:32 +00:00
}
if expected != r {
return errProblemParsingBooleanFalse ( expected , r )
}
}
return nil
}