Do not export the scanner type

It is an internal specific to parse list responses.
This commit is contained in:
Julien Laffaye 2017-03-04 13:01:41 +01:00
parent 68918a8852
commit 602886c6b8
3 changed files with 11 additions and 11 deletions

View File

@ -72,7 +72,7 @@ func parseLsListLine(line string) (*Entry, error) {
return nil, errUnsupportedListLine return nil, errUnsupportedListLine
} }
scanner := NewScanner(line) scanner := newScanner(line)
fields := scanner.NextFields(6) fields := scanner.NextFields(6)
if len(fields) < 6 { if len(fields) < 6 {

View File

@ -1,20 +1,20 @@
package ftp package ftp
// A Scanner for fields delimited by one or more whitespace characters // A scanner for fields delimited by one or more whitespace characters
type Scanner struct { type scanner struct {
bytes []byte bytes []byte
position int position int
} }
// NewScanner creates a new Scanner // newScanner creates a new scanner
func NewScanner(str string) *Scanner { func newScanner(str string) *scanner {
return &Scanner{ return &scanner{
bytes: []byte(str), bytes: []byte(str),
} }
} }
// NextFields returns the next `count` fields // 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) fields := make([]string, 0, count)
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
if field := s.Next(); field != "" { if field := s.Next(); field != "" {
@ -27,7 +27,7 @@ func (s *Scanner) NextFields(count int) []string {
} }
// Next returns the next field // Next returns the next field
func (s *Scanner) Next() string { func (s *scanner) Next() string {
sLen := len(s.bytes) sLen := len(s.bytes)
// skip trailing whitespace // skip trailing whitespace
@ -53,6 +53,6 @@ func (s *Scanner) Next() string {
} }
// Remaining returns the remaining 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)]) return string(s.bytes[s.position:len(s.bytes)])
} }

View File

@ -6,7 +6,7 @@ import "github.com/stretchr/testify/assert"
func TestScanner(t *testing.T) { func TestScanner(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
s := NewScanner("foo bar x y") s := newScanner("foo bar x y")
assert.Equal("foo", s.Next()) assert.Equal("foo", s.Next())
assert.Equal(" bar x y", s.Remaining()) assert.Equal(" bar x y", s.Remaining())
assert.Equal("bar", s.Next()) assert.Equal("bar", s.Next())
@ -21,7 +21,7 @@ func TestScanner(t *testing.T) {
func TestScannerEmpty(t *testing.T) { func TestScannerEmpty(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
s := NewScanner("") s := newScanner("")
assert.Equal("", s.Next()) assert.Equal("", s.Next())
assert.Equal("", s.Next()) assert.Equal("", s.Next())
assert.Equal("", s.Remaining()) assert.Equal("", s.Remaining())