v_escape_base/lib.rs
1//! A crate for escaping strings
2//!
3//! # Features
4//!
5//! - `std`: Enable standard library features
6//! - `alloc`: Enable alloc crate features
7//! - `string`: Enable `escape_string` function
8//! - `fmt`: Enable `escape_fmt` function
9//!
10//! # Examples
11//!
12//! ```rust
13//! use v_escape_base::{escape_builder, Escapes, EscapesBuilder, Vector};
14//!
15//! #[derive(Debug, Clone, Copy)]
16//! struct Equal<V: Vector> {
17//! a: V,
18//! }
19//!
20//! struct Builder;
21//! impl EscapesBuilder for Builder {
22//! type Escapes<V: Vector> = Equal<V>;
23//!
24//! fn new<V: Vector>() -> Self::Escapes<V> {
25//! Equal { a: V::splat(b'a') }
26//! }
27//! }
28//!
29//! impl<V: Vector> Escapes for Equal<V> {
30//! const ESCAPE_LEN: usize = 1;
31//!
32//! const FALSE_POSITIVE: bool = false;
33//!
34//! type Vector = V;
35//!
36//! #[inline(always)]
37//! fn masking(&self, vector2: V) -> V {
38//! self.a.cmpeq(vector2)
39//! }
40//!
41//! #[inline(always)]
42//! fn escape(_: usize) -> &'static str {
43//! "foo"
44//! }
45//!
46//! #[inline(always)]
47//! fn position(_: u8) -> usize {
48//! 0
49//! }
50//!
51//! #[inline(always)]
52//! fn byte_byte_compare(c: u8) -> bool {
53//! c == b'a'
54//! }
55//! }
56//!
57//! escape_builder!(Builder);
58//!
59//! let mut buffer = String::new();
60//! let haystack = "a".repeat(64);
61//! # #[cfg(feature = "string")]
62//! escape_string(&haystack, &mut buffer);
63//! # #[cfg(feature = "string")]
64//! assert_eq!(buffer, "foo".repeat(64));
65//!
66//! let haystack = "a".repeat(64);
67//! # #[cfg(feature = "fmt")]
68//! assert_eq!(escape_fmt(&haystack).to_string(), "foo".repeat(64));
69//! ```
70#![deny(missing_docs)]
71#![no_std]
72
73/// A module for standard library
74#[cfg(any(test, feature = "std"))]
75extern crate std;
76
77/// A module for alloc crate
78#[cfg(any(test, feature = "alloc"))]
79extern crate alloc;
80
81/// A module for architecture-specific escape functions
82#[macro_use]
83pub mod arch;
84
85/// A module for escapes
86mod escapes;
87
88/// A module for extensions
89mod ext;
90
91/// A module for generic escape functions
92mod generic;
93mod vector;
94#[macro_use]
95mod writer;
96
97pub use escapes::{Escapes, EscapesBuilder};
98pub use vector::Vector;