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

Structured road names, codes, destinations #91

Merged
merged 6 commits into from
Nov 15, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions MapboxDirections/MBRouteStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -388,17 +388,17 @@ struct Road {

init(name: String?, ref: String?, destination: String?) {
var codes: [String]?
if let names = name, let ref = ref ?? destination {
// Mapbox Directions API v5 encodes the ref separately from the name but redundantly includes the ref in the name for backwards compatibility. Remove the ref from the name.
let parenthetical = "(\(ref))"
if names == ref {
if let names = name, let gloss = ref ?? destination {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand the semantic meaning of gloss and the dictionary did not help me understand. The case that in Mapbox Directions v5 destination is mixed into name can not exist. Likewise it makes no sense to me that codes would ever have the contents of destination in them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out Directions API v5 used to conflate destination with ref in the parenthetical, but it no longer does so, much to my relief. I’ll gladly remove the fallbacks.

// Mapbox Directions API v5 encodes the ref separately from the name but redundantly includes the ref or destination in the name for backwards compatibility. Remove the ref or destination from the name.
Copy link
Contributor

Choose a reason for hiding this comment

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

To clarify: This is not true, the direction is never mixed into the name, but only the ref.

let parenthetical = "(\(gloss))"
if names == gloss {
self.names = nil
} else {
self.names = names.stringByReplacingOccurrencesOfString(parenthetical, withString: "").tagValuesSeparatedByString(";")
}
codes = ref.tagValuesSeparatedByString(";")
codes = gloss.tagValuesSeparatedByString(";")
} else if let names = name, let codesRange = names.rangeOfString("\\(.+?\\)$", options: .RegularExpressionSearch, range: names.startIndex..<names.endIndex) {
// Mapbox Directions API v4 encodes the ref inside a parenthetical. Remove the ref from the name.
// Mapbox Directions API v4 encodes the ref or destination inside a parenthetical. Remove the ref or destination from the name.
let parenthetical = names.substringWithRange(codesRange)
if names == ref ?? destination {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above, remove ?? destination

self.names = nil
Expand Down