Skip to content

Commit 7d04105

Browse files
committed
Adopt name-and-ref phrase
1 parent e10a0bc commit 7d04105

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

OSRMTextInstructions/OSRMTextInstructions.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,18 @@ public class OSRMInstructionFormatter: Formatter {
247247
let isMotorway = roadClasses?.contains(.motorway) ?? false
248248

249249
if let name = name, let ref = ref, name != ref, !isMotorway {
250-
wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, name)) (\(modifyValueByKey!(.code, ref)))" : "\(name) (\(ref))"
250+
let phrases = instructions["phrase"] as! [String: String]
251+
let phrase = phrases["name and ref"]!
252+
wayName = phrase.replacingTokens(using: { (tokenType) -> String in
253+
switch tokenType {
254+
case .wayName:
255+
return modifyValueByKey?(.wayName, name) ?? name
256+
case .code:
257+
return modifyValueByKey?(.code, ref) ?? ref
258+
default:
259+
fatalError("Unexpected token type \(tokenType) in name-and-ref phrase")
260+
}
261+
})
251262
} else if let ref = ref, isMotorway, let decimalRange = ref.rangeOfCharacter(from: .decimalDigits), !decimalRange.isEmpty {
252263
wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.code, ref))" : ref
253264
} else if name == nil, let ref = ref {

OSRMTextInstructions/TokenType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public enum TokenType: Int, CustomStringConvertible {
2222
public init?(description: String) {
2323
let type: TokenType
2424
switch description {
25-
case "way_name":
25+
case "way_name", "name":
2626
type = .wayName
2727
case "destination":
2828
type = .destination

OSRMTextInstructionsTests/OSRMTextInstructionsTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ class OSRMTextInstructionsTests: XCTestCase {
2424
let bundle = Bundle(for: OSRMTextInstructionsTests.self)
2525
let url = bundle.url(forResource: "v5", withExtension: nil, subdirectory: "osrm-text-instructions/test/fixtures/")!
2626

27-
let v5 = OSRMTextInstructionsStrings["v5"] as! [String: Any]
28-
let phrases = v5["phrase"] as! [String: String]
27+
let phrases = instructions.instructions["phrase"] as! [String: String]
2928

3029
var directoryContents: [URL] = []
3130
XCTAssertNoThrow(directoryContents = try FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: nil, options: []))

0 commit comments

Comments
 (0)