Percent-encode a string for safe use in URL query parameter values. Encodes all characters except unreserved characters (RFC 3986 Section 2.3): ALPHA / DIGIT / "-" / "." / "_" / "~"
(input: &str)
| 560 | /// Encodes all characters except unreserved characters (RFC 3986 Section 2.3): |
| 561 | /// ALPHA / DIGIT / "-" / "." / "_" / "~" |
| 562 | fn percent_encode_query(input: &str) -> String { |
| 563 | let mut encoded = String::with_capacity(input.len()); |
| 564 | for byte in input.bytes() { |
| 565 | match byte { |
| 566 | b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'.' | b'_' | b'~' => { |
| 567 | encoded.push(byte as char); |
| 568 | } |
| 569 | _ => { |
| 570 | use fmt::Write; |
| 571 | let _ = write!(encoded, "%{byte:02X}"); |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | encoded |
| 576 | } |
| 577 | |
| 578 | /// Percent-encode a string for safe use in URL path segments. |
| 579 | /// |