88 lines
10 KiB
HTML
88 lines
10 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `v_escape` crate."><meta name="keywords" content="rust, rustlang, rust-lang, v_escape"><title>v_escape - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../dark.css"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script src="../storage.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="shortcut icon" href="../favicon.ico"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../v_escape/index.html'><div class='logo-container'><img src='../rust-logo.png' alt='logo'></div></a><p class='location'>Crate v_escape</p><div class="sidebar-elems"><a id='all-types' href='all.html'><p>See all v_escape's items</p></a><div class="block items"><ul><li><a href="#macros">Macros</a></li></ul></div><p class='location'></p><script>window.sidebarCurrent = {name: 'v_escape', ty: 'mod', relpath: '../'};</script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>−</span>]</a></span><a class='srclink' href='../src/v_escape/lib.rs.html#1-319' title='goto source code'>[src]</a></span><span class='in-band'>Crate <a class="mod" href=''>v_escape</a></span></h1><div class='docblock'><p>Crate v_escape provides a macro, <code>new_escape!</code> that define a <code>struct</code> with
|
||
escaping functionality. These macros are optimized using simd by default,
|
||
but this can be alter using sub-attributes.</p>
|
||
<h1 id="quick-start" class="section-header"><a href="#quick-start">Quick start</a></h1>
|
||
<p>In order to use v_escape you will have to call one of the two macros
|
||
to create a escape <code>struct</code>. In this example, when using the macro
|
||
<code>new_escape!(MyEscape, "62->bar");</code> a new a <code>struct</code> <code>MyEscape</code>
|
||
will be created that every time its method <code>MyEscape::fmt</code> is called
|
||
will replace all characters <code>">"</code> with <code>"bar"</code>.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="attribute">#[<span class="ident">macro_use</span>]</span>
|
||
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">v_escape</span>;
|
||
|
||
<span class="macro">new_escape</span><span class="macro">!</span>(<span class="ident">MyEscape</span>, <span class="string">"62->bar"</span>);
|
||
|
||
<span class="kw">let</span> <span class="ident">escaped</span> <span class="op">=</span> <span class="ident">escape</span>(<span class="ident">s</span>);
|
||
|
||
<span class="macro">print</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">escaped</span>);</pre></div>
|
||
<h2 id="pairs-syntax" class="section-header"><a href="#pairs-syntax">Pairs syntax</a></h2>
|
||
<p>v_escape uses a simple syntax to replace characters
|
||
with their respective quotes. The tuple is named <code>Pair</code>,
|
||
and several can be defined, referred as <code>Pairs</code>. The syntax to define
|
||
<code>Pairs</code> consists of a character, followed
|
||
by the delimiter <code>-></code>, followed by the substitution quote
|
||
and the delimiter <code>||</code> (last delimiter is optional):</p>
|
||
<p><code>([character]->[quote] || )*</code></p>
|
||
<ul>
|
||
<li>
|
||
<p><code>character</code> : Character to substitute. Accepts<code>i8+</code> from <code>0</code> to <code>i8::MAX</code> and
|
||
accepts the following formats: decimal (49), hexadecimal (0x31),
|
||
octal (0o61) or character (#1).
|
||
Note: Numbers are read in ASCII: <code>#6->foo</code></p>
|
||
</li>
|
||
<li>
|
||
<p><code>quote</code> : Characters that will replace <code>character</code></p>
|
||
</li>
|
||
</ul>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="macro">new_escape</span><span class="macro">!</span>(<span class="ident">MyEscape</span>, <span class="string">"49->bar"</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">escape</span>(<span class="string">"foo 1"</span>).<span class="ident">to_string</span>(), <span class="string">"foo bar"</span>);</pre></div>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="macro">new_escape</span><span class="macro">!</span>(<span class="ident">MyEscape</span>, <span class="string">"0x31->bar"</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">escape</span>(<span class="string">"foo 1"</span>).<span class="ident">to_string</span>(), <span class="string">"foo bar"</span>);</pre></div>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="macro">new_escape</span><span class="macro">!</span>(<span class="ident">MyEscape</span>, <span class="string">"0o61->bar"</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">escape</span>(<span class="string">"foo 1"</span>).<span class="ident">to_string</span>(), <span class="string">"foo bar"</span>);</pre></div>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="macro">new_escape</span><span class="macro">!</span>(<span class="ident">MyEscape</span>, <span class="string">"#1->bar"</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">escape</span>(<span class="string">"foo 1"</span>).<span class="ident">to_string</span>(), <span class="string">"foo bar"</span>);</pre></div>
|
||
<p><code>ranges</code> refers to a possible optimization that when given a number of pairs,
|
||
an optimal number of ranges (with a maximum of three) are calculated and used
|
||
to escape all bytes within each range. It is possible the existence of false
|
||
positives, and will be discarded. If a lot of pairs have to be discarded
|
||
sub-attribute <code>ranges</code> must be explicitly disabled. In the case that more than
|
||
three bytes are used and the distance between the escaped characters is very
|
||
large, then <code>ranges = false</code>.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="macro">new_escape</span><span class="macro">!</span>(<span class="ident">MyEscape</span>, <span class="string">"0-> || 33->foo || 66->bar || 127->"</span>, <span class="ident">ranges</span> <span class="op">=</span> <span class="bool-val">false</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">escape</span>(<span class="string">"fooBbar"</span>).<span class="ident">to_string</span>(), <span class="string">"foobarbar"</span>);</pre></div>
|
||
<p>In the following example more than 16 pairs are given, this exceeds simd's
|
||
boundary. If simd optimization is wanted, ranges must be enabled (default)
|
||
or an error will be thrown. It is possible to not use ranges but simd
|
||
optimization has to be disabled.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="macro">new_escape</span><span class="macro">!</span>(
|
||
<span class="ident">MyEscape</span>,
|
||
<span class="string">"62->b || 60->f || B->b || 65->f || 0o67->b || #6->f || 68->b || \
|
||
71->f || 72->b || 73->f || 74->b || 75->f || 76->b || 77->f || \
|
||
78->b || 79->f || 0x1A->f"</span>
|
||
);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">escape</span>(<span class="string">"foo>bar<"</span>).<span class="ident">to_string</span>(), <span class="string">"foobbarf"</span>);</pre></div>
|
||
<p>For debugging purposes, sub-attribute <code>print</code>, can be set to <code>true</code>
|
||
to print generated code</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="macro">new_escape</span><span class="macro">!</span>(<span class="ident">MyEscape</span>, <span class="string">"o->bar"</span>, <span class="ident">print</span> <span class="op">=</span> <span class="bool-val">true</span>);</pre></div>
|
||
</div><h2 id='macros' class='section-header'><a href="#macros">Macros</a></h2>
|
||
<table><tr class='module-item'><td><a class="macro" href="macro.loop_range_switch_avx2.html" title='v_escape::loop_range_switch_avx2 macro'>loop_range_switch_avx2</a></td><td class='docblock-short'><p>Generate ranges avx2 implementation</p>
|
||
</td></tr><tr class='module-item'><td><a class="macro" href="macro.loop_range_switch_sse2.html" title='v_escape::loop_range_switch_sse2 macro'>loop_range_switch_sse2</a></td><td class='docblock-short'><p>Generate ranges sse2 implementation</p>
|
||
</td></tr><tr class='module-item'><td><a class="macro" href="macro.new_escape.html" title='v_escape::new_escape macro'>new_escape</a></td><td class='docblock-short'><p>Generates struct <code>$name</code> with escaping functionality at <code>fmt</code></p>
|
||
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../";window.currentCrate = "v_escape";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html> |