Compare commits
No commits in common. "a854dd06189c2e55074e0b7e28fd5619955266de" and "5821510143896ff3abb27208f5893aecaf44fc74" have entirely different histories.
a854dd0618
...
5821510143
53
asv.go
53
asv.go
@ -4,7 +4,6 @@ package asv
|
||||
import "io"
|
||||
import "bufio"
|
||||
import "strings"
|
||||
import "strconv"
|
||||
|
||||
// Collection is composed of Files.
|
||||
type Collection []File
|
||||
@ -17,50 +16,6 @@ type Record []Unit
|
||||
// Unit is an element of a record.
|
||||
type Unit string
|
||||
|
||||
func (collection Collection) String () string {
|
||||
builder := strings.Builder { }
|
||||
builder.WriteString("Collection { ")
|
||||
for index, file := range collection {
|
||||
if index > 0 { builder.WriteString(", ") }
|
||||
builder.WriteString(file.String())
|
||||
}
|
||||
builder.WriteString(" }")
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
func (file File) String () string {
|
||||
builder := strings.Builder { }
|
||||
builder.WriteString("File { ")
|
||||
for index, group := range file {
|
||||
if index > 0 { builder.WriteString(", ") }
|
||||
builder.WriteString(group.String())
|
||||
}
|
||||
builder.WriteString(" }")
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
func (group Group) String () string {
|
||||
builder := strings.Builder { }
|
||||
builder.WriteString("Group { ")
|
||||
for index, record := range group {
|
||||
if index > 0 { builder.WriteString(", ") }
|
||||
builder.WriteString(record.String())
|
||||
}
|
||||
builder.WriteString(" }")
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
func (record Record) String () string {
|
||||
builder := strings.Builder { }
|
||||
builder.WriteString("Record { ")
|
||||
for index, unit := range record {
|
||||
if index > 0 { builder.WriteString(", ") }
|
||||
builder.WriteString(strconv.Quote(string(unit)))
|
||||
}
|
||||
builder.WriteString(" }")
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
const (
|
||||
Escape rune = '\x1B'
|
||||
FileSeparator rune = '\x1C'
|
||||
@ -106,7 +61,7 @@ func (this *Decoder) ReadFile () (file File, next rune, err error) {
|
||||
group, next, err := this.ReadGroup()
|
||||
file = append(file, group)
|
||||
if err != nil { return file, 0, err }
|
||||
if next <= FileSeparator {
|
||||
if next >= FileSeparator {
|
||||
return file, next, nil
|
||||
}
|
||||
}
|
||||
@ -121,7 +76,7 @@ func (this *Decoder) ReadGroup () (group Group, next rune, err error) {
|
||||
record, next, err := this.ReadRecord()
|
||||
group = append(group, record)
|
||||
if err != nil { return group, 0, err }
|
||||
if next <= GroupSeparator {
|
||||
if next >= GroupSeparator {
|
||||
return group, next, nil
|
||||
}
|
||||
}
|
||||
@ -136,7 +91,7 @@ func (this *Decoder) ReadRecord () (record Record, next rune, err error) {
|
||||
unit, next, err := this.ReadUnit()
|
||||
record = append(record, unit)
|
||||
if err != nil { return record, 0, err }
|
||||
if next <= RecordSeparator {
|
||||
if next >= RecordSeparator {
|
||||
return record, next, nil
|
||||
}
|
||||
}
|
||||
@ -158,7 +113,7 @@ func (this *Decoder) ReadUnit () (unit Unit, next rune, err error) {
|
||||
|
||||
if esc {
|
||||
esc = false
|
||||
} else if IsSeparator(char) {
|
||||
} else if char >= FileSeparator && char <= UnitSeparator {
|
||||
return Unit(str.String()), char, nil
|
||||
}
|
||||
str.WriteRune(char)
|
||||
|
Loading…
Reference in New Issue
Block a user