From 9e53c5a034fa2823b52e30bd3be1592e2c233b1b Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Sun, 18 Feb 2024 09:09:29 -0800 Subject: [PATCH] refactor constants --- consts.go | 18 +++++++++--------- cr/rune.go | 4 +--- lf/rune.go | 4 +--- ls/rune.go | 4 +--- nel/rune.go | 4 +--- notfound.go | 13 +++++++++---- readcr.go | 4 +++- readcrlf.go | 7 +++++-- readeol.go | 15 ++++++++++----- readlf.go | 4 +++- readls.go | 4 +++- readnel.go | 4 +++- 12 files changed, 49 insertions(+), 36 deletions(-) diff --git a/consts.go b/consts.go index 0e4aeda..9d8d375 100644 --- a/consts.go +++ b/consts.go @@ -1,16 +1,16 @@ package eol -const ( - lf = '\u000A' - cr = '\u000D' - nel = '\u0085' - ls = '\u2028' +import ( + "sourcecode.social/reiver/go-eol/cr" + "sourcecode.social/reiver/go-eol/lf" + "sourcecode.social/reiver/go-eol/ls" + "sourcecode.social/reiver/go-eol/nel" ) const ( - LF = string(lf) - CR = string(cr) + LF = string(lf.Rune) + CR = string(cr.Rune) CRLF = CR+LF - NEL = string(nel) - LS = string(ls) + NEL = string(nel.Rune) + LS = string(ls.Rune) ) diff --git a/cr/rune.go b/cr/rune.go index 49c278c..fa0b68d 100644 --- a/cr/rune.go +++ b/cr/rune.go @@ -1,5 +1,3 @@ package cr -const ( - CR = '\u000D' -) +const Rune rune = '\u000D' diff --git a/lf/rune.go b/lf/rune.go index 952ce68..23ad5c5 100644 --- a/lf/rune.go +++ b/lf/rune.go @@ -1,5 +1,3 @@ package lf -const ( - LF = '\u000A' -) +const Rune = '\u000A' diff --git a/ls/rune.go b/ls/rune.go index 4e713dd..d2c0ebb 100644 --- a/ls/rune.go +++ b/ls/rune.go @@ -1,5 +1,3 @@ package ls -const ( - lS = '\u2028' -) +const Rune = '\u2028' diff --git a/nel/rune.go b/nel/rune.go index eff2947..8493755 100644 --- a/nel/rune.go +++ b/nel/rune.go @@ -1,5 +1,3 @@ package nel -const ( - NEL = '\u0085' -) +const Rune = '\u0085' diff --git a/notfound.go b/notfound.go index dea9a59..863bc97 100644 --- a/notfound.go +++ b/notfound.go @@ -4,6 +4,11 @@ import ( "fmt" "sourcecode.social/reiver/go-opt" + + "sourcecode.social/reiver/go-eol/cr" + "sourcecode.social/reiver/go-eol/lf" + "sourcecode.social/reiver/go-eol/ls" + "sourcecode.social/reiver/go-eol/nel" ) var _ error = internalNotFoundError{} @@ -35,25 +40,25 @@ func (receiver internalNotFoundError) Error() string { var eolSequence opt.Optional[string] = receiver.circumstance.EOLSequence() switch expected { - case lf: + case lf.Rune: 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: + case cr.Rune: 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: + case nel.Rune: 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: + case ls.Rune: 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) diff --git a/readcr.go b/readcr.go index dfdfa43..e160713 100644 --- a/readcr.go +++ b/readcr.go @@ -4,6 +4,8 @@ import ( "io" "sourcecode.social/reiver/go-opt" + + "sourcecode.social/reiver/go-eol/cr" ) // ReadCR tries to read the "\r" (i.e., carriage-return) end-of-line sequence. @@ -18,5 +20,5 @@ import ( func ReadCR(runescanner io.RuneScanner) (size int, err error) { const characterNumber uint64 = 1 var circumstance internalCircumstance = specifyCircumstance(opt.Something(CR), characterNumber) - return readthisrune(circumstance, runescanner, cr) + return readthisrune(circumstance, runescanner, cr.Rune) } diff --git a/readcrlf.go b/readcrlf.go index aae876e..1d09cf7 100644 --- a/readcrlf.go +++ b/readcrlf.go @@ -4,6 +4,9 @@ import ( "io" "sourcecode.social/reiver/go-opt" + + "sourcecode.social/reiver/go-eol/cr" + "sourcecode.social/reiver/go-eol/lf" ) // ReadCRLF tries to read the "\r\n" (i.e., carriage-return line-feed) end-of-line sequence. @@ -24,7 +27,7 @@ func ReadCRLF(runescanner io.RuneScanner) (size int, err error) { const characterNumber uint64 = 1 var circumstance internalCircumstance = specifyCircumstance(opt.Something(CRLF), characterNumber) - size0, err = readthisrune(circumstance, runescanner, cr) + size0, err = readthisrune(circumstance, runescanner, cr.Rune) if nil != err { return size0, err } @@ -36,7 +39,7 @@ func ReadCRLF(runescanner io.RuneScanner) (size int, err error) { const characterNumber uint64 = 2 var circumstance internalCircumstance = specifyCircumstance(opt.Something(CRLF), characterNumber) - size1, err = readthisrune(circumstance, runescanner, lf) + size1, err = readthisrune(circumstance, runescanner, lf.Rune) if nil != err { return size1+size0, err } diff --git a/readeol.go b/readeol.go index d6eeabc..a8fbd40 100644 --- a/readeol.go +++ b/readeol.go @@ -4,6 +4,11 @@ import ( "io" "sourcecode.social/reiver/go-opt" + + "sourcecode.social/reiver/go-eol/cr" + "sourcecode.social/reiver/go-eol/lf" + "sourcecode.social/reiver/go-eol/ls" + "sourcecode.social/reiver/go-eol/nel" ) // ReadEOL tries to read an end-of-line sequence. @@ -42,13 +47,13 @@ func ReadEOL(runescanner io.RuneScanner) (endofline string, size int, err error) } switch r0 { - case lf: + case lf.Rune: return LF, size0, nil - case cr: + case cr.Rune: // Nothing here. - case nel: + case nel.Rune: return NEL, size0, nil - case ls: + case ls.Rune: return LS, size0, nil default: err := runescanner.UnreadRune() @@ -84,7 +89,7 @@ func ReadEOL(runescanner io.RuneScanner) (endofline string, size int, err error) } switch r1 { - case lf: + case lf.Rune: return CRLF, size1+size0, nil default: err := runescanner.UnreadRune() diff --git a/readlf.go b/readlf.go index cf4760f..4cdb3a2 100644 --- a/readlf.go +++ b/readlf.go @@ -4,6 +4,8 @@ import ( "io" "sourcecode.social/reiver/go-opt" + + "sourcecode.social/reiver/go-eol/lf" ) // ReadLF tries to read the "\n" (i.e., line-feed) end-of-line sequence. @@ -18,5 +20,5 @@ import ( func ReadLF(runescanner io.RuneScanner) (size int, err error) { const characterNumber uint64 = 1 var circumstance internalCircumstance = specifyCircumstance(opt.Something(LF), characterNumber) - return readthisrune(circumstance, runescanner, lf) + return readthisrune(circumstance, runescanner, lf.Rune) } diff --git a/readls.go b/readls.go index f862b4d..ad6d462 100644 --- a/readls.go +++ b/readls.go @@ -4,6 +4,8 @@ import ( "io" "sourcecode.social/reiver/go-opt" + + "sourcecode.social/reiver/go-eol/ls" ) // ReadLS tries to read the "\u2028" (i.e., line-separator) end-of-line sequence. @@ -18,5 +20,5 @@ import ( func ReadLS(runescanner io.RuneScanner) (size int, err error) { const characterNumber uint64 = 1 var circumstance internalCircumstance = specifyCircumstance(opt.Something(LS), characterNumber) - return readthisrune(circumstance, runescanner, ls) + return readthisrune(circumstance, runescanner, ls.Rune) } diff --git a/readnel.go b/readnel.go index 80df7bf..0791a6e 100644 --- a/readnel.go +++ b/readnel.go @@ -4,6 +4,8 @@ import ( "io" "sourcecode.social/reiver/go-opt" + + "sourcecode.social/reiver/go-eol/nel" ) // ReadNEL tries to read the "\u0085" (i.e., next-line) end-of-line sequence. @@ -18,5 +20,5 @@ import ( func ReadNEL(runescanner io.RuneScanner) (size int, err error) { const characterNumber uint64 = 1 var circumstance internalCircumstance = specifyCircumstance(opt.Something(NEL), characterNumber) - return readthisrune(circumstance, runescanner, nel) + return readthisrune(circumstance, runescanner, nel.Rune) }