-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcontentdisposition.go
51 lines (46 loc) · 1.06 KB
/
contentdisposition.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
// 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 (
"strings"
)
// ContentDisposition is a struct that holds a parsed
// content-disposition hdr:
// -- Val is the raw value
// -- DispType is the display type
// -- Params is slice of parameters
type ContentDisposition struct {
// Val is the raw value
Val string
// DispType is the display type
DispType string
// Params is a slice of *Param
Params []*Param
}
func (c *ContentDisposition) addParam(s string) {
if s == "" {
return
}
if c.Params == nil {
c.Params = []*Param{getParam(s)}
return
}
c.Params = append(c.Params, getParam(s))
}
func (c *ContentDisposition) parse() {
charPos := strings.IndexRune(c.Val, ';')
if charPos == -1 {
c.DispType = c.Val
return
}
c.DispType = c.Val[0:charPos]
if len(c.Val)-1 > charPos {
params := strings.Split(c.Val[charPos+1:], ";")
for i := range params {
c.addParam(params[i])
}
}
return
}