github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/path/split.go (about)

     1  package path
     2  
     3  import (
     4  	"path"
     5  	"strings"
     6  
     7  	"github.com/lmorg/murex/utils/consts"
     8  )
     9  
    10  func Split(s string) []string {
    11  	if len(s) == 0 {
    12  		return []string{"."}
    13  	}
    14  
    15  	s = path.Clean(s)
    16  
    17  	split := strings.Split(s, consts.PathSlash)
    18  
    19  	if len(split) == 0 {
    20  		// this should never happen
    21  		return []string{"."}
    22  	}
    23  
    24  	if len(split) > 0 && split[0] == "" {
    25  		split[0] = consts.PathSlash
    26  	}
    27  
    28  	if split[len(split)-1] == "" {
    29  		split = split[:len(split)-1]
    30  	}
    31  
    32  	return split
    33  }