gitlab.com/evatix-go/core@v1.3.55/coredata/stringslice/LinesProcess.go (about)

     1  package stringslice
     2  
     3  import (
     4  	"gitlab.com/evatix-go/core/constants"
     5  )
     6  
     7  // LinesProcess split text using constants.NewLineUnix
     8  // then returns lines processed by lineProcessor
     9  func LinesProcess(
    10  	lines []string,
    11  	lineProcessor func(index int, lineIn string) (lineOut string, isTake, isBreak bool),
    12  ) []string {
    13  	if len(lines) == 0 {
    14  		return []string{}
    15  	}
    16  
    17  	slice := Make(constants.Zero, len(lines))
    18  
    19  	for i, lineIn := range lines {
    20  		lineOut, isTake, isBreak := lineProcessor(i, lineIn)
    21  
    22  		if isTake {
    23  			slice = append(slice, lineOut)
    24  		}
    25  
    26  		if isBreak {
    27  			break
    28  		}
    29  	}
    30  
    31  	return slice
    32  }