github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/path.go (about)

     1  package utils
     2  
     3  // CleanPath 清理Path中的多余的字符
     4  func CleanPath(path string) string {
     5  	l := len(path)
     6  	if l == 0 {
     7  		return "/"
     8  	}
     9  	result := []byte{'/'}
    10  	isSlash := true
    11  	for i := 0; i < l; i++ {
    12  		if path[i] == '?' {
    13  			result = append(result, path[i:]...)
    14  			break
    15  		}
    16  		if path[i] == '\\' || path[i] == '/' {
    17  			if !isSlash {
    18  				isSlash = true
    19  				result = append(result, '/')
    20  			}
    21  		} else {
    22  			isSlash = false
    23  			result = append(result, path[i])
    24  		}
    25  	}
    26  	return string(result)
    27  }