gitlab.com/evatix-go/core@v1.3.55/corecsv/CompileStringersToCsvStrings.go (about) 1 package corecsv 2 3 import ( 4 "fmt" 5 6 "gitlab.com/evatix-go/core/constants" 7 ) 8 9 // CompileStringersToCsvStrings 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 CompileStringersToCsvStrings( 16 isIncludeQuote, 17 isIncludeSingleQuote bool, // disable this will give double quote 18 compileStringerFunctions ...func() string, 19 ) []string { 20 if len(compileStringerFunctions) == 0 { 21 return []string{} 22 } 23 24 slice := make([]string, len(compileStringerFunctions)) 25 26 if isIncludeQuote && isIncludeSingleQuote { 27 // single quote 28 for i, compilerFunc := range compileStringerFunctions { 29 slice[i] = fmt.Sprintf( 30 constants.ValueWithSingleQuoteFormat, 31 compilerFunc()) 32 } 33 34 return slice 35 } else if isIncludeQuote && !isIncludeSingleQuote { 36 // double quote 37 for i, compilerFunc := range compileStringerFunctions { 38 slice[i] = fmt.Sprintf( 39 constants.ValueWithDoubleQuoteFormat, 40 compilerFunc()) 41 } 42 43 return slice 44 } 45 46 // no quote 47 for i, compilerFunc := range compileStringerFunctions { 48 slice[i] = fmt.Sprintf( 49 constants.SprintValueFormat, 50 compilerFunc()) 51 } 52 53 return slice 54 }