refactor constants
parent
ae739f1281
commit
43b24cd789
16
consts.go
16
consts.go
|
@ -1,16 +0,0 @@
|
|||
package eol
|
||||
|
||||
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.Rune)
|
||||
CR = string(cr.Rune)
|
||||
CRLF = CR+LF
|
||||
NEL = string(nel.Rune)
|
||||
LS = string(ls.Rune)
|
||||
)
|
|
@ -19,6 +19,6 @@ import (
|
|||
// size, err := eol.ReadCR(runescanner)
|
||||
func ReadCR(runescanner io.RuneScanner) (size int, err error) {
|
||||
const characterNumber uint64 = 1
|
||||
var circumstance internalCircumstance = specifyCircumstance(opt.Something(CR), characterNumber)
|
||||
var circumstance internalCircumstance = specifyCircumstance(opt.Something(cr.String), characterNumber)
|
||||
return readthisrune(circumstance, runescanner, cr.Rune)
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"sourcecode.social/reiver/go-opt"
|
||||
|
||||
"sourcecode.social/reiver/go-eol/cr"
|
||||
"sourcecode.social/reiver/go-eol/crlf"
|
||||
"sourcecode.social/reiver/go-eol/lf"
|
||||
)
|
||||
|
||||
|
@ -26,7 +27,7 @@ func ReadCRLF(runescanner io.RuneScanner) (size int, err error) {
|
|||
var err error
|
||||
|
||||
const characterNumber uint64 = 1
|
||||
var circumstance internalCircumstance = specifyCircumstance(opt.Something(CRLF), characterNumber)
|
||||
var circumstance internalCircumstance = specifyCircumstance(opt.Something(crlf.String), characterNumber)
|
||||
size0, err = readthisrune(circumstance, runescanner, cr.Rune)
|
||||
if nil != err {
|
||||
return size0, err
|
||||
|
@ -38,7 +39,7 @@ func ReadCRLF(runescanner io.RuneScanner) (size int, err error) {
|
|||
var err error
|
||||
|
||||
const characterNumber uint64 = 2
|
||||
var circumstance internalCircumstance = specifyCircumstance(opt.Something(CRLF), characterNumber)
|
||||
var circumstance internalCircumstance = specifyCircumstance(opt.Something(crlf.String), characterNumber)
|
||||
size1, err = readthisrune(circumstance, runescanner, lf.Rune)
|
||||
if nil != err {
|
||||
return size1+size0, err
|
||||
|
|
13
readeol.go
13
readeol.go
|
@ -6,6 +6,7 @@ import (
|
|||
"sourcecode.social/reiver/go-opt"
|
||||
|
||||
"sourcecode.social/reiver/go-eol/cr"
|
||||
"sourcecode.social/reiver/go-eol/crlf"
|
||||
"sourcecode.social/reiver/go-eol/lf"
|
||||
"sourcecode.social/reiver/go-eol/ls"
|
||||
"sourcecode.social/reiver/go-eol/nel"
|
||||
|
@ -48,13 +49,13 @@ func ReadEOL(runescanner io.RuneScanner) (endofline string, size int, err error)
|
|||
|
||||
switch r0 {
|
||||
case lf.Rune:
|
||||
return LF, size0, nil
|
||||
return lf.String, size0, nil
|
||||
case cr.Rune:
|
||||
// Nothing here.
|
||||
case nel.Rune:
|
||||
return NEL, size0, nil
|
||||
return nel.String, size0, nil
|
||||
case ls.Rune:
|
||||
return LS, size0, nil
|
||||
return ls.String, size0, nil
|
||||
default:
|
||||
err := runescanner.UnreadRune()
|
||||
if nil != err {
|
||||
|
@ -77,7 +78,7 @@ func ReadEOL(runescanner io.RuneScanner) (endofline string, size int, err error)
|
|||
|
||||
r1, size1, err = runescanner.ReadRune()
|
||||
if io.EOF == err {
|
||||
return CR, size0, nil
|
||||
return cr.String, size0, nil
|
||||
}
|
||||
if nil != err {
|
||||
const characterNumber uint64 = 2
|
||||
|
@ -90,7 +91,7 @@ func ReadEOL(runescanner io.RuneScanner) (endofline string, size int, err error)
|
|||
|
||||
switch r1 {
|
||||
case lf.Rune:
|
||||
return CRLF, size1+size0, nil
|
||||
return crlf.String, size1+size0, nil
|
||||
default:
|
||||
err := runescanner.UnreadRune()
|
||||
if nil != err {
|
||||
|
@ -101,6 +102,6 @@ func ReadEOL(runescanner io.RuneScanner) (endofline string, size int, err error)
|
|||
return "", size1+size0, errProblemUnreadingRune(circumstance, err, r1)
|
||||
}
|
||||
|
||||
return CR, size0, nil
|
||||
return cr.String, size0, nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,11 @@ import (
|
|||
"sourcecode.social/reiver/go-utf8"
|
||||
|
||||
"sourcecode.social/reiver/go-eol"
|
||||
"sourcecode.social/reiver/go-eol/cr"
|
||||
"sourcecode.social/reiver/go-eol/crlf"
|
||||
"sourcecode.social/reiver/go-eol/lf"
|
||||
"sourcecode.social/reiver/go-eol/ls"
|
||||
"sourcecode.social/reiver/go-eol/nel"
|
||||
)
|
||||
|
||||
func TestReadEOL(t *testing.T) {
|
||||
|
@ -20,27 +25,27 @@ func TestReadEOL(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
Value: "\n",
|
||||
ExpectedEOL: eol.LF,
|
||||
ExpectedEOL: lf.String,
|
||||
ExpectedSize: 1,
|
||||
},
|
||||
{
|
||||
Value: "\r",
|
||||
ExpectedEOL: eol.CR,
|
||||
ExpectedEOL: cr.String,
|
||||
ExpectedSize: 1,
|
||||
},
|
||||
{
|
||||
Value: "\r\n",
|
||||
ExpectedEOL: eol.CRLF,
|
||||
ExpectedEOL: crlf.String,
|
||||
ExpectedSize: 2,
|
||||
},
|
||||
{
|
||||
Value: "\u0085",
|
||||
ExpectedEOL: eol.NEL,
|
||||
ExpectedEOL: nel.String,
|
||||
ExpectedSize: 2,
|
||||
},
|
||||
{
|
||||
Value: "\u2028",
|
||||
ExpectedEOL: eol.LS,
|
||||
ExpectedEOL: ls.String,
|
||||
ExpectedSize: 3,
|
||||
},
|
||||
|
||||
|
@ -48,27 +53,27 @@ func TestReadEOL(t *testing.T) {
|
|||
|
||||
{
|
||||
Value: "\napple banana cherry",
|
||||
ExpectedEOL: eol.LF,
|
||||
ExpectedEOL: lf.String,
|
||||
ExpectedSize: 1,
|
||||
},
|
||||
{
|
||||
Value: "\rapple banana cherr",
|
||||
ExpectedEOL: eol.CR,
|
||||
ExpectedEOL: cr.String,
|
||||
ExpectedSize: 1,
|
||||
},
|
||||
{
|
||||
Value: "\r\napple banana cherr",
|
||||
ExpectedEOL: eol.CRLF,
|
||||
ExpectedEOL: crlf.String,
|
||||
ExpectedSize: 2,
|
||||
},
|
||||
{
|
||||
Value: "\u0085apple banana cherr",
|
||||
ExpectedEOL: eol.NEL,
|
||||
ExpectedEOL: nel.String,
|
||||
ExpectedSize: 2,
|
||||
},
|
||||
{
|
||||
Value: "\u2028apple banana cherr",
|
||||
ExpectedEOL: eol.LS,
|
||||
ExpectedEOL: ls.String,
|
||||
ExpectedSize: 3,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -19,6 +19,6 @@ import (
|
|||
// size, err := eol.ReadLF(runescanner)
|
||||
func ReadLF(runescanner io.RuneScanner) (size int, err error) {
|
||||
const characterNumber uint64 = 1
|
||||
var circumstance internalCircumstance = specifyCircumstance(opt.Something(LF), characterNumber)
|
||||
var circumstance internalCircumstance = specifyCircumstance(opt.Something(lf.String), characterNumber)
|
||||
return readthisrune(circumstance, runescanner, lf.Rune)
|
||||
}
|
||||
|
|
|
@ -19,6 +19,6 @@ import (
|
|||
// size, err := eol.ReadLS(runescanner)
|
||||
func ReadLS(runescanner io.RuneScanner) (size int, err error) {
|
||||
const characterNumber uint64 = 1
|
||||
var circumstance internalCircumstance = specifyCircumstance(opt.Something(LS), characterNumber)
|
||||
var circumstance internalCircumstance = specifyCircumstance(opt.Something(ls.String), characterNumber)
|
||||
return readthisrune(circumstance, runescanner, ls.Rune)
|
||||
}
|
||||
|
|
|
@ -19,6 +19,6 @@ import (
|
|||
// size, err := eol.ReadNEL(runescanner)
|
||||
func ReadNEL(runescanner io.RuneScanner) (size int, err error) {
|
||||
const characterNumber uint64 = 1
|
||||
var circumstance internalCircumstance = specifyCircumstance(opt.Something(NEL), characterNumber)
|
||||
var circumstance internalCircumstance = specifyCircumstance(opt.Something(nel.String), characterNumber)
|
||||
return readthisrune(circumstance, runescanner, nel.Rune)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,12 @@ package eol
|
|||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"sourcecode.social/reiver/go-eol/cr"
|
||||
"sourcecode.social/reiver/go-eol/crlf"
|
||||
"sourcecode.social/reiver/go-eol/lf"
|
||||
"sourcecode.social/reiver/go-eol/ls"
|
||||
"sourcecode.social/reiver/go-eol/nel"
|
||||
)
|
||||
|
||||
// ReadThisEOL tries to read the specified end-of-line sequence.
|
||||
|
@ -25,15 +31,15 @@ func ReadThisEOL(runescanner io.RuneScanner, endofline string) (size int, err er
|
|||
}
|
||||
|
||||
switch endofline {
|
||||
case LF:
|
||||
case lf.String:
|
||||
return ReadLF(runescanner)
|
||||
case CR:
|
||||
case cr.String:
|
||||
return ReadCR(runescanner)
|
||||
case CRLF:
|
||||
case crlf.String:
|
||||
return ReadCRLF(runescanner)
|
||||
case NEL:
|
||||
case nel.String:
|
||||
return ReadNEL(runescanner)
|
||||
case LS:
|
||||
case ls.String:
|
||||
return ReadLS(runescanner)
|
||||
default:
|
||||
return 0, errUnrecognizedEOL(endofline)
|
||||
|
|
|
@ -8,6 +8,11 @@ import (
|
|||
|
||||
"sourcecode.social/reiver/go-opt"
|
||||
"sourcecode.social/reiver/go-utf8"
|
||||
|
||||
"sourcecode.social/reiver/go-eol/cr"
|
||||
"sourcecode.social/reiver/go-eol/lf"
|
||||
"sourcecode.social/reiver/go-eol/ls"
|
||||
"sourcecode.social/reiver/go-eol/nel"
|
||||
)
|
||||
|
||||
func TestReadThisRune(t *testing.T) {
|
||||
|
@ -123,28 +128,28 @@ func TestReadThisRune_fail(t *testing.T) {
|
|||
{
|
||||
Value: "",
|
||||
Rune: '\n',
|
||||
EOLSequence: opt.Something(LF),
|
||||
EOLSequence: opt.Something(lf.String),
|
||||
RuneNumber: 7,
|
||||
ExpectedError: `eol: problem reading character №7 of end-of-line sequence "\n": EOF`,
|
||||
},
|
||||
{
|
||||
Value: "",
|
||||
Rune: '\r',
|
||||
EOLSequence: opt.Something(CR),
|
||||
EOLSequence: opt.Something(cr.String),
|
||||
RuneNumber: 8,
|
||||
ExpectedError: `eol: problem reading character №8 of end-of-line sequence "\r": EOF`,
|
||||
},
|
||||
{
|
||||
Value: "",
|
||||
Rune: '\u0085',
|
||||
EOLSequence: opt.Something(NEL),
|
||||
EOLSequence: opt.Something(nel.String),
|
||||
RuneNumber: 9,
|
||||
ExpectedError: `eol: problem reading character №9 of end-of-line sequence "\u0085": EOF`,
|
||||
},
|
||||
{
|
||||
Value: "",
|
||||
Rune: '\u2028',
|
||||
EOLSequence: opt.Something(LS),
|
||||
EOLSequence: opt.Something(ls.String),
|
||||
RuneNumber: 10,
|
||||
ExpectedError: `eol: problem reading character №10 of end-of-line sequence "\u2028": EOF`,
|
||||
},
|
||||
|
@ -164,28 +169,28 @@ func TestReadThisRune_fail(t *testing.T) {
|
|||
{
|
||||
Value: " \n",
|
||||
Rune: '\n',
|
||||
EOLSequence: opt.Something(LF),
|
||||
EOLSequence: opt.Something(lf.String),
|
||||
RuneNumber: 12,
|
||||
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line sequence "\n" character №12 — instead found ' ' (U+0020)`,
|
||||
},
|
||||
{
|
||||
Value: " \r",
|
||||
Rune: '\r',
|
||||
EOLSequence: opt.Something(CR),
|
||||
EOLSequence: opt.Something(cr.String),
|
||||
RuneNumber: 13,
|
||||
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line sequence "\r" character №13 — instead found ' ' (U+0020)`,
|
||||
},
|
||||
{
|
||||
Value: " \u0085",
|
||||
Rune: '\u0085',
|
||||
EOLSequence: opt.Something(NEL),
|
||||
EOLSequence: opt.Something(nel.String),
|
||||
RuneNumber: 14,
|
||||
ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line sequence "\u0085" character №14 — instead found ' ' (U+0020)`,
|
||||
},
|
||||
{
|
||||
Value: " \u2028",
|
||||
Rune: '\u2028',
|
||||
EOLSequence: opt.Something(LS),
|
||||
EOLSequence: opt.Something(ls.String),
|
||||
RuneNumber: 15,
|
||||
ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line sequence "\u2028" character №15 — instead found ' ' (U+0020)`,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue