src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

split.go (461B)


      1 package rulesfn
      2 
      3 import "strings"
      4 
      5 // Split splits the input string by the delimiter and returns the resulting
      6 // parts. If limit is > 0, at most limit substrings are returned.
      7 // Returns a slice with a single empty string if the input is empty.
      8 func Split(input, delimiter string, limit int) []string {
      9 	if len(input) == 0 {
     10 		return []string{""}
     11 	}
     12 	if limit > 0 {
     13 		return strings.SplitN(input, delimiter, limit)
     14 	}
     15 	return strings.Split(input, delimiter)
     16 }