MCPcopy Create free account
hub / github.com/akalin/gopar / decodeNullPaddedASCIIString

Function decodeNullPaddedASCIIString

par2/string.go:21–39  ·  view source on GitHub ↗
(bs []byte)

Source from the content-addressed store, hash-verified

19}
20
21func decodeNullPaddedASCIIString(bs []byte) string {
22 // First, null-terminate if necessary.
23 bs = nullTerminate(bs)
24
25 var replaceBuf [4]byte
26 n := utf8.EncodeRune(replaceBuf[:], unicode.ReplacementChar)
27
28 // Replace all non-ASCII characters with the replacement character.
29 var outBytes []byte
30 for _, b := range bs {
31 if b <= unicode.MaxASCII {
32 outBytes = append(outBytes, b)
33 } else {
34 outBytes = append(outBytes, replaceBuf[:n]...)
35 }
36 }
37
38 return string(outBytes)
39}
40
41func encodeASCIIString(s string) ([]byte, error) {
42 var bs []byte

Callers 5

TestDecodeASCIIStringFunction · 0.85
TestDecodeNonASCIIStringFunction · 0.85
readCreatorPacketFunction · 0.85

Calls 1

nullTerminateFunction · 0.85

Tested by 3

TestDecodeASCIIStringFunction · 0.68
TestDecodeNonASCIIStringFunction · 0.68