@@ -14,19 +14,19 @@ import (
1414 "reflect"
1515)
1616
17- // DeserializeCSV deserializes a CSV or TSV string into a Go instance.
17+ // DeserializeSV deserializes a CSV or TSV string into a Go instance.
1818// - https://golang.org/pkg/encoding/csv/
19- func DeserializeCSV (input io.Reader , format string , input_header []string , input_comment string , inputLazyQuotes bool , inputSkipLines int , inputLimit int , output_type reflect.Type ) (interface {}, error ) {
19+ func DeserializeSV (input io.Reader , format string , inputHeader []string , inputComment string , inputLazyQuotes bool , inputSkipLines int , inputLimit int , outputType reflect.Type ) (interface {}, error ) {
2020
21- if output_type .Kind () == reflect .Map {
21+ if outputType .Kind () == reflect .Map {
2222 if inputLimit != 1 {
23- return nil , errors .Wrap (& ErrInvalidLimit {Value : inputLimit }, "DeserializeCSV expects input limit of 1 when output type is of kind map." )
23+ return nil , errors .Wrap (& ErrInvalidLimit {Value : inputLimit }, "DeserializeSV expects input limit of 1 when output type is of kind map." )
2424 }
25- if len (input_header ) == 0 {
26- return nil , errors .New ("deserializeCSV when returning a map type expects a input header" )
25+ if len (inputHeader ) == 0 {
26+ return nil , errors .New ("deserializeSV when returning a map type expects a input header" )
2727 }
28- } else if ! (output_type .Kind () == reflect .Array || output_type .Kind () == reflect .Slice ) {
29- return nil , & ErrInvalidKind {Value : output_type .Kind (), Valid : []reflect.Kind {reflect .Array , reflect .Slice , reflect .Map }}
28+ } else if ! (outputType .Kind () == reflect .Array || outputType .Kind () == reflect .Slice ) {
29+ return nil , & ErrInvalidKind {Value : outputType .Kind (), Valid : []reflect.Kind {reflect .Array , reflect .Slice , reflect .Map }}
3030 }
3131
3232 reader := csv .NewReader (input )
@@ -36,13 +36,13 @@ func DeserializeCSV(input io.Reader, format string, input_header []string, input
3636 reader .LazyQuotes = inputLazyQuotes
3737 reader .FieldsPerRecord = - 1 // records may have a variable number of fields
3838
39- if len (input_comment ) > 1 {
39+ if len (inputComment ) > 1 {
4040 return nil , errors .New ("go's encoding/csv package only supports single character comment characters" )
41- } else if len (input_comment ) == 1 {
42- reader .Comment = []rune (input_comment )[0 ]
41+ } else if len (inputComment ) == 1 {
42+ reader .Comment = []rune (inputComment )[0 ]
4343 }
4444
45- if output_type .Kind () == reflect .Map {
45+ if outputType .Kind () == reflect .Map {
4646 inRow , err := reader .Read ()
4747 if err != nil {
4848 if err == io .EOF {
@@ -53,8 +53,8 @@ func DeserializeCSV(input io.Reader, format string, input_header []string, input
5353 if len (inRow ) == 0 {
5454 return nil , & ErrEmptyRow {}
5555 }
56- m := reflect .MakeMap (output_type )
57- for i , h := range input_header {
56+ m := reflect .MakeMap (outputType )
57+ for i , h := range inputHeader {
5858 // if the number of columns in the header is greater than in the row,
5959 // then break and return data for the columns that are there
6060 if i >= len (inRow ) {
@@ -65,17 +65,17 @@ func DeserializeCSV(input io.Reader, format string, input_header []string, input
6565 return m .Interface (), nil
6666 }
6767
68- if len (input_header ) == 0 {
68+ if len (inputHeader ) == 0 {
6969 h , err := reader .Read ()
7070 if err != nil {
7171 if err != io .EOF {
7272 return nil , errors .Wrap (err , "Error reading header from input with format csv" )
7373 }
7474 }
75- input_header = h
75+ inputHeader = h
7676 }
7777
78- output := reflect .MakeSlice (output_type , 0 , 0 )
78+ output := reflect .MakeSlice (outputType , 0 , 0 )
7979 for {
8080 inRow , err := reader .Read ()
8181 if err != nil {
@@ -85,8 +85,8 @@ func DeserializeCSV(input io.Reader, format string, input_header []string, input
8585 return nil , errors .Wrap (err , "error reading row into slice from input with format csv" )
8686 }
8787 }
88- m := reflect .MakeMap (output_type .Elem ())
89- for i , h := range input_header {
88+ m := reflect .MakeMap (outputType .Elem ())
89+ for i , h := range inputHeader {
9090 if i < len (inRow ) {
9191 m .SetMapIndex (reflect .ValueOf (h ), reflect .ValueOf (inRow [i ]))
9292 }
0 commit comments