Crate url_escape[−][src]
URL Escape
This library is for encoding/escaping special characters in URLs and decoding/unescaping URLs as well.
Usage
Encoding
This crate provides some encode_*
functions to encode URL text in different situations.
For example, to put a text to a fragment, use the encode_fragment
function.
extern crate url_escape; assert_eq!("a%20%3E%20b?", url_escape::encode_fragment("a > b?"));
The functions suffixed with _to_writer
, _to_vec
or _to_string
are useful to generate URL text.
extern crate url_escape; let mut url = String::from("https://"); assert_eq!("admin%40example.com", url_escape::encode_userinfo_to_string("admin@example.com", &mut url)); url.push_str("@127.0.0.1/"); assert_eq!("%E4%B8%AD%E6%96%87%E5%AD%97/eng/12%2034", url_escape::encode_path_to_string("中文字/eng/12 34", &mut url)); url.push('/'); assert_eq!(r"56%2F78", url_escape::encode_component_to_string("56/78", &mut url)); url.push('?'); assert_eq!(r"a=1&b=a%20b%20c", url_escape::encode_query_to_string("a=1&b=a b c", &mut url)); assert_eq!("https://admin%40example.com@127.0.0.1/%E4%B8%AD%E6%96%87%E5%AD%97/eng/12%2034/56%2F78?a=1&b=a%20b%20c", url);
Decoding
extern crate url_escape; assert_eq!("中文字/eng/12 34", url_escape::decode("%E4%B8%AD%E6%96%87%E5%AD%97/eng/12%2034"));
Re-exports
pub extern crate percent_encoding; |
Constants
COMPONENT | The component percent-encode set is the userinfo percent-encode set and U+0024 ($) to U+0026 (&), inclusive, U+002B (+), and U+002C (,). |
CONTROLS | The C0 control percent-encode set are the C0 controls and U+007F (DEL). |
FRAGMENT | The fragment percent-encode set is the C0 control percent-encode set and U+0020 SPACE, U+0022 (“), U+003C (<), U+003E (>), and U+0060 (`). |
NON_ALPHANUMERIC | Not an ASCII letter or digit. |
PATH | The path percent-encode set is the query percent-encode set and U+003F (?), U+0060 (`), U+007B ({), and U+007D (}). |
QUERY | The query percent-encode set is the C0 control percent-encode set and U+0020 SPACE, U+0022 (“), U+0023 (#), U+003C (<), and U+003E (>). |
SPECIAL_QUERY | The special-query percent-encode set is the query percent-encode set and U+0027 (’). |
USERINFO | The userinfo percent-encode set is the path percent-encode set and U+002F (/), U+003A (:), U+003B (;), U+003D (=), U+0040 (@), U+005B ([) to U+005E (^), inclusive, and U+007C (|). |
X_WWW_FORM_URLENCODED | The application/x-www-form-urlencoded percent-encode set is the component percent-encode set and U+0021 (!), U+0027 (’) to U+0029 RIGHT PARENTHESIS, inclusive, and U+007E (~). |
Functions
decode | Decode percent-encoded bytes in a given string. |
decode_to_string | Decode percent-encoded bytes in a given string to a mutable |
decode_to_vec | Decode percent-encoded bytes in a given string to a mutable |
decode_to_writer | Decode percent-encoded bytes in a given string to a writer. |
encode | Encode text. |
encode_component | Encode text used in a component. |
encode_component_to_string | Write text used in a component to a mutable |
encode_component_to_vec | Write text used in a component to a mutable |
encode_component_to_writer | Write text used in a component to a writer. |
encode_fragment | Encode text used in a fragment part. |
encode_fragment_to_string | Write text used in a fragment part to a mutable |
encode_fragment_to_vec | Write text used in a fragment part to a mutable |
encode_fragment_to_writer | Write text used in a fragment part to a writer. |
encode_path | Encode text used in the path part. |
encode_path_to_string | Write text used in the path part to a mutable |
encode_path_to_vec | Write text used in the path part to a mutable |
encode_path_to_writer | Write text used in the path part to a writer. |
encode_query | Encode text used in the query part. |
encode_query_to_string | Write text used in the query part to a mutable |
encode_query_to_vec | Write text used in the query part to a mutable |
encode_query_to_writer | Write text used in the query part to a writer. |
encode_special_query | Encode text used in the query part. |
encode_special_query_to_string | Write text used in the query part to a mutable |
encode_special_query_to_vec | Write text used in the query part to a mutable |
encode_special_query_to_writer | Write text used in the query part to a writer. |
encode_to_string | Write text to a mutable |
encode_to_vec | Write text to a mutable |
encode_to_writer | Write text to a writer. |
encode_userinfo | Encode text used in the userinfo part. |
encode_userinfo_to_string | Write text used in the userinfo part to a mutable |
encode_userinfo_to_vec | Write text used in the userinfo part to a mutable |
encode_userinfo_to_writer | Write text used in the userinfo part to a writer. |
encode_www_form_urlencoded | Encode text as a www-form-urlencoded text. |
encode_www_form_urlencoded_to_string | Write text as a urlencoded text to a mutable |
encode_www_form_urlencoded_to_vec | Write text as a www-form-urlencoded text to a mutable |
encode_www_form_urlencoded_to_writer | Write text as a www-form-urlencoded text to a writer. |