-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaccept.go
56 lines (50 loc) · 1.26 KB
/
accept.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2011, Shelby Ramsey. All rights reserved.
// Use of this code is governed by a BSD license that can be
// found in the LICENSE.txt file.
package sipparser
// Imports from the go standard library
import ()
// AcceptParam is just a key:value pair of params for the accept
// header
type AcceptParam struct {
Type string
Val string
}
// Accept is a struct that holds the following:
// -- the raw value
// -- a slice of parced AcceptParam
type Accept struct {
// Val is the raw value
Val string
// Params is a slice of AcceptParam
Params []*AcceptParam
}
// addParam is called when you want to add a parameter to the accept
// struct
func (a *Accept) addParam(s string) {
for i := range s {
if s[i] == '/' {
if len(s)-1 > i {
if a.Params == nil {
a.Params = []*AcceptParam{&AcceptParam{Type: cleanWs(s[0:i]), Val: cleanWs(s[i+1:])}}
return
}
a.Params = append(a.Params, &AcceptParam{Type: cleanWs(s[0:i]), Val: cleanWs(s[i+1:])})
return
}
return
}
}
}
// parse just gets a comma seperated list of the parameters from
// the .Val and calls addparam on each of the parameters
func (a *Accept) parse() {
cs := getCommaSeperated(a.Val)
if cs == nil {
a.addParam(a.Val)
return
}
for i := range cs {
a.addParam(cs[i])
}
}