ConfTextStorage: Make fieldType an enum
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
@@ -92,7 +92,11 @@ class ConfTextStorage: NSTextStorage {
|
|||||||
|
|
||||||
func evaluateExcludePrivateIPs(highlightSpans: UnsafePointer<highlight_span>) {
|
func evaluateExcludePrivateIPs(highlightSpans: UnsafePointer<highlight_span>) {
|
||||||
var spans = highlightSpans
|
var spans = highlightSpans
|
||||||
var fieldType = 0
|
enum FieldType: String {
|
||||||
|
case dns
|
||||||
|
case allowedips
|
||||||
|
}
|
||||||
|
var fieldType: FieldType?
|
||||||
resetLastPeer()
|
resetLastPeer()
|
||||||
while spans.pointee.type != HighlightEnd {
|
while spans.pointee.type != HighlightEnd {
|
||||||
let span = spans.pointee
|
let span = spans.pointee
|
||||||
@@ -111,19 +115,12 @@ class ConfTextStorage: NSTextStorage {
|
|||||||
hasOnePeer = true
|
hasOnePeer = true
|
||||||
}
|
}
|
||||||
} else if span.type == HighlightField {
|
} else if span.type == HighlightField {
|
||||||
let field = substring.lowercased()
|
fieldType = FieldType(rawValue: substring.lowercased())
|
||||||
if field == "dns" {
|
} else if span.type == HighlightIP && fieldType == .dns {
|
||||||
fieldType = 1
|
|
||||||
} else if field == "allowedips" {
|
|
||||||
fieldType = 2
|
|
||||||
} else {
|
|
||||||
fieldType = 0
|
|
||||||
}
|
|
||||||
} else if span.type == HighlightIP && fieldType == 1 {
|
|
||||||
if let parsed = DNSServer(from: substring) {
|
if let parsed = DNSServer(from: substring) {
|
||||||
lastOnePeerDNSServers.append(parsed)
|
lastOnePeerDNSServers.append(parsed)
|
||||||
}
|
}
|
||||||
} else if span.type == HighlightIP && fieldType == 2 {
|
} else if span.type == HighlightIP && fieldType == .allowedips {
|
||||||
let next = spans.successor()
|
let next = spans.successor()
|
||||||
let nextnext = next.successor()
|
let nextnext = next.successor()
|
||||||
if next.pointee.type == HighlightDelimiter && nextnext.pointee.type == HighlightCidr {
|
if next.pointee.type == HighlightDelimiter && nextnext.pointee.type == HighlightCidr {
|
||||||
|
|||||||
Reference in New Issue
Block a user