/
SubjectParser.go
49 lines (40 loc) · 1020 Bytes
/
SubjectParser.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
package parser
import (
"gosips/core"
"gosips/sip/header"
"strings"
)
/** SIPParser for Subject header.
*/
type SubjectParser struct {
HeaderParser
}
/** Creates a new instance of SubjectParser
* @param subject the header to parse
*/
func NewSubjectParser(subject string) *SubjectParser {
this := &SubjectParser{}
this.HeaderParser.super(subject)
return this
}
/** Cosntructor
* @param lexer the lexer to use to parse the header
*/
func NewSubjectParserFromLexer(lexer core.Lexer) *SubjectParser {
this := &SubjectParser{}
this.HeaderParser.superFromLexer(lexer)
return this
}
/** parse the String message
* @return SIPHeader (Subject object)
* @throws SIPParseException if the message does not respect the spec.
*/
func (this *SubjectParser) Parse() (sh header.Header, ParseException error) {
subject := header.NewSubject()
lexer := this.GetLexer()
this.HeaderName(TokenTypes_SUBJECT)
lexer.SPorHT()
s := lexer.GetRest()
subject.SetSubject(strings.TrimSpace(s))
return subject, nil
}