Exemple #1
0
func writeQ(buf *bytes.Buffer, b byte) {
	switch {
	case b == ' ':
		buf.WriteByte('_')
	case b >= '!' && b <= '~' && b != '=' && b != '?' && b != '_':
		buf.WriteByte(b)
	default:
		enc := make([]byte, 3)
		internal.EncodeByte(enc, b)
		buf.Write(enc)
	}
}
// Encode encodes src into at most MaxEncodedLen(len(src)) bytes to dst,
// returning the actual number of bytes written to dst.
func Encode(dst, src []byte) int {
	n := 0
	for i, c := range src {
		switch {
		case c != '=' && (c >= '!' && c <= '~' || c == '\n' || c == '\r'):
			dst[n] = c
			n++
		case c == ' ' || c == '\t':
			if isLastChar(i, src) {
				internal.EncodeByte(dst[n:], c)
				n += 3
			} else {
				dst[n] = c
				n++
			}
		default:
			internal.EncodeByte(dst[n:], c)
			n += 3
		}
	}

	return n
}