refactor constants

master
Charles Iliya Krempeaux 2024-02-18 09:09:29 -08:00
parent 0862513ec1
commit 9e53c5a034
12 changed files with 49 additions and 36 deletions

View File

@ -1,16 +1,16 @@
package eol package eol
const ( import (
lf = '\u000A' "sourcecode.social/reiver/go-eol/cr"
cr = '\u000D' "sourcecode.social/reiver/go-eol/lf"
nel = '\u0085' "sourcecode.social/reiver/go-eol/ls"
ls = '\u2028' "sourcecode.social/reiver/go-eol/nel"
) )
const ( const (
LF = string(lf) LF = string(lf.Rune)
CR = string(cr) CR = string(cr.Rune)
CRLF = CR+LF CRLF = CR+LF
NEL = string(nel) NEL = string(nel.Rune)
LS = string(ls) LS = string(ls.Rune)
) )

View File

@ -1,5 +1,3 @@
package cr package cr
const ( const Rune rune = '\u000D'
CR = '\u000D'
)

View File

@ -1,5 +1,3 @@
package lf package lf
const ( const Rune = '\u000A'
LF = '\u000A'
)

View File

@ -1,5 +1,3 @@
package ls package ls
const ( const Rune = '\u2028'
lS = '\u2028'
)

View File

@ -1,5 +1,3 @@
package nel package nel
const ( const Rune = '\u0085'
NEL = '\u0085'
)

View File

@ -4,6 +4,11 @@ import (
"fmt" "fmt"
"sourcecode.social/reiver/go-opt" "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{} var _ error = internalNotFoundError{}
@ -35,25 +40,25 @@ func (receiver internalNotFoundError) Error() string {
var eolSequence opt.Optional[string] = receiver.circumstance.EOLSequence() var eolSequence opt.Optional[string] = receiver.circumstance.EOLSequence()
switch expected { 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) 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){ 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) 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...) 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) 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){ 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) 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...) 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) 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){ 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) 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...) 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) 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){ 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) 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)

View File

@ -4,6 +4,8 @@ import (
"io" "io"
"sourcecode.social/reiver/go-opt" "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. // 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) { func ReadCR(runescanner io.RuneScanner) (size int, err error) {
const characterNumber uint64 = 1 const characterNumber uint64 = 1
var circumstance internalCircumstance = specifyCircumstance(opt.Something(CR), characterNumber) var circumstance internalCircumstance = specifyCircumstance(opt.Something(CR), characterNumber)
return readthisrune(circumstance, runescanner, cr) return readthisrune(circumstance, runescanner, cr.Rune)
} }

View File

@ -4,6 +4,9 @@ import (
"io" "io"
"sourcecode.social/reiver/go-opt" "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. // 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 const characterNumber uint64 = 1
var circumstance internalCircumstance = specifyCircumstance(opt.Something(CRLF), characterNumber) var circumstance internalCircumstance = specifyCircumstance(opt.Something(CRLF), characterNumber)
size0, err = readthisrune(circumstance, runescanner, cr) size0, err = readthisrune(circumstance, runescanner, cr.Rune)
if nil != err { if nil != err {
return size0, err return size0, err
} }
@ -36,7 +39,7 @@ func ReadCRLF(runescanner io.RuneScanner) (size int, err error) {
const characterNumber uint64 = 2 const characterNumber uint64 = 2
var circumstance internalCircumstance = specifyCircumstance(opt.Something(CRLF), characterNumber) var circumstance internalCircumstance = specifyCircumstance(opt.Something(CRLF), characterNumber)
size1, err = readthisrune(circumstance, runescanner, lf) size1, err = readthisrune(circumstance, runescanner, lf.Rune)
if nil != err { if nil != err {
return size1+size0, err return size1+size0, err
} }

View File

@ -4,6 +4,11 @@ import (
"io" "io"
"sourcecode.social/reiver/go-opt" "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. // 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 { switch r0 {
case lf: case lf.Rune:
return LF, size0, nil return LF, size0, nil
case cr: case cr.Rune:
// Nothing here. // Nothing here.
case nel: case nel.Rune:
return NEL, size0, nil return NEL, size0, nil
case ls: case ls.Rune:
return LS, size0, nil return LS, size0, nil
default: default:
err := runescanner.UnreadRune() err := runescanner.UnreadRune()
@ -84,7 +89,7 @@ func ReadEOL(runescanner io.RuneScanner) (endofline string, size int, err error)
} }
switch r1 { switch r1 {
case lf: case lf.Rune:
return CRLF, size1+size0, nil return CRLF, size1+size0, nil
default: default:
err := runescanner.UnreadRune() err := runescanner.UnreadRune()

View File

@ -4,6 +4,8 @@ import (
"io" "io"
"sourcecode.social/reiver/go-opt" "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. // 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) { func ReadLF(runescanner io.RuneScanner) (size int, err error) {
const characterNumber uint64 = 1 const characterNumber uint64 = 1
var circumstance internalCircumstance = specifyCircumstance(opt.Something(LF), characterNumber) var circumstance internalCircumstance = specifyCircumstance(opt.Something(LF), characterNumber)
return readthisrune(circumstance, runescanner, lf) return readthisrune(circumstance, runescanner, lf.Rune)
} }

View File

@ -4,6 +4,8 @@ import (
"io" "io"
"sourcecode.social/reiver/go-opt" "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. // 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) { func ReadLS(runescanner io.RuneScanner) (size int, err error) {
const characterNumber uint64 = 1 const characterNumber uint64 = 1
var circumstance internalCircumstance = specifyCircumstance(opt.Something(LS), characterNumber) var circumstance internalCircumstance = specifyCircumstance(opt.Something(LS), characterNumber)
return readthisrune(circumstance, runescanner, ls) return readthisrune(circumstance, runescanner, ls.Rune)
} }

View File

@ -4,6 +4,8 @@ import (
"io" "io"
"sourcecode.social/reiver/go-opt" "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. // 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) { func ReadNEL(runescanner io.RuneScanner) (size int, err error) {
const characterNumber uint64 = 1 const characterNumber uint64 = 1
var circumstance internalCircumstance = specifyCircumstance(opt.Something(NEL), characterNumber) var circumstance internalCircumstance = specifyCircumstance(opt.Something(NEL), characterNumber)
return readthisrune(circumstance, runescanner, nel) return readthisrune(circumstance, runescanner, nel.Rune)
} }