All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 2m12s
Test / Hakurei (push) Successful in 3m8s
Test / Hpkg (push) Successful in 4m9s
Test / Sandbox (race detector) (push) Successful in 4m31s
Test / Hakurei (race detector) (push) Successful in 5m25s
Test / Flake checks (push) Successful in 1m40s
This is used in hst to format strings. Signed-off-by: Ophestra <cat@gensokyo.uk>
30 lines
846 B
Go
30 lines
846 B
Go
package check
|
|
|
|
import "strings"
|
|
|
|
const (
|
|
// SpecialOverlayEscape is the escape string for overlay mount options.
|
|
SpecialOverlayEscape = `\`
|
|
// SpecialOverlayOption is the separator string between overlay mount options.
|
|
SpecialOverlayOption = ","
|
|
// SpecialOverlayPath is the separator string between overlay paths.
|
|
SpecialOverlayPath = ":"
|
|
)
|
|
|
|
// EscapeOverlayDataSegment escapes a string for formatting into the data argument of an overlay mount call.
|
|
func EscapeOverlayDataSegment(s string) string {
|
|
if s == "" {
|
|
return ""
|
|
}
|
|
|
|
if f := strings.SplitN(s, "\x00", 2); len(f) > 0 {
|
|
s = f[0]
|
|
}
|
|
|
|
return strings.NewReplacer(
|
|
SpecialOverlayEscape, SpecialOverlayEscape+SpecialOverlayEscape,
|
|
SpecialOverlayOption, SpecialOverlayEscape+SpecialOverlayOption,
|
|
SpecialOverlayPath, SpecialOverlayEscape+SpecialOverlayPath,
|
|
).Replace(s)
|
|
}
|