]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
ConfTextStorage: Make fieldType an enum
authorRoopesh Chander <roop@roopc.net>
Fri, 15 Feb 2019 18:56:49 +0000 (00:26 +0530)
committerRoopesh Chander <roop@roopc.net>
Fri, 15 Feb 2019 18:56:49 +0000 (00:26 +0530)
Signed-off-by: Roopesh Chander <roop@roopc.net>
WireGuard/WireGuard/UI/macOS/View/ConfTextStorage.swift

index 47c05b1719ba53e815dffe50ce3821ce932d914e..48a32edf684244b37819dd14820939d6277b4cdc 100644 (file)
@@ -92,7 +92,11 @@ class ConfTextStorage: NSTextStorage {
 
     func evaluateExcludePrivateIPs(highlightSpans: UnsafePointer<highlight_span>) {
         var spans = highlightSpans
-        var fieldType = 0
+        enum FieldType: String {
+            case dns
+            case allowedips
+        }
+        var fieldType: FieldType?
         resetLastPeer()
         while spans.pointee.type != HighlightEnd {
             let span = spans.pointee
@@ -111,19 +115,12 @@ class ConfTextStorage: NSTextStorage {
                     hasOnePeer = true
                 }
             } else if span.type == HighlightField {
-                let field = substring.lowercased()
-                if field == "dns" {
-                    fieldType = 1
-                } else if field == "allowedips" {
-                    fieldType = 2
-                } else {
-                    fieldType = 0
-                }
-            } else if span.type == HighlightIP && fieldType == 1 {
+                fieldType = FieldType(rawValue: substring.lowercased())
+            } else if span.type == HighlightIP && fieldType == .dns {
                 if let parsed = DNSServer(from: substring) {
                     lastOnePeerDNSServers.append(parsed)
                 }
-            } else if span.type == HighlightIP && fieldType == 2 {
+            } else if span.type == HighlightIP && fieldType == .allowedips {
                 let next = spans.successor()
                 let nextnext = next.successor()
                 if next.pointee.type == HighlightDelimiter && nextnext.pointee.type == HighlightCidr {