From 9ca364d8753a5f2c7529c5b3dd7178bfd51effc6 Mon Sep 17 00:00:00 2001 From: clsr Date: Fri, 25 Aug 2017 17:04:42 +0200 Subject: Add support for the draft/cnp-select "select" request/response parameter --- header.go | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'header.go') diff --git a/header.go b/header.go index e185dca..cb16db5 100644 --- a/header.go +++ b/header.go @@ -245,7 +245,7 @@ func (h Header) String() string { type Parameters map[string]string // Write writes the parameters encoded for inclusion in the wire format. -// Includes a leading space. +// Includes a leading space if p is nonempty. func (p Parameters) Write(w io.Writer) (err error) { bw := bufio.NewWriter(w) keys := []string{} @@ -280,41 +280,41 @@ func Escape(s string) []byte { if el == len(s) { return []byte(s) } - bs := make([]byte, el) + data := make([]byte, el) bi := 0 for i := 0; i < len(s); i++ { switch s[i] { case '\x00': - bs[bi] = '\\' - bs[bi+1] = '0' + data[bi] = '\\' + data[bi+1] = '0' bi += 2 case '\n': - bs[bi] = '\\' - bs[bi+1] = 'n' + data[bi] = '\\' + data[bi+1] = 'n' bi += 2 case ' ': - bs[bi] = '\\' - bs[bi+1] = '_' + data[bi] = '\\' + data[bi+1] = '_' bi += 2 case '=': - bs[bi] = '\\' - bs[bi+1] = '-' + data[bi] = '\\' + data[bi+1] = '-' bi += 2 case '\\': - bs[bi] = '\\' - bs[bi+1] = '\\' + data[bi] = '\\' + data[bi+1] = '\\' bi += 2 default: - bs[bi] = s[i] + data[bi] = s[i] bi++ } } - return bs + return data } func escapeLength(s string) (l int) { @@ -329,19 +329,19 @@ func escapeLength(s string) (l int) { return } -// Unescape unescapes the bs from wire format into a bytestring. -func Unescape(bs []byte) (string, error) { - buf := make([]byte, len(bs)) +// Unescape unescapes data from wire format into a bytestring. +func Unescape(data []byte) (string, error) { + buf := make([]byte, len(data)) bi := 0 - for i := 0; i < len(bs); i++ { - switch bs[i] { + for i := 0; i < len(data); i++ { + switch data[i] { case '\\': i++ - if i >= len(bs) { + if i >= len(data) { return string(buf[:bi]), ErrorSyntax{"invalid escape sequence: unexpected end of string"} } - switch bs[i] { + switch data[i] { case '0': buf[bi] = '\x00' case 'n': @@ -356,7 +356,7 @@ func Unescape(bs []byte) (string, error) { return string(buf[:bi]), ErrorSyntax{"invalid escape sequence: undefined sequence"} } default: - buf[bi] = bs[i] + buf[bi] = data[i] } bi++ } -- cgit