(value: &str, path: bool)
| 9 | pub struct IriError(pub String); |
| 10 | |
| 11 | fn encode(value: &str, path: bool) -> String { |
| 12 | let mut encoded = String::new(); |
| 13 | for byte in value.bytes() { |
| 14 | if byte.is_ascii_alphanumeric() || b"-._~".contains(&byte) || (path && byte == b'/') { |
| 15 | encoded.push(byte as char); |
| 16 | } else { |
| 17 | use std::fmt::Write; |
| 18 | write!(encoded, "%{byte:02X}").expect("write to string"); |
| 19 | } |
| 20 | } |
| 21 | encoded |
| 22 | } |
| 23 | |
| 24 | fn decode(value: &str, path: bool) -> Result<String, IriError> { |
| 25 | let mut decoded = Vec::new(); |