-
Notifications
You must be signed in to change notification settings - Fork 0
/
device_utils_generic.go
24 lines (20 loc) · 1010 Bytes
/
device_utils_generic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package device
import (
"strings"
)
// deviceNameEncode encodes a string to be used as part of a file name in the LXD devices path.
// The encoding scheme replaces "-" with "--" and then "/" with "-".
func deviceNameEncode(text string) string {
return strings.Replace(strings.Replace(text, "-", "--", -1), "/", "-", -1)
}
// deviceNameDecode decodes a string used in the LXD devices path back to its original form.
// The decoding scheme converts "-" back to "/" and "--" back to "-".
func deviceNameDecode(text string) string {
// This converts "--" to the null character "\0" first, to allow remaining "-" chars to be
// converted back to "/" before making a final pass to convert "\0" back to original "-".
return strings.Replace(strings.Replace(strings.Replace(text, "--", "\000", -1), "-", "/", -1), "\000", "-", -1)
}
// deviceJoinPath joins together prefix and text delimited by a "." for device path generation.
func deviceJoinPath(parts ...string) string {
return strings.Join(parts, ".")
}