gitlab.com/evatix-go/core@v1.3.55/coreutils/stringutil/SplitContentsByWhitespaceConditions.go (about)

     1  package stringutil
     2  
     3  import (
     4  	"sort"
     5  	"strings"
     6  
     7  	"gitlab.com/evatix-go/core/coredata/corestr"
     8  	"gitlab.com/evatix-go/core/coredata/stringslice"
     9  )
    10  
    11  func SplitContentsByWhitespaceConditions(
    12  	input string,
    13  	isTrimEachLine,
    14  	isNonEmptyWhitespace,
    15  	isSort bool,
    16  	isUnique bool,
    17  	isLowerCase bool,
    18  ) []string {
    19  	if isLowerCase || isUnique {
    20  		input = strings.ToLower(input)
    21  	}
    22  
    23  	compiledStringSplits := strings.Fields(input)
    24  
    25  	if isNonEmptyWhitespace && isTrimEachLine {
    26  		compiledStringSplits = stringslice.NonWhitespaceTrimSlice(
    27  			compiledStringSplits)
    28  	} else if isNonEmptyWhitespace && !isTrimEachLine {
    29  		compiledStringSplits = stringslice.NonWhitespaceSlice(
    30  			compiledStringSplits)
    31  	}
    32  
    33  	if isUnique {
    34  		hashset := corestr.New.Hashset.StringsPtr(&compiledStringSplits)
    35  		compiledStringSplits = hashset.List()
    36  	}
    37  
    38  	if isSort {
    39  		sort.Strings(compiledStringSplits)
    40  	}
    41  
    42  	return compiledStringSplits
    43  }