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
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)
)

View File

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

View File

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

View File

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

View File

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

View File

@ -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)

View File

@ -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)
}

View File

@ -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
}

View File

@ -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()

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}