Revision as of 08:02, 20 February 2021 by Legoktm (talk | contribs) (Created page with "<source lang="rust"> fn encode_uri_component(component: &str) -> String { use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS}; const COMPONENT: &AsciiSet =...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Rust/encodeURIComponent

From Legoktm
fn encode_uri_component(component: &str) -> String {
    use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS};
    const COMPONENT: &AsciiSet = &CONTROLS
        // query set
        .add(b' ')
        .add(b'"')
        //.add(b'#')
        .add(b'<')
        .add(b'>')
        // path set
        .add(b'?')
        .add(b'`')
        .add(b'{')
        .add(b'}')
        // userinfo set
        .add(b'/')
        .add(b':')
        .add(b';')
        .add(b'=')
        .add(b'@')
        .add(b'[')
        .add(b'\\')
        .add(b']')
        .add(b'^')
        // component set
        .add(b'$')
        .add(b'%')
        .add(b'&')
        .add(b'+')
        .add(b',');
    utf8_percent_encode(component, COMPONENT).to_string()
}