The simd optimized html escaping code
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
benches
v_escape
v_escape_derive
v_htmlescape
v_latexescape
v_shellescape
.gitignore
.travis.yml
Cargo.toml
LICENSE-APACHE initial release Dec 2, 2018
LICENSE-MIT
README.md
appveyor.yml

README.md

v_escape Documentation Latest version codecov Build status Windows build

The simd optimized escape code

Crate v_escape provides two macros, new_escape! and new_escape_sized!, that define a struct with escaping functionalities. These macros are optimized using simd by default, but this can be alter using sub-attributes.

Quick start

In order to use v_escape you will have to call one of the two macros to create a escape struct. In this example, when using the macro new_escape!(MyEscape, "62->bar"); a new a struct MyEscape will be created that every time its method MyEscape::fmt is called will replace all characters ">" with "bar".

#[macro_use]
extern crate v_escape;

new_escape_sized!(MyEscape, "62->bar");

fn main() {
    let s = "foo<bar";
    let escaped = MyEscape::from(s);
    
    print!("#{} : {}", escaped.size(), escaped);
}

To check if rust version has simd functionality. The following code has to be added to file build.rs.

use version_check::is_min_version;

fn main() {
    enable_simd_optimizations();
}

fn enable_simd_optimizations() {
    if !is_min_version("1.27.0").map_or(false, |(yes, _)| yes) {
        println!("cargo:rustc-cfg=v_escape_nosimd");
    }
}