Macro word_filter::_replace_graphemes_with[][src]

macro_rules! _replace_graphemes_with {
    ($s : literal) => { ... };
}
Expand description

Creates a censor replacing every grapheme with the given string.

Example

Assuming a compile-time constructed WordFilter FILTER, defined in a build.rs as:

use std::{
    env,
    fs::File,
    io::{BufWriter, Write},
    path::Path,
};
use word_filter_codegen::WordFilterGenerator;

fn main() {
    let path = Path::new(&env::var("OUT_DIR").unwrap()).join("codegen.rs");
    let mut file = BufWriter::new(File::create(&path).unwrap());

    writeln!(
        &mut file,
        "{}",
        WordFilterGenerator::new()
            .word("fõõ")
            .generate("FILTER")
        );
}

a custom censor function can be used as follows:

include!(concat!(env!("OUT_DIR"), "/codegen.rs"));

assert!(
    FILTER.censor_with("this string contains fõõ", censor::replace_graphemes_with("#")),
    "this string contains ###"
);