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

     1  package pathsplit
     2  
     3  import (
     4  	"errors"
     5  	"strings"
     6  )
     7  
     8  func Split(path string) ([]string, error) {
     9  	switch len(path) {
    10  	case 0:
    11  		return nil, errors.New("empty path and missing separator")
    12  
    13  	case 1:
    14  		return nil, errors.New("path separator supplied but empty path followed")
    15  
    16  	case 2:
    17  		if path[0] == path[1] {
    18  			return []string{""}, nil
    19  		}
    20  		fallthrough
    21  
    22  	default:
    23  		return strings.Split(path[1:], path[0:1]), nil
    24  	}
    25  }