go-eol/notfound.go

92 lines
3.9 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"
2024-02-18 17:09:29 +00:00
"sourcecode.social/reiver/go-eol/cr"
"sourcecode.social/reiver/go-eol/lf"
"sourcecode.social/reiver/go-eol/ls"
"sourcecode.social/reiver/go-eol/nel"
2024-03-26 06:05:26 +00:00
"sourcecode.social/reiver/go-eol/vt"
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 {
2024-02-18 17:09:29 +00:00
case lf.Rune:
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...)
2024-03-26 06:05:26 +00:00
case vt.Rune:
var s string = fmt.Sprintf(`eol: vertical-tab (VT) character ('\v') (U+000B) 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: vertical-tab (VT) character ('\v') (U+000B) not found for end-of-line sequence %q character №%d — instead found %q (%U)`, sequence, characterNumber, actual, actual)
})
p = append(p, s...)
2024-02-18 17:09:29 +00:00
case cr.Rune:
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...)
2024-02-18 17:09:29 +00:00
case nel.Rune:
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...)
2024-02-18 17:09:29 +00:00
case ls.Rune:
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
}