@@ -50,11 +50,10 @@ func trimSpaceSliceSliceString(s [][]string) [][]string {
50
50
// ReadFile reads in a delimited file and returns a `Table` struct.
51
51
func readSingleFile (opts * ParseOptions , filename string ) (Table , error ) {
52
52
tbl := NewTable ("" )
53
- comma := ','
54
- if opts != nil {
55
- comma = opts .CommaValue ()
53
+ if opts == nil {
54
+ opts = & ParseOptions {}
56
55
}
57
- csvReader , f , err := csvutil .NewReader (filename , comma )
56
+ csvReader , f , err := csvutil .NewReader (filename , opts . CommaValue () )
58
57
if err != nil {
59
58
return tbl , err
60
59
}
@@ -79,15 +78,13 @@ func readSingleFile(opts *ParseOptions, filename string) (Table, error) {
79
78
}
80
79
}
81
80
} else {
81
+ csvReader .FieldsPerRecord = opts .FieldsPerRecord
82
82
errorOutofBounds := true
83
- if opts != nil {
84
- csvReader .FieldsPerRecord = opts .FieldsPerRecord
85
- if csvReader .FieldsPerRecord < 0 {
86
- errorOutofBounds = false
87
- }
83
+ if csvReader .FieldsPerRecord < 0 {
84
+ errorOutofBounds = false
88
85
}
89
86
lines , err := csvReader .ReadAll ()
90
- if opts != nil && opts .TrimSpace {
87
+ if opts .TrimSpace {
91
88
lines = trimSpaceSliceSliceString (lines )
92
89
}
93
90
if err != nil {
@@ -96,8 +93,8 @@ func readSingleFile(opts *ParseOptions, filename string) (Table, error) {
96
93
if len (lines ) == 0 {
97
94
return tbl , errors .New ("no content" )
98
95
}
99
- if opts == nil || ! opts .NoHeader {
100
- if opts == nil || ! opts .HasFilter () {
96
+ if ! opts .NoHeader { // hasHeader
97
+ if ! opts .HasFilter () {
101
98
tbl .LoadMergedRows (lines )
102
99
} else {
103
100
if len (opts .FilterColNames ) > 0 {
@@ -122,7 +119,7 @@ func readSingleFile(opts *ParseOptions, filename string) (Table, error) {
122
119
tbl .Rows = rows
123
120
}
124
121
} else {
125
- if opts == nil || len (opts .FilterColIndices ) == 0 {
122
+ if len (opts .FilterColIndices ) == 0 {
126
123
tbl .Rows = lines
127
124
} else {
128
125
rows , err := opts .Filter ([]string {}, lines , errorOutofBounds )
0 commit comments