summaryrefslogtreecommitdiffstats
path: root/header.go
diff options
context:
space:
mode:
authorclsr <clsr@clsr.net>2017-08-25 17:04:42 +0200
committerclsr <clsr@clsr.net>2017-08-25 17:04:44 +0200
commit9ca364d8753a5f2c7529c5b3dd7178bfd51effc6 (patch)
treedc5ab072ffbbd37da910d440e05b5bc56dc3f6da /header.go
parentba217ddeef9c6cd502a6f150bf59cf3ce329cc61 (diff)
downloadcnp-go-9ca364d8753a5f2c7529c5b3dd7178bfd51effc6.tar.gz
cnp-go-9ca364d8753a5f2c7529c5b3dd7178bfd51effc6.zip
Add support for the draft/cnp-select "select" request/response parameterv0.1.2
Diffstat (limited to 'header.go')
-rw-r--r--header.go44
1 files changed, 22 insertions, 22 deletions
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++
}