Giter Club home page Giter Club logo

rust_urlencoding's Introduction

urlencoding

Latest Version

A tiny Rust library for doing URL percentage encoding and decoding. It percent-encodes everything except alphanumerics and -, _, ., ~.

When decoding + is not treated as a space. Error recovery from incomplete percent-escapes follows the WHATWG URL standard.

Usage

To encode a string, do the following:

use urlencoding::encode;

let encoded = encode("This string will be URL encoded.");
println!("{}", encoded);
// This%20string%20will%20be%20URL%20encoded.

To decode a string, it's only slightly different:

use urlencoding::decode;

let decoded = decode("%F0%9F%91%BE%20Exterminate%21")?;
println!("{}", decoded);
// ๐Ÿ‘พ Exterminate!

To decode allowing arbitrary bytes and invalid UTF-8:

use urlencoding::decode_binary;

let binary = decode_binary(b"%F1%F2%F3%C0%C1%C2");
let decoded = String::from_utf8_lossy(&binary);

This library returns Cow to avoid allocating when decoding/encoding is not needed. Call .into_owned() on the Cow to get a Vec or String.

License

This project is licensed under the MIT license. For more information see the LICENSE file.

rust_urlencoding's People

Contributors

kornelski avatar bt avatar jdudish avatar smalls0098 avatar themadprofessor avatar nabijaczleweli avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.