Simplify unprintable handling in UnpackDomainName (#845)

* Avoid the for loop for unprintable octets in UnpackDomainName

* Unify unprintable checking with writeTXTStringByte

These constants are identical.
This commit is contained in:
Tom Thorogood 2018-11-29 18:02:13 +10:30 committed by Miek Gieben
parent ed726faad6
commit b1bf6f1b9b
1 changed files with 3 additions and 6 deletions

9
msg.go
View File

@ -405,14 +405,11 @@ Loop:
case '"', '\\':
s = append(s, '\\', b)
default:
if b < 32 || b >= 127 { // unprintable, use \DDD
if b < ' ' || b > '~' { // unprintable, use \DDD
var buf [3]byte
bufs := strconv.AppendInt(buf[:0], int64(b), 10)
s = append(s, '\\')
for i := len(bufs); i < 3; i++ {
s = append(s, '0')
}
s = append(s, bufs...)
s = append(s, '\\', '0', '0', '0')
copy(s[len(s)-len(bufs):], bufs)
} else {
s = append(s, b)
}