Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / scripts / maps / tile_build / src / geojson_extra.rs
geojson_extra.rs27 lines · 794 BRaw
| 1 | pub fn unescape(s: &str) -> String { |
| 2 | if !s.contains('\\') { |
| 3 | return s.to_string(); |
| 4 | } |
| 5 | let mut out = String::with_capacity(s.len()); |
| 6 | let mut it = s.chars(); |
| 7 | while let Some(c) = it.next() { |
| 8 | if c != '\\' { |
| 9 | out.push(c); |
| 10 | continue; |
| 11 | } |
| 12 | match it.next() { |
| 13 | Some('n') => out.push('\n'), |
| 14 | Some('r') => out.push('\r'), |
| 15 | Some('t') => out.push('\t'), |
| 16 | Some('u') => { |
| 17 | let hex: String = it.by_ref().take(4).collect(); |
| 18 | if let Some(ch) = u32::from_str_radix(&hex, 16).ok().and_then(char::from_u32) { |
| 19 | out.push(ch); |
| 20 | } |
| 21 | } |
| 22 | Some(other) => out.push(other), |
| 23 | None => break, |
| 24 | } |
| 25 | } |
| 26 | out |
| 27 | } |