File: string.go

package info (click to toggle)
golang-github-mdlayher-netlink 1.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 420 kB
  • sloc: makefile: 5
file content (18 lines) | stat: -rw-r--r-- 585 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package nlenc

import "bytes"

// Bytes returns a null-terminated byte slice with the contents of s.
func Bytes(s string) []byte {
	return append([]byte(s), 0x00)
}

// String returns a string with the contents of b from a null-terminated
// byte slice.
func String(b []byte) string {
	// If the string has more than one NULL terminator byte, we want to remove
	// all of them before returning the string to the caller; hence the use of
	// strings.TrimRight instead of strings.TrimSuffix (which previously only
	// removed a single NULL).
	return string(bytes.TrimRight(b, "\x00"))
}