Do not export the scanner type
It is an internal specific to parse list responses.
This commit is contained in:
parent
68918a8852
commit
602886c6b8
2
parse.go
2
parse.go
@ -72,7 +72,7 @@ func parseLsListLine(line string) (*Entry, error) {
|
||||
return nil, errUnsupportedListLine
|
||||
}
|
||||
|
||||
scanner := NewScanner(line)
|
||||
scanner := newScanner(line)
|
||||
fields := scanner.NextFields(6)
|
||||
|
||||
if len(fields) < 6 {
|
||||
|
16
scanner.go
16
scanner.go
@ -1,20 +1,20 @@
|
||||
package ftp
|
||||
|
||||
// A Scanner for fields delimited by one or more whitespace characters
|
||||
type Scanner struct {
|
||||
// A scanner for fields delimited by one or more whitespace characters
|
||||
type scanner struct {
|
||||
bytes []byte
|
||||
position int
|
||||
}
|
||||
|
||||
// NewScanner creates a new Scanner
|
||||
func NewScanner(str string) *Scanner {
|
||||
return &Scanner{
|
||||
// newScanner creates a new scanner
|
||||
func newScanner(str string) *scanner {
|
||||
return &scanner{
|
||||
bytes: []byte(str),
|
||||
}
|
||||
}
|
||||
|
||||
// NextFields returns the next `count` fields
|
||||
func (s *Scanner) NextFields(count int) []string {
|
||||
func (s *scanner) NextFields(count int) []string {
|
||||
fields := make([]string, 0, count)
|
||||
for i := 0; i < count; i++ {
|
||||
if field := s.Next(); field != "" {
|
||||
@ -27,7 +27,7 @@ func (s *Scanner) NextFields(count int) []string {
|
||||
}
|
||||
|
||||
// Next returns the next field
|
||||
func (s *Scanner) Next() string {
|
||||
func (s *scanner) Next() string {
|
||||
sLen := len(s.bytes)
|
||||
|
||||
// skip trailing whitespace
|
||||
@ -53,6 +53,6 @@ func (s *Scanner) Next() string {
|
||||
}
|
||||
|
||||
// Remaining returns the remaining string
|
||||
func (s *Scanner) Remaining() string {
|
||||
func (s *scanner) Remaining() string {
|
||||
return string(s.bytes[s.position:len(s.bytes)])
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import "github.com/stretchr/testify/assert"
|
||||
func TestScanner(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
s := NewScanner("foo bar x y")
|
||||
s := newScanner("foo bar x y")
|
||||
assert.Equal("foo", s.Next())
|
||||
assert.Equal(" bar x y", s.Remaining())
|
||||
assert.Equal("bar", s.Next())
|
||||
@ -21,7 +21,7 @@ func TestScanner(t *testing.T) {
|
||||
func TestScannerEmpty(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
s := NewScanner("")
|
||||
s := newScanner("")
|
||||
assert.Equal("", s.Next())
|
||||
assert.Equal("", s.Next())
|
||||
assert.Equal("", s.Remaining())
|
||||
|
Loading…
Reference in New Issue
Block a user