gitlab.com/evatix-go/core@v1.3.55/internal/csvinternal/StringersToCsvStrings.go (about) 1 package csvinternal 2 3 import ( 4 "fmt" 5 6 "gitlab.com/evatix-go/core/constants" 7 ) 8 9 // StringersToCsvStrings 10 // 11 // Formats : 12 // - isIncludeQuote && isIncludeSingleQuote = '%v' will be added 13 // - isIncludeQuote && !isIncludeSingleQuote = "'%v'" will be added 14 // - !isIncludeQuote && !isIncludeSingleQuote = %v will be added 15 func StringersToCsvStrings( 16 isIncludeQuote, 17 isIncludeSingleQuote bool, 18 stringerFunctions ...fmt.Stringer, 19 ) []string { 20 if len(stringerFunctions) == 0 { 21 return []string{} 22 } 23 24 slice := make([]string, len(stringerFunctions)) 25 26 if isIncludeQuote && isIncludeSingleQuote { 27 // single quote 28 for i, stringerFunc := range stringerFunctions { 29 slice[i] = fmt.Sprintf( 30 constants.ValueWithSingleQuoteFormat, 31 stringerFunc.String()) 32 } 33 34 return slice 35 } else if isIncludeQuote && !isIncludeSingleQuote { 36 // double quote 37 for i, stringerFunc := range stringerFunctions { 38 slice[i] = fmt.Sprintf( 39 constants.ValueWithDoubleQuoteFormat, 40 stringerFunc.String()) 41 } 42 43 return slice 44 } 45 46 // no quote 47 for i, stringerFunc := range stringerFunctions { 48 slice[i] = fmt.Sprintf( 49 constants.SprintValueFormat, 50 stringerFunc.String()) 51 } 52 53 return slice 54 }