From 9d5e4af6b2585d1305dc1a113d12f0e373802da5 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Tue, 28 Nov 2023 08:04:21 -0800 Subject: [PATCH] initial commits --- notfound.go | 40 +++++++++++++++++++++++++++++++++------- problemreadingrune.go | 16 +++++++++++----- problemunreadingrune.go | 16 +++++++++++----- 3 files changed, 55 insertions(+), 17 deletions(-) diff --git a/notfound.go b/notfound.go index 3950c35..dea9a59 100644 --- a/notfound.go +++ b/notfound.go @@ -2,6 +2,8 @@ package eol import ( "fmt" + + "sourcecode.social/reiver/go-opt" ) var _ error = internalNotFoundError{} @@ -9,7 +11,15 @@ var _ error = internalNotFoundError{} type internalNotFoundError struct{ expected rune actual rune - characterNumber uint64 + circumstance internalCircumstance +} + +func errNotFound(circumstance internalCircumstance, expected rune, actual rune) error { + return internalNotFoundError { + expected:expected, + actual:actual, + circumstance:circumstance, + } } func (receiver internalNotFoundError) Error() string { @@ -21,23 +31,39 @@ func (receiver internalNotFoundError) Error() string { var expected rune = receiver.expected var actual rune = receiver.actual - var characterNumber uint64 = receiver.characterNumber + var characterNumber uint64 = receiver.circumstance.CharacterNumber() + var eolSequence opt.Optional[string] = receiver.circumstance.EOLSequence() switch expected { case lf: - var s string = fmt.Sprintf(`eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №%d — instead found %q (%U)`, characterNumber, actual, actual) + 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) + }) p = append(p, s...) case cr: - var s string = fmt.Sprintf(`eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №%d — instead found %q (%U)`, characterNumber, actual, actual) + 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) + }) p = append(p, s...) case nel: - var s string = fmt.Sprintf(`eol: next-line (NEL) character (U+0085) not found for end-of-line character №%d — instead found %q (%U)`, characterNumber, actual, actual) + 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) + }) p = append(p, s...) case ls: - var s string = fmt.Sprintf(`eol: line-separator (LS) character (U+2028) not found for end-of-line character №%d — instead found %q (%U)`, characterNumber, actual, actual) + 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) + }) p = append(p, s...) default: - var s string = fmt.Sprintf(`eol: %q character (%U) not found for character №%d — instead found %q (%U)`, expected, expected, characterNumber, actual, actual) + 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) + }) p = append(p, s...) } diff --git a/problemreadingrune.go b/problemreadingrune.go index aebf498..0dca87d 100644 --- a/problemreadingrune.go +++ b/problemreadingrune.go @@ -6,23 +6,29 @@ import ( var _ error = internalProblemReadingRuneError{} -func errProblemReadingRune(err error, runeNumber uint64) error { +func errProblemReadingRune(circumstance internalCircumstance, err error) error { return internalProblemReadingRuneError{ err:err, - runeNumber:runeNumber, + circumstance:circumstance, } } type internalProblemReadingRuneError struct { err error - runeNumber uint64 + circumstance internalCircumstance } func (receiver internalProblemReadingRuneError) Error() string { err := receiver.err - runeNumber := receiver.runeNumber + characterNumber := receiver.circumstance.CharacterNumber() + eolSequence := receiver.circumstance.EOLSequence() - return fmt.Sprintf("eol: problem reading character №%d of end-of-line sequence: %s", runeNumber, err) + var s string = fmt.Sprintf("eol: problem reading character №%d of end-of-line sequence: %s", characterNumber, err) + eolSequence.WhenSomething(func(sequence string){ + s = fmt.Sprintf("eol: problem reading character №%d of end-of-line sequence %q: %s", characterNumber, sequence, err) + }) + + return s } func (receiver internalProblemReadingRuneError) Unwrap() error { diff --git a/problemunreadingrune.go b/problemunreadingrune.go index 12a2354..e049934 100644 --- a/problemunreadingrune.go +++ b/problemunreadingrune.go @@ -6,26 +6,32 @@ import ( var _ error = internalProblemUnreadingRuneError{} -func errProblemUnreadingRune(err error, runeNumber uint64, r rune) error { +func errProblemUnreadingRune(circumstance internalCircumstance, err error, r rune) error { return internalProblemUnreadingRuneError{ err:err, - runeNumber:runeNumber, r:r, + circumstance:circumstance, } } type internalProblemUnreadingRuneError struct { err error - runeNumber uint64 r rune + circumstance internalCircumstance } func (receiver internalProblemUnreadingRuneError) Error() string { err := receiver.err - runeNumber := receiver.runeNumber r := receiver.r + characterNumber := receiver.circumstance.CharacterNumber() + eolSequence := receiver.circumstance.EOLSequence() - return fmt.Sprintf("eol: problem unreading character №%d (%q (%U)) of end-of-line sequence: %s", runeNumber, r, r, err) + var s string = fmt.Sprintf("eol: problem unreading character №%d (%q (%U)) of end-of-line sequence: %s", characterNumber, r, r, err) + eolSequence.WhenSomething(func(sequence string){ + s = fmt.Sprintf("eol: problem unreading character №%d (%q (%U)) of end-of-line sequence %q: %s", characterNumber, r, r, sequence, err) + }) + + return s } func (receiver internalProblemUnreadingRuneError) Unwrap() error {