/
RouteParser.go
59 lines (51 loc) · 1.27 KB
/
RouteParser.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
57
58
59
package parser
import (
"gosips/core"
"gosips/sip/header"
)
/** SIPParser for a list of route headers.
*/
type RouteParser struct {
AddressParametersParser
}
/** Constructor
* @param String route message to parse to set
*/
func NewRouteParser(route string) *RouteParser {
this := &RouteParser{}
this.AddressParametersParser.super(route)
return this
}
func NewRouteParserFromLexer(lexer core.Lexer) *RouteParser {
this := &RouteParser{}
this.AddressParametersParser.superFromLexer(lexer)
return this
}
/** parse the String message and generate the Route List Object
* @return SIPHeader the Route List object
* @throws SIPParseException if errors occur during the parsing
*/
func (this *RouteParser) Parse() (sh header.Header, ParseException error) {
routeList := header.NewRouteList()
var ch byte
lexer := this.GetLexer()
lexer.Match(TokenTypes_ROUTE)
lexer.SPorHT()
lexer.Match(':')
lexer.SPorHT()
for {
route := header.NewRoute()
this.AddressParametersParser.Parse(route)
routeList.PushBack(route)
lexer.SPorHT()
if ch, _ = lexer.LookAheadK(0); ch == ',' {
lexer.Match(',')
lexer.SPorHT()
} else if ch, _ = lexer.LookAheadK(0); ch == '\n' {
break
} else {
return nil, this.CreateParseException("unexpected char")
}
}
return routeList, nil
}