Merge pull request #299 from hairyhenderson/update-utfbom-dep

textfile collector: updating utfbom dependency and simplifying code
This commit is contained in:
Calle Pettersson 2018-12-12 20:05:44 +01:00 committed by GitHub
commit d58ce114d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 15 deletions

6
Gopkg.lock generated
View File

@ -37,12 +37,12 @@
revision = "4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9"
[[projects]]
digest = "1:ec6271918b59b872a2d25e374569a4f75f1839d91e4191470c297b7eaaaf7641"
digest = "1:f9adc21a937e5da643ea14a3488cb7506788876737a5e205394e508627a6eec8"
name = "github.com/dimchansky/utfbom"
packages = ["."]
pruneopts = "NUT"
revision = "5448fe645cb1964ba70ac8f9f2ffe975e61a536c"
version = "v1.0.0"
revision = "d2133a1ce379ef6fa992b0514a77146c60db9d1c"
version = "v1.1.0"
[[projects]]
digest = "1:cb4e216bd9f58866f42dc65893455b24f879b026fdaa1ecc3aafff625fdb5a66"

View File

@ -288,19 +288,9 @@ fileLoop:
}
func checkBOM(encoding utfbom.Encoding) error {
bom := ""
switch encoding {
case utfbom.Unknown, utfbom.UTF8:
if encoding == utfbom.Unknown || encoding == utfbom.UTF8 {
return nil
case utfbom.UTF16BigEndian:
bom = "UTF16BigEndian"
case utfbom.UTF16LittleEndian:
bom = "UTF16LittleEndian"
case utfbom.UTF32BigEndian:
bom = "UTF32BigEndian"
case utfbom.UTF32LittleEndian:
bom = "UTF32LittleEndian"
}
return fmt.Errorf(bom)
return fmt.Errorf(encoding.String())
}

View File

@ -32,6 +32,24 @@ const (
UTF32LittleEndian
)
// String returns a user-friendly string representation of the encoding. Satisfies fmt.Stringer interface.
func (e Encoding) String() string {
switch e {
case UTF8:
return "UTF8"
case UTF16BigEndian:
return "UTF16BigEndian"
case UTF16LittleEndian:
return "UTF16LittleEndian"
case UTF32BigEndian:
return "UTF32BigEndian"
case UTF32LittleEndian:
return "UTF32LittleEndian"
default:
return "Unknown"
}
}
const maxConsecutiveEmptyReads = 100
// Skip creates Reader which automatically detects BOM (Unicode Byte Order Mark) and removes it as necessary.