v_jsonescape 0.9.0

The simd optimized JSON escaping code
Documentation
//! autogenerated by v_escape_codegen@0.2.1
//!
//! # `v_jsonescape`
//!
//! Autogenerated escape crate produced by
//! [`v_escape_codegen`](https://crates.io/crates/v_escape_codegen) on top of the
//! [`v_escape-base`](https://crates.io/crates/v_escape-base) runtime.
//!
//! ## Behavior
//!
//! Each call rewrites the characters listed in the table below into their
//! replacement string; every other byte of the input is forwarded verbatim.
//! All public entry points take a `&str` (UTF-8 guaranteed at the type level),
//! so they cannot be used to construct invalid UTF-8.
//!
//! ## Escape table
//!
//! | Byte (hex) | Source | Replacement |
//! | ---------- | ------ | ----------- |
//! | `0x00` | `<0x00>` | `\u0000` |
//! | `0x01` | `<0x01>` | `\u0001` |
//! | `0x02` | `<0x02>` | `\u0002` |
//! | `0x03` | `<0x03>` | `\u0003` |
//! | `0x04` | `<0x04>` | `\u0004` |
//! | `0x05` | `<0x05>` | `\u0005` |
//! | `0x06` | `<0x06>` | `\u0006` |
//! | `0x07` | `<0x07>` | `\u0007` |
//! | `0x08` | `<0x08>` | `\b` |
//! | `0x09` | `<0x09>` | `\t` |
//! | `0x0A` | `<0x0A>` | `\n` |
//! | `0x0B` | `<0x0B>` | `\u000b` |
//! | `0x0C` | `<0x0C>` | `\f` |
//! | `0x0D` | `<0x0D>` | `\r` |
//! | `0x0E` | `<0x0E>` | `\u000e` |
//! | `0x0F` | `<0x0F>` | `\u000f` |
//! | `0x10` | `<0x10>` | `\u0010` |
//! | `0x11` | `<0x11>` | `\u0011` |
//! | `0x12` | `<0x12>` | `\u0012` |
//! | `0x13` | `<0x13>` | `\u0013` |
//! | `0x14` | `<0x14>` | `\u0014` |
//! | `0x15` | `<0x15>` | `\u0015` |
//! | `0x16` | `<0x16>` | `\u0016` |
//! | `0x17` | `<0x17>` | `\u0017` |
//! | `0x18` | `<0x18>` | `\u0018` |
//! | `0x19` | `<0x19>` | `\u0019` |
//! | `0x1A` | `<0x1A>` | `\u001a` |
//! | `0x1B` | `<0x1B>` | `\u001b` |
//! | `0x1C` | `<0x1C>` | `\u001c` |
//! | `0x1D` | `<0x1D>` | `\u001d` |
//! | `0x1E` | `<0x1E>` | `\u001e` |
//! | `0x1F` | `<0x1F>` | `\u001f` |
//! | `0x22` | `"` | `\"` |
//! | `0x5C` | `\` | `\\` |
//!
//! ## Public API
//!
//! The following functions are emitted, gated by their respective Cargo
//! features (all enabled by default):
//!
//! | Function | Feature | Signature |
//! | -------- | ------- | --------- |
//! | `escape_string` | `string` | `fn(&str, &mut String)` |
//! | `escape_bytes`  | `bytes`  | `fn(&str, &mut Vec<u8>)` |
//! | `escape_fmt`    | `fmt`    | `fn(&str) -> impl Display + '_` |
//!
//! At runtime the implementation dispatches to the best SIMD backend
//! available on the current CPU (AVX2/SSE2 on x86_64, NEON on aarch64,
//! `simd128` on wasm32) and falls back to a scalar loop otherwise.
//!
static V_ESCAPE_CHARS: [u8; 256] = [
    0u8, 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u8, 9u8, 10u8, 11u8, 12u8, 13u8, 14u8, 15u8, 16u8,
    17u8, 18u8, 19u8, 20u8, 21u8, 22u8, 23u8, 24u8, 25u8, 26u8, 27u8, 28u8, 29u8, 30u8, 31u8, 34u8,
    34u8, 32u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8,
    34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8,
    34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8,
    34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 33u8, 34u8, 34u8, 34u8, 34u8,
    34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8,
    34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8,
    34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8,
    34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8,
    34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8,
    34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8,
    34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8,
    34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8,
    34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8,
    34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8, 34u8,
];
static V_ESCAPE_QUOTES: [&str; 34usize] = [
    "\\u0000", "\\u0001", "\\u0002", "\\u0003", "\\u0004", "\\u0005", "\\u0006", "\\u0007", "\\b",
    "\\t", "\\n", "\\u000b", "\\f", "\\r", "\\u000e", "\\u000f", "\\u0010", "\\u0011", "\\u0012",
    "\\u0013", "\\u0014", "\\u0015", "\\u0016", "\\u0017", "\\u0018", "\\u0019", "\\u001a",
    "\\u001b", "\\u001c", "\\u001d", "\\u001e", "\\u001f", "\\\"", "\\\\",
];
const V_ESCAPE_LEN: usize = 34usize;
use v_escape_base::{Escapes, EscapesBuilder, Vector, escape_builder};
#[derive(Debug, Clone, Copy)]
struct Escape<V: Vector> {
    translation_a: V,
    below_a: V,
    b: V,
    c: V,
}
#[allow(dead_code)]
struct Builder;
impl EscapesBuilder for Builder {
    type Escapes<V: Vector> = Escape<V>;
    fn new<V: Vector>() -> Self::Escapes<V> {
        Self::Escapes {
            translation_a: V::splat(96i8 as u8),
            below_a: V::splat(95i8 as u8),
            b: V::splat(34i8 as u8),
            c: V::splat(92i8 as u8),
        }
    }
}
impl<V: Vector> Escapes for Escape<V> {
    const ESCAPE_LEN: usize = 34usize;
    const FALSE_POSITIVE: bool = false;
    type Vector = V;
    #[inline(always)]
    fn masking(&self, vector2: V) -> V {
        vector2
            .add(self.translation_a)
            .gt(self.below_a)
            .or(vector2.cmpeq(self.b))
            .or(vector2.cmpeq(self.c))
    }
    #[inline(always)]
    fn escape(i: usize) -> &'static str {
        V_ESCAPE_QUOTES[i]
    }
    #[inline(always)]
    fn position(i: u8) -> usize {
        V_ESCAPE_CHARS[i as usize] as usize
    }
    #[inline(always)]
    fn byte_byte_compare(c: u8) -> bool {
        (V_ESCAPE_CHARS[c as usize] as usize) < V_ESCAPE_LEN
    }
}
escape_builder!(Builder);