Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit interpret-as=address to numbers in road names #552

Merged
merged 4 commits into from Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this will miss any codes like A-35. OSM tagging conventions call for a space, as in I 35, but I do see some other regions using hyphens. We could harden this code by enumerating the string with String.enumerateSubstrings(in:options:_:) and byWord, or with String.replacingOccurrences(of:with:options:range:) and regularExpression.


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
}
}