This is how I detect Overpass output format right now:
|
let re = Regex::new(r"^out:[a-z]$").unwrap(); |
|
|
|
let output_format = if query.contains("[out:xml]") { |
|
OverpassOutputFormat::Xml |
|
} else if query.contains("[out:json]") { |
|
OverpassOutputFormat::Json |
|
} else if re.is_match(&query) { |
|
return Err(SkywayError::InvalidInputFile( |
|
"Your Overpass query requests an output format that skyway cannot parse. Please request XML or JSON, if possible.".to_string(), |
|
)); |
|
} else { |
|
OverpassOutputFormat::Xml |
|
}; |
I'd like to make this a little bit smarter, and avoid matching [out:xml] or [out:json] anywhere in the query outside of the first line(s). Shouldn't be too hard to implement regex for each of these that's aware of comments and semicolons.
This is how I detect Overpass output format right now:
skyway/src/overpass.rs
Lines 21 to 33 in ff6a764
I'd like to make this a little bit smarter, and avoid matching
[out:xml]or[out:json]anywhere in the query outside of the first line(s). Shouldn't be too hard to implement regex for each of these that's aware of comments and semicolons.