2026-05-22 20:26:11 -04:00
|
|
|
package pathscope
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var likeEscaper = strings.NewReplacer(
|
|
|
|
|
`\`, `\\`,
|
|
|
|
|
`%`, `\%`,
|
|
|
|
|
`_`, `\_`,
|
|
|
|
|
)
|
|
|
|
|
|
2026-07-06 18:52:44 -04:00
|
|
|
// EscapeLike escapes LIKE wildcards in a literal fragment for use with
|
|
|
|
|
// ESCAPE '\' queries.
|
|
|
|
|
func EscapeLike(literal string) string {
|
|
|
|
|
return likeEscaper.Replace(literal)
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-22 20:26:11 -04:00
|
|
|
func PrefixLike(pathPrefix string) string {
|
|
|
|
|
clean := filepath.Clean(pathPrefix)
|
|
|
|
|
if clean == string(filepath.Separator) {
|
|
|
|
|
return likeEscaper.Replace(clean) + "%"
|
|
|
|
|
}
|
|
|
|
|
return likeEscaper.Replace(clean) + string(filepath.Separator) + "%"
|
|
|
|
|
}
|