go-eol/notfound.go

80 lines
3.2 KiB
Go
Raw Normal View History

2023-11-27 19:32:08 +00:00
package eol
import (
"fmt"
2023-11-28 16:04:21 +00:00
"sourcecode.social/reiver/go-opt"
2023-11-27 19:32:08 +00:00
)
var _ error = internalNotFoundError{}
type internalNotFoundError struct{
expected rune
actual rune
2023-11-28 16:04:21 +00:00
circumstance internalCircumstance
}
func errNotFound(circumstance internalCircumstance, expected rune, actual rune) error {
return internalNotFoundError {
expected:expected,
actual:actual,
circumstance:circumstance,
}
2023-11-27 19:32:08 +00:00
}
func (receiver internalNotFoundError) Error() string {
var buffer [256]byte
var p []byte = buffer[0:0]
var expected rune = receiver.expected
var actual rune = receiver.actual
2023-11-28 16:04:21 +00:00
var characterNumber uint64 = receiver.circumstance.CharacterNumber()
var eolSequence opt.Optional[string] = receiver.circumstance.EOLSequence()
2023-11-28 14:26:36 +00:00
2023-11-27 19:32:08 +00:00
switch expected {
case lf:
2023-11-28 16:04:21 +00:00
var s string = fmt.Sprintf(`eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line sequence character №%d — instead found %q (%U)`, characterNumber, actual, actual)
eolSequence.WhenSomething(func(sequence string){
s = fmt.Sprintf(`eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line sequence %q character №%d — instead found %q (%U)`, sequence, characterNumber, actual, actual)
})
2023-11-27 19:32:08 +00:00
p = append(p, s...)
case cr:
2023-11-28 16:04:21 +00:00
var s string = fmt.Sprintf(`eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line sequence character №%d — instead found %q (%U)`, characterNumber, actual, actual)
eolSequence.WhenSomething(func(sequence string){
s = fmt.Sprintf(`eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line sequence %q character №%d — instead found %q (%U)`, sequence, characterNumber, actual, actual)
})
2023-11-27 19:32:08 +00:00
p = append(p, s...)
case nel:
2023-11-28 16:04:21 +00:00
var s string = fmt.Sprintf(`eol: next-line (NEL) character (U+0085) not found for end-of-line sequence character №%d — instead found %q (%U)`, characterNumber, actual, actual)
eolSequence.WhenSomething(func(sequence string){
s = fmt.Sprintf(`eol: next-line (NEL) character (U+0085) not found for end-of-line sequence %q character №%d — instead found %q (%U)`, sequence, characterNumber, actual, actual)
})
2023-11-27 19:32:08 +00:00
p = append(p, s...)
case ls:
2023-11-28 16:04:21 +00:00
var s string = fmt.Sprintf(`eol: line-separator (LS) character (U+2028) not found for end-of-line sequence character №%d — instead found %q (%U)`, characterNumber, actual, actual)
eolSequence.WhenSomething(func(sequence string){
s = fmt.Sprintf(`eol: line-separator (LS) character (U+2028) not found for end-of-line sequence %q character №%d — instead found %q (%U)`, sequence, characterNumber, actual, actual)
})
2023-11-27 19:32:08 +00:00
p = append(p, s...)
default:
2023-11-28 16:04:21 +00:00
var s string = fmt.Sprintf(`eol: %q character (%U) not found for sequence character №%d — instead found %q (%U)`, expected, expected, characterNumber, actual, actual)
eolSequence.WhenSomething(func(sequence string){
s = fmt.Sprintf(`eol: %q character (%U) not found for sequence %q character №%d — instead found %q (%U)`, expected, expected, sequence, characterNumber, actual, actual)
})
2023-11-27 19:32:08 +00:00
p = append(p, s...)
}
return string(p)
}
func (receiver internalNotFoundError) Actual() rune {
return receiver.actual
}
func (receiver internalNotFoundError) Expected() rune {
return receiver.expected
}