Files
mercator_service/v_escape/index.html

88 lines
10 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!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">&#9776;</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'>&#x2212;</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, &quot;62-&gt;bar&quot;);</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>&quot;&gt;&quot;</code> with <code>&quot;bar&quot;</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">&quot;62-&gt;bar&quot;</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">&quot;{}&quot;</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>-&gt;</code>, followed by the substitution quote
and the delimiter <code>||</code> (last delimiter is optional):</p>
<p><code>([character]-&gt;[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-&gt;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">&quot;49-&gt;bar&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">escape</span>(<span class="string">&quot;foo 1&quot;</span>).<span class="ident">to_string</span>(), <span class="string">&quot;foo bar&quot;</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">&quot;0x31-&gt;bar&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">escape</span>(<span class="string">&quot;foo 1&quot;</span>).<span class="ident">to_string</span>(), <span class="string">&quot;foo bar&quot;</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">&quot;0o61-&gt;bar&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">escape</span>(<span class="string">&quot;foo 1&quot;</span>).<span class="ident">to_string</span>(), <span class="string">&quot;foo bar&quot;</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">&quot;#1-&gt;bar&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">escape</span>(<span class="string">&quot;foo 1&quot;</span>).<span class="ident">to_string</span>(), <span class="string">&quot;foo bar&quot;</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">&quot;0-&gt; || 33-&gt;foo || 66-&gt;bar || 127-&gt;&quot;</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">&quot;fooBbar&quot;</span>).<span class="ident">to_string</span>(), <span class="string">&quot;foobarbar&quot;</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">&quot;62-&gt;b || 60-&gt;f || B-&gt;b || 65-&gt;f || 0o67-&gt;b || #6-&gt;f || 68-&gt;b || \
71-&gt;f || 72-&gt;b || 73-&gt;f || 74-&gt;b || 75-&gt;f || 76-&gt;b || 77-&gt;f || \
78-&gt;b || 79-&gt;f || 0x1A-&gt;f&quot;</span>
);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">escape</span>(<span class="string">&quot;foo&gt;bar&lt;&quot;</span>).<span class="ident">to_string</span>(), <span class="string">&quot;foobbarf&quot;</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">&quot;o-&gt;bar&quot;</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>