diff options
author | Wim <wim@42.be> | 2020-08-10 00:29:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-10 00:29:54 +0200 |
commit | 4e50fd864921c556988c919269448efdb90fa961 (patch) | |
tree | a3625f03f8de3c4f3841364000a4ea3aa42c1533 /vendor/github.com/francoispqt/gojay/encode_builder.go | |
parent | dfdffa0027334e55ce213fc6eb62206dbf48baf6 (diff) | |
download | matterbridge-msglm-4e50fd864921c556988c919269448efdb90fa961.tar.gz matterbridge-msglm-4e50fd864921c556988c919269448efdb90fa961.tar.bz2 matterbridge-msglm-4e50fd864921c556988c919269448efdb90fa961.zip |
Use mattermost v5 module (#1192)
Diffstat (limited to 'vendor/github.com/francoispqt/gojay/encode_builder.go')
-rw-r--r-- | vendor/github.com/francoispqt/gojay/encode_builder.go | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/vendor/github.com/francoispqt/gojay/encode_builder.go b/vendor/github.com/francoispqt/gojay/encode_builder.go new file mode 100644 index 00000000..2895ba34 --- /dev/null +++ b/vendor/github.com/francoispqt/gojay/encode_builder.go @@ -0,0 +1,65 @@ +package gojay + +const hex = "0123456789abcdef" + +// grow grows b's capacity, if necessary, to guarantee space for +// another n bytes. After grow(n), at least n bytes can be written to b +// without another allocation. If n is negative, grow panics. +func (enc *Encoder) grow(n int) { + if cap(enc.buf)-len(enc.buf) < n { + Buf := make([]byte, len(enc.buf), 2*cap(enc.buf)+n) + copy(Buf, enc.buf) + enc.buf = Buf + } +} + +// Write appends the contents of p to b's Buffer. +// Write always returns len(p), nil. +func (enc *Encoder) writeBytes(p []byte) { + enc.buf = append(enc.buf, p...) +} + +func (enc *Encoder) writeTwoBytes(b1 byte, b2 byte) { + enc.buf = append(enc.buf, b1, b2) +} + +// WriteByte appends the byte c to b's Buffer. +// The returned error is always nil. +func (enc *Encoder) writeByte(c byte) { + enc.buf = append(enc.buf, c) +} + +// WriteString appends the contents of s to b's Buffer. +// It returns the length of s and a nil error. +func (enc *Encoder) writeString(s string) { + enc.buf = append(enc.buf, s...) +} + +func (enc *Encoder) writeStringEscape(s string) { + l := len(s) + for i := 0; i < l; i++ { + c := s[i] + if c >= 0x20 && c != '\\' && c != '"' { + enc.writeByte(c) + continue + } + switch c { + case '\\', '"': + enc.writeTwoBytes('\\', c) + case '\n': + enc.writeTwoBytes('\\', 'n') + case '\f': + enc.writeTwoBytes('\\', 'f') + case '\b': + enc.writeTwoBytes('\\', 'b') + case '\r': + enc.writeTwoBytes('\\', 'r') + case '\t': + enc.writeTwoBytes('\\', 't') + default: + enc.writeString(`\u00`) + enc.writeTwoBytes(hex[c>>4], hex[c&0xF]) + } + continue + } +} |