Skip to content

Commit

Permalink
Limit interpret-as=address to numbers in road names (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobby Sudekum committed Aug 29, 2017
1 parent 0237c8e commit c61e31b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 5 additions & 8 deletions MapboxCoreNavigation/RouteStepFormatter.swift
Expand Up @@ -23,15 +23,12 @@ public class RouteStepFormatter: Formatter {

let modifyValueByKey = { (key: OSRMTextInstructions.TokenType, value: String) -> String in
switch key {
case .code:
let refComponents = value.addingXMLEscapes.components(separatedBy: .whitespaces)
guard var firstRefComponent = refComponents.first else { return value.asSSMLAddress }
case .wayName, .destination, .rotaryName, .code:
let stringComponents = value.addingXMLEscapes.components(separatedBy: .whitespaces)

firstRefComponent = firstRefComponent.isUppercased ? firstRefComponent.asSSMLCharacters : firstRefComponent.asSSMLAddress

return "\(firstRefComponent) \(refComponents.suffix(from: 1).joined(separator: " ").asSSMLAddress)"
case .wayName, .destination, .rotaryName:
return value.asSSMLAddress
return stringComponents.map {
$0.containsDecimalDigit ? $0.asSSMLAddress : $0
}.joined(separator: " ")
default:
return value
}
Expand Down
4 changes: 4 additions & 0 deletions MapboxCoreNavigation/String.swift
Expand Up @@ -52,4 +52,8 @@ extension String {
var isUppercased: Bool {
return self == uppercased() && self != lowercased()
}

var containsDecimalDigit: Bool {
return self.rangeOfCharacter(from: CharacterSet.decimalDigits) != nil
}
}

0 comments on commit c61e31b

Please sign in to comment.