From b766553e844515dcc5c329fef0f0e5b01ac0ede4 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Thu, 17 Aug 2017 15:10:35 -0700 Subject: [PATCH 1/2] Expose refs in modifier function --- OSRMTextInstructions/OSRMTextInstructions.swift | 7 ++++--- OSRMTextInstructions/TokenType.swift | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/OSRMTextInstructions/OSRMTextInstructions.swift b/OSRMTextInstructions/OSRMTextInstructions.swift index 6bb45d0..5538b79 100644 --- a/OSRMTextInstructions/OSRMTextInstructions.swift +++ b/OSRMTextInstructions/OSRMTextInstructions.swift @@ -192,11 +192,11 @@ public class OSRMInstructionFormatter: Formatter { let isMotorway = roadClasses?.contains(.motorway) ?? false if let name = name, let ref = ref, name != ref, !isMotorway { - wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, name)) (\(modifyValueByKey!(.wayName, ref)))" : "\(name) (\(ref))" + wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, name)) (\(modifyValueByKey!(.code, ref)))" : "\(name) (\(ref))" } else if let ref = ref, isMotorway, let decimalRange = ref.rangeOfCharacter(from: .decimalDigits), !decimalRange.isEmpty { - wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, ref))" : ref + wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.code, ref))" : ref } else if name == nil, let ref = ref { - wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, ref))" : ref + wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.code, ref))" : ref } else { wayName = name != nil ? modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, name!))" : name! : "" } @@ -276,6 +276,7 @@ public class OSRMInstructionFormatter: Formatter { if let tokenType = TokenType(description: token! as String) { var replacement: String switch tokenType { + case .code: replacement = step.codes?.first ?? "" case .wayName: replacement = wayName case .destination: replacement = destination case .exitCode: replacement = exitCode diff --git a/OSRMTextInstructions/TokenType.swift b/OSRMTextInstructions/TokenType.swift index 0db3e41..cb63c5a 100644 --- a/OSRMTextInstructions/TokenType.swift +++ b/OSRMTextInstructions/TokenType.swift @@ -12,6 +12,7 @@ public enum TokenType: Int, CustomStringConvertible { case modifier case direction case wayPoint + case code public init?(description: String) { let type: TokenType @@ -34,6 +35,8 @@ public enum TokenType: Int, CustomStringConvertible { type = .direction case "nth": type = .wayPoint + case "code": + type = .code default: return nil } @@ -60,6 +63,8 @@ public enum TokenType: Int, CustomStringConvertible { return "direction" case .wayPoint: return "nth" + case .code: + return "code" } } } From 1682c9020dd48369302a7b9ec31c105b1b212ee8 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Thu, 17 Aug 2017 17:08:49 -0700 Subject: [PATCH 2/2] ref --- OSRMTextInstructions/TokenType.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OSRMTextInstructions/TokenType.swift b/OSRMTextInstructions/TokenType.swift index cb63c5a..6d43ab3 100644 --- a/OSRMTextInstructions/TokenType.swift +++ b/OSRMTextInstructions/TokenType.swift @@ -35,7 +35,7 @@ public enum TokenType: Int, CustomStringConvertible { type = .direction case "nth": type = .wayPoint - case "code": + case "ref": type = .code default: return nil @@ -64,7 +64,7 @@ public enum TokenType: Int, CustomStringConvertible { case .wayPoint: return "nth" case .code: - return "code" + return "ref" } } }