package check

import "strings"

const (
	// SpecialOverlayEscape is the escape string for overlay mount options.
	//
	// Deprecated: This is no longer used and will be removed in 0.5.
	SpecialOverlayEscape = `\`
	// SpecialOverlayOption is the separator string between overlay mount options.
	//
	// Deprecated: This is no longer used and will be removed in 0.5.
	SpecialOverlayOption = ","
	// SpecialOverlayPath is the separator string between overlay paths.
	//
	// Deprecated: This is no longer used and will be removed in 0.5.
	SpecialOverlayPath = ":"
)

// EscapeOverlayDataSegment escapes a string for formatting into the data
// argument of an overlay mount system call.
//
// Deprecated: This is no longer used and will be removed in 0.5.
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)
}
