diff options
author | 2015-06-29 20:16:15 +0000 | |
---|---|---|
committer | 2015-06-29 20:16:15 +0000 | |
commit | 64106c4d3d4ddba8c7bc2af75376e6d3d3d75601 (patch) | |
tree | 8c64d6e8be006486d975a651505fbbde61365cd6 /openssl/x509/struct.SslString.html | |
download | irsc-gh-pages.tar.gz irsc-gh-pages.tar.xz irsc-gh-pages.zip |
Update documentationgh-pages
Diffstat (limited to 'openssl/x509/struct.SslString.html')
-rw-r--r-- | openssl/x509/struct.SslString.html | 1170 |
1 files changed, 1170 insertions, 0 deletions
diff --git a/openssl/x509/struct.SslString.html b/openssl/x509/struct.SslString.html new file mode 100644 index 0000000..7d907a3 --- /dev/null +++ b/openssl/x509/struct.SslString.html @@ -0,0 +1,1170 @@ +<!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 `SslString` struct in crate `openssl`."> + <meta name="keywords" content="rust, rustlang, rust-lang, SslString"> + + <title>openssl::x509::SslString - Rust</title> + + <link rel="stylesheet" type="text/css" href="../../main.css"> + + + +</head> +<body class="rustdoc"> + <!--[if lte IE 8]> + <div class="warning"> + This old browser is unsupported and will most likely display funky + things. + </div> + <![endif]--> + + + + <section class="sidebar"> + + <p class='location'><a href='../index.html'>openssl</a>::<wbr><a href='index.html'>x509</a></p><script>window.sidebarCurrent = {name: 'SslString', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script> + </section> + + <nav class="sub"> + <form class="search-form js-only"> + <div class="search-container"> + <input class="search-input" name="search" + autocomplete="off" + placeholder="Click or press 'S' to search, '?' for more options..." + type="search"> + </div> + </form> + </nav> + + <section id='main' class="content struct"> +<h1 class='fqn'><span class='in-band'>Struct <a href='../index.html'>openssl</a>::<wbr><a href='index.html'>x509</a>::<wbr><a class='struct' href=''>SslString</a></span><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 id='src-13896' class='srclink' href='../../src/openssl/x509/mod.rs.html#27-29' title='goto source code'>[src]</a></span></h1> +<pre class='rust struct'>pub struct SslString { + // some fields omitted +}</pre><h2 id='deref-methods'>Methods from <a class='trait' href='http://doc.rust-lang.org/nightly/core/ops/trait.Deref.html' title='core::ops::Deref'>Deref</a><Target=<a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>></h2><div class='impl-items'><h4 id='method.len' class='method'><code>fn <a href='#method.len' class='fnname'>len</a>(&self) -> <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a></code></h4> +<div class='docblock'><p>Returns the length of <code>self</code> in bytes.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='string'>"foo"</span>.<span class='ident'>len</span>(), <span class='number'>3</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='string'>"ƒoo"</span>.<span class='ident'>len</span>(), <span class='number'>4</span>); <span class='comment'>// fancy f!</span> +</pre> +</div><h4 id='method.is_empty' class='method'><code>fn <a href='#method.is_empty' class='fnname'>is_empty</a>(&self) -> <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a></code></h4> +<div class='docblock'><p>Returns true if this slice has a length of zero bytes.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='macro'>assert</span><span class='macro'>!</span>(<span class='string'>""</span>.<span class='ident'>is_empty</span>()); +</pre> +</div><h4 id='method.width' class='method'><code>fn <a href='#method.width' class='fnname'>width</a>(&self, is_cjk: <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a>) -> <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a></code></h4> +<div class='stability'><em class='stab unstable deprecated'>Deprecated since 1.0.0<p>: use the crates.io <code>unicode-width</code> library instead</p> +</em></div><div class='docblock'><p>Returns a string's displayed width in columns.</p> + +<p>Control characters have zero width.</p> + +<p><code>is_cjk</code> determines behavior for characters in the Ambiguous category: +if <code>is_cjk</code> is +<code>true</code>, these are 2 columns wide; otherwise, they are 1. +In CJK locales, <code>is_cjk</code> should be +<code>true</code>, else it should be <code>false</code>. +<a href="http://www.unicode.org/reports/tr11/">Unicode Standard Annex #11</a> +recommends that these +characters be treated as 1 column (i.e., <code>is_cjk = false</code>) if the +locale is unknown.</p> +</div><h4 id='method.is_char_boundary' class='method'><code>fn <a href='#method.is_char_boundary' class='fnname'>is_char_boundary</a>(&self, index: <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>) -> <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a></code></h4> +<div class='stability'><em class='stab unstable'>Unstable<p>: it is unclear whether this method pulls its weight with the existence of the char_indices iterator or this method may want to be replaced with checked slicing</p> +</em></div><div class='docblock'><p>Checks that <code>index</code>-th byte lies at the start and/or end of a +UTF-8 code point sequence.</p> + +<p>The start and end of the string (when <code>index == self.len()</code>) are +considered to be +boundaries.</p> + +<h1 id="panics" class='section-header'><a + href="#panics">Panics</a></h1> +<p>Panics if <code>index</code> is greater than <code>self.len()</code>.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"Löwe 老虎 Léopard"</span>; +<span class='macro'>assert</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>is_char_boundary</span>(<span class='number'>0</span>)); +<span class='comment'>// start of `老`</span> +<span class='macro'>assert</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>is_char_boundary</span>(<span class='number'>6</span>)); +<span class='macro'>assert</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>is_char_boundary</span>(<span class='ident'>s</span>.<span class='ident'>len</span>())); + +<span class='comment'>// second byte of `ö`</span> +<span class='macro'>assert</span><span class='macro'>!</span>(<span class='op'>!</span><span class='ident'>s</span>.<span class='ident'>is_char_boundary</span>(<span class='number'>2</span>)); + +<span class='comment'>// third byte of `老`</span> +<span class='macro'>assert</span><span class='macro'>!</span>(<span class='op'>!</span><span class='ident'>s</span>.<span class='ident'>is_char_boundary</span>(<span class='number'>8</span>)); +</pre> +</div><h4 id='method.as_bytes' class='method'><code>fn <a href='#method.as_bytes' class='fnname'>as_bytes</a>(&self) -> <a href='http://doc.rust-lang.org/nightly/std/primitive.slice.html'>&[</a><a href='http://doc.rust-lang.org/nightly/std/primitive.u8.html'>u8</a><a href='http://doc.rust-lang.org/nightly/std/primitive.slice.html'>]</a></code></h4> +<div class='docblock'><p>Converts <code>self</code> to a byte slice.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='string'>"bors"</span>.<span class='ident'>as_bytes</span>(), <span class='string'>b"bors"</span>); +</pre> +</div><h4 id='method.as_ptr' class='method'><code>fn <a href='#method.as_ptr' class='fnname'>as_ptr</a>(&self) -> <a href='http://doc.rust-lang.org/nightly/std/primitive.pointer.html'>*const <a href='http://doc.rust-lang.org/nightly/std/primitive.u8.html'>u8</a></a></code></h4> +<div class='docblock'><p>Returns a raw pointer to the <code>&str</code>'s buffer.</p> + +<p>The caller must ensure that the string outlives this pointer, and +that it is not +reallocated (e.g. by pushing to the string).</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"Hello"</span>; +<span class='kw'>let</span> <span class='ident'>p</span> <span class='op'>=</span> <span class='ident'>s</span>.<span class='ident'>as_ptr</span>(); +</pre> +</div><h4 id='method.slice_unchecked' class='method'><code>unsafe fn <a href='#method.slice_unchecked' class='fnname'>slice_unchecked</a>(&self, begin: <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>, end: <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>) -> &<a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a></code></h4> +<div class='docblock'><p>Takes a bytewise slice from a string.</p> + +<p>Returns the substring from [<code>begin</code>..<code>end</code>).</p> + +<h1 id="unsafety" class='section-header'><a + href="#unsafety">Unsafety</a></h1> +<p>Caller must check both UTF-8 character boundaries and the boundaries +of the entire slice as +well.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"Löwe 老虎 Léopard"</span>; + +<span class='kw'>unsafe</span> { + <span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>slice_unchecked</span>(<span class='number'>0</span>, <span class='number'>21</span>), <span class='string'>"Löwe 老虎 Léopard"</span>); +} +</pre> +</div><h4 id='method.slice_chars' class='method'><code>fn <a href='#method.slice_chars' class='fnname'>slice_chars</a>(&self, begin: <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>, end: <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>) -> &<a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a></code></h4> +<div class='stability'><em class='stab unstable'>Unstable<p>: may have yet to prove its worth</p> +</em></div><div class='docblock'><p>Returns a slice of the string from the character range [<code>begin</code>..<code>end</code>).</p> + +<p>That is, start at the <code>begin</code>-th code point of the string and continue +to the <code>end</code>-th code point. This does not detect or handle edge cases +such as leaving a combining character as the first code point of the +string.</p> + +<p>Due to the design of UTF-8, this operation is <code>O(end)</code>. Use slicing +syntax if you want to use byte indices rather than codepoint indices.</p> + +<h1 id="panics" class='section-header'><a + href="#panics">Panics</a></h1> +<p>Panics if <code>begin</code> > <code>end</code> or the either <code>begin</code> or <code>end</code> are beyond the +last character of the string.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"Löwe 老虎 Léopard"</span>; + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>slice_chars</span>(<span class='number'>0</span>, <span class='number'>4</span>), <span class='string'>"Löwe"</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>slice_chars</span>(<span class='number'>5</span>, <span class='number'>7</span>), <span class='string'>"老虎"</span>); +</pre> +</div><h4 id='method.char_range_at' class='method'><code>fn <a href='#method.char_range_at' class='fnname'>char_range_at</a>(&self, start: <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>) -> <a class='struct' href='http://doc.rust-lang.org/nightly/core/str/struct.CharRange.html' title='core::str::CharRange'>CharRange</a></code></h4> +<div class='stability'><em class='stab unstable'>Unstable<p>: often replaced by char_indices, this method may be removed in favor of just char_at() or eventually removed altogether</p> +</em></div><div class='docblock'><p>Given a byte position, return the next char and its index.</p> + +<p>This can be used to iterate over the Unicode characters of a string.</p> + +<h1 id="panics" class='section-header'><a + href="#panics">Panics</a></h1> +<p>If <code>i</code> is greater than or equal to the length of the string. +If <code>i</code> is not the index of the beginning of a valid UTF-8 character.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1> +<p>This example manually iterates through the characters of a string; +this should normally be +done by <code>.chars()</code> or <code>.char_indices()</code>.</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>str</span>::<span class='ident'>CharRange</span>; + +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"中华Việt Nam"</span>; +<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>i</span> <span class='op'>=</span> <span class='number'>0</span>; +<span class='kw'>while</span> <span class='ident'>i</span> <span class='op'><</span> <span class='ident'>s</span>.<span class='ident'>len</span>() { + <span class='kw'>let</span> <span class='ident'>CharRange</span> {<span class='ident'>ch</span>, <span class='ident'>next</span>} <span class='op'>=</span> <span class='ident'>s</span>.<span class='ident'>char_range_at</span>(<span class='ident'>i</span>); + <span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{}: {}"</span>, <span class='ident'>i</span>, <span class='ident'>ch</span>); + <span class='ident'>i</span> <span class='op'>=</span> <span class='ident'>next</span>; +} +</pre> + +<p>This outputs:</p> + +<pre><code class="language-text">0: 中 +3: 华 +6: V +7: i +8: ệ +11: t +12: +13: N +14: a +15: m +</code></pre> +</div><h4 id='method.char_range_at_reverse' class='method'><code>fn <a href='#method.char_range_at_reverse' class='fnname'>char_range_at_reverse</a>(&self, start: <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>) -> <a class='struct' href='http://doc.rust-lang.org/nightly/core/str/struct.CharRange.html' title='core::str::CharRange'>CharRange</a></code></h4> +<div class='stability'><em class='stab unstable'>Unstable<p>: often replaced by char_indices, this method may be removed in favor of just char_at_reverse() or eventually removed altogether</p> +</em></div><div class='docblock'><p>Given a byte position, return the previous <code>char</code> and its position.</p> + +<p>This function can be used to iterate over a Unicode string in reverse.</p> + +<p>Returns 0 for next index if called on start index 0.</p> + +<h1 id="panics" class='section-header'><a + href="#panics">Panics</a></h1> +<p>If <code>i</code> is greater than the length of the string. +If <code>i</code> is not an index following a valid UTF-8 character.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1> +<p>This example manually iterates through the characters of a string; +this should normally be +done by <code>.chars().rev()</code> or <code>.char_indices()</code>.</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>str</span>::<span class='ident'>CharRange</span>; + +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"中华Việt Nam"</span>; +<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>i</span> <span class='op'>=</span> <span class='ident'>s</span>.<span class='ident'>len</span>(); +<span class='kw'>while</span> <span class='ident'>i</span> <span class='op'>></span> <span class='number'>0</span> { + <span class='kw'>let</span> <span class='ident'>CharRange</span> {<span class='ident'>ch</span>, <span class='ident'>next</span>} <span class='op'>=</span> <span class='ident'>s</span>.<span class='ident'>char_range_at_reverse</span>(<span class='ident'>i</span>); + <span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>"{}: {}"</span>, <span class='ident'>i</span>, <span class='ident'>ch</span>); + <span class='ident'>i</span> <span class='op'>=</span> <span class='ident'>next</span>; +} +</pre> + +<p>This outputs:</p> + +<pre><code class="language-text">16: m +15: a +14: N +13: +12: t +11: ệ +8: i +7: V +6: 华 +3: 中 +</code></pre> +</div><h4 id='method.char_at' class='method'><code>fn <a href='#method.char_at' class='fnname'>char_at</a>(&self, i: <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>) -> <a href='http://doc.rust-lang.org/nightly/std/primitive.char.html'>char</a></code></h4> +<div class='stability'><em class='stab unstable'>Unstable<p>: frequently replaced by the chars() iterator, this method may be removed or possibly renamed in the future; it is normally replaced by chars/char_indices iterators or by getting the first char from a subslice</p> +</em></div><div class='docblock'><p>Given a byte position, return the <code>char</code> at that position.</p> + +<h1 id="panics" class='section-header'><a + href="#panics">Panics</a></h1> +<p>If <code>i</code> is greater than or equal to the length of the string. +If <code>i</code> is not the index of the beginning of a valid UTF-8 character.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"abπc"</span>; +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>char_at</span>(<span class='number'>1</span>), <span class='string'>'b'</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>char_at</span>(<span class='number'>2</span>), <span class='string'>'π'</span>); +</pre> +</div><h4 id='method.char_at_reverse' class='method'><code>fn <a href='#method.char_at_reverse' class='fnname'>char_at_reverse</a>(&self, i: <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>) -> <a href='http://doc.rust-lang.org/nightly/std/primitive.char.html'>char</a></code></h4> +<div class='stability'><em class='stab unstable'>Unstable<p>: see char_at for more details, but reverse semantics are also somewhat unclear, especially with which cases generate panics</p> +</em></div><div class='docblock'><p>Given a byte position, return the <code>char</code> at that position, counting +from the end.</p> + +<h1 id="panics" class='section-header'><a + href="#panics">Panics</a></h1> +<p>If <code>i</code> is greater than the length of the string. +If <code>i</code> is not an index following a valid UTF-8 character.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"abπc"</span>; +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>char_at_reverse</span>(<span class='number'>1</span>), <span class='string'>'a'</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>char_at_reverse</span>(<span class='number'>2</span>), <span class='string'>'b'</span>); +</pre> +</div><h4 id='method.slice_shift_char' class='method'><code>fn <a href='#method.slice_shift_char' class='fnname'>slice_shift_char</a>(&self) -> <a class='enum' href='http://doc.rust-lang.org/nightly/core/option/enum.Option.html' title='core::option::Option'>Option</a><<a href='http://doc.rust-lang.org/nightly/std/primitive.tuple.html'>(<a href='http://doc.rust-lang.org/nightly/std/primitive.char.html'>char</a>, &<a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>)</a>></code></h4> +<div class='stability'><em class='stab unstable'>Unstable<p>: awaiting conventions about shifting and slices and may not be warranted with the existence of the chars and/or char_indices iterators</p> +</em></div><div class='docblock'><p>Retrieves the first character from a <code>&str</code> and returns it.</p> + +<p>This does not allocate a new string; instead, it returns a slice that +points one character +beyond the character that was shifted.</p> + +<p>If the slice does not contain any characters, None is returned instead.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"Löwe 老虎 Léopard"</span>; +<span class='kw'>let</span> (<span class='ident'>c</span>, <span class='ident'>s1</span>) <span class='op'>=</span> <span class='ident'>s</span>.<span class='ident'>slice_shift_char</span>().<span class='ident'>unwrap</span>(); + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>c</span>, <span class='string'>'L'</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s1</span>, <span class='string'>"öwe 老虎 Léopard"</span>); + +<span class='kw'>let</span> (<span class='ident'>c</span>, <span class='ident'>s2</span>) <span class='op'>=</span> <span class='ident'>s1</span>.<span class='ident'>slice_shift_char</span>().<span class='ident'>unwrap</span>(); + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>c</span>, <span class='string'>'ö'</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s2</span>, <span class='string'>"we 老虎 Léopard"</span>); +</pre> +</div><h4 id='method.split_at' class='method'><code>fn <a href='#method.split_at' class='fnname'>split_at</a>(&self, mid: <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>) -> <a href='http://doc.rust-lang.org/nightly/std/primitive.tuple.html'>(&<a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>, &<a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>)</a></code></h4> +<div class='stability'><em class='stab unstable'>Unstable<p>: library is unlikely to be stabilized with the current layout and name, use std::collections instead</p> +</em></div><div class='docblock'><p>Divide one string slice into two at an index.</p> + +<p>The index <code>mid</code> is a byte offset from the start of the string +that must be on a character boundary.</p> + +<p>Return slices <code>&self[..mid]</code> and <code>&self[mid..]</code>.</p> + +<h1 id="panics" class='section-header'><a + href="#panics">Panics</a></h1> +<p>Panics if <code>mid</code> is beyond the last character of the string, +or if it is not on a character boundary.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"Löwe 老虎 Léopard"</span>; +<span class='kw'>let</span> <span class='ident'>first_space</span> <span class='op'>=</span> <span class='ident'>s</span>.<span class='ident'>find</span>(<span class='string'>' '</span>).<span class='ident'>unwrap_or</span>(<span class='ident'>s</span>.<span class='ident'>len</span>()); +<span class='kw'>let</span> (<span class='ident'>a</span>, <span class='ident'>b</span>) <span class='op'>=</span> <span class='ident'>s</span>.<span class='ident'>split_at</span>(<span class='ident'>first_space</span>); + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>a</span>, <span class='string'>"Löwe"</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>b</span>, <span class='string'>" 老虎 Léopard"</span>); +</pre> +</div><h4 id='method.chars' class='method'><code>fn <a href='#method.chars' class='fnname'>chars</a>(&self) -> <a class='struct' href='http://doc.rust-lang.org/nightly/core/str/struct.Chars.html' title='core::str::Chars'>Chars</a></code></h4> +<div class='docblock'><p>An iterator over the codepoints of <code>self</code>.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='ident'>char</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"abc åäö"</span>.<span class='ident'>chars</span>().<span class='ident'>collect</span>(); + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>'a'</span>, <span class='string'>'b'</span>, <span class='string'>'c'</span>, <span class='string'>' '</span>, <span class='string'>'å'</span>, <span class='string'>'ä'</span>, <span class='string'>'ö'</span>]); +</pre> +</div><h4 id='method.char_indices' class='method'><code>fn <a href='#method.char_indices' class='fnname'>char_indices</a>(&self) -> <a class='struct' href='http://doc.rust-lang.org/nightly/core/str/struct.CharIndices.html' title='core::str::CharIndices'>CharIndices</a></code></h4> +<div class='docblock'><p>An iterator over the characters of <code>self</code> and their byte offsets.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span>(<span class='ident'>usize</span>, <span class='ident'>char</span>)<span class='op'>></span> <span class='op'>=</span> <span class='string'>"abc"</span>.<span class='ident'>char_indices</span>().<span class='ident'>collect</span>(); +<span class='kw'>let</span> <span class='ident'>b</span> <span class='op'>=</span> <span class='macro'>vec</span><span class='macro'>!</span>[(<span class='number'>0</span>, <span class='string'>'a'</span>), (<span class='number'>1</span>, <span class='string'>'b'</span>), (<span class='number'>2</span>, <span class='string'>'c'</span>)]; + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, <span class='ident'>b</span>); +</pre> +</div><h4 id='method.bytes' class='method'><code>fn <a href='#method.bytes' class='fnname'>bytes</a>(&self) -> <a class='struct' href='http://doc.rust-lang.org/nightly/core/str/struct.Bytes.html' title='core::str::Bytes'>Bytes</a></code></h4> +<div class='docblock'><p>An iterator over the bytes of <code>self</code>.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='ident'>u8</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"bors"</span>.<span class='ident'>bytes</span>().<span class='ident'>collect</span>(); + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, <span class='string'>b"bors"</span>.<span class='ident'>to_vec</span>()); +</pre> +</div><h4 id='method.split_whitespace' class='method'><code>fn <a href='#method.split_whitespace' class='fnname'>split_whitespace</a>(&self) -> <a class='struct' href='http://doc.rust-lang.org/nightly/rustc_unicode/u_str/struct.SplitWhitespace.html' title='rustc_unicode::u_str::SplitWhitespace'>SplitWhitespace</a></code></h4> +<div class='docblock'><p>An iterator over the non-empty substrings of <code>self</code> which contain no whitespace, +and which are separated by any amount of whitespace.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>some_words</span> <span class='op'>=</span> <span class='string'>" Mary had\ta little \n\t lamb"</span>; +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='ident'>some_words</span>.<span class='ident'>split_whitespace</span>().<span class='ident'>collect</span>(); + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"Mary"</span>, <span class='string'>"had"</span>, <span class='string'>"a"</span>, <span class='string'>"little"</span>, <span class='string'>"lamb"</span>]); +</pre> +</div><h4 id='method.words' class='method'><code>fn <a href='#method.words' class='fnname'>words</a>(&self) -> <a class='struct' href='http://doc.rust-lang.org/nightly/rustc_unicode/u_str/struct.SplitWhitespace.html' title='rustc_unicode::u_str::SplitWhitespace'>SplitWhitespace</a></code></h4> +<div class='stability'><em class='stab unstable deprecated'>Deprecated since 1.1.0<p>: words() will be removed. Use split_whitespace() instead</p> +</em></div><div class='docblock'><p>An iterator over the non-empty substrings of <code>self</code> which contain no whitespace, +and which are separated by any amount of whitespace.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>some_words</span> <span class='op'>=</span> <span class='string'>" Mary had\ta little \n\t lamb"</span>; +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='ident'>some_words</span>.<span class='ident'>words</span>().<span class='ident'>collect</span>(); + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"Mary"</span>, <span class='string'>"had"</span>, <span class='string'>"a"</span>, <span class='string'>"little"</span>, <span class='string'>"lamb"</span>]); +</pre> +</div><h4 id='method.lines' class='method'><code>fn <a href='#method.lines' class='fnname'>lines</a>(&self) -> <a class='struct' href='http://doc.rust-lang.org/nightly/core/str/struct.Lines.html' title='core::str::Lines'>Lines</a></code></h4> +<div class='docblock'><p>An iterator over the lines of a string, separated by <code>\n</code>.</p> + +<p>This does not include the empty string after a trailing <code>\n</code>.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>four_lines</span> <span class='op'>=</span> <span class='string'>"foo\nbar\n\nbaz"</span>; +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='ident'>four_lines</span>.<span class='ident'>lines</span>().<span class='ident'>collect</span>(); + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"foo"</span>, <span class='string'>"bar"</span>, <span class='string'>""</span>, <span class='string'>"baz"</span>]); +</pre> + +<p>Leaving off the trailing character:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>four_lines</span> <span class='op'>=</span> <span class='string'>"foo\nbar\n\nbaz\n"</span>; +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='ident'>four_lines</span>.<span class='ident'>lines</span>().<span class='ident'>collect</span>(); + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"foo"</span>, <span class='string'>"bar"</span>, <span class='string'>""</span>, <span class='string'>"baz"</span>]); +</pre> +</div><h4 id='method.lines_any' class='method'><code>fn <a href='#method.lines_any' class='fnname'>lines_any</a>(&self) -> <a class='struct' href='http://doc.rust-lang.org/nightly/core/str/struct.LinesAny.html' title='core::str::LinesAny'>LinesAny</a></code></h4> +<div class='docblock'><p>An iterator over the lines of a string, separated by either +<code>\n</code> or <code>\r\n</code>.</p> + +<p>As with <code>.lines()</code>, this does not include an empty trailing line.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>four_lines</span> <span class='op'>=</span> <span class='string'>"foo\r\nbar\n\r\nbaz"</span>; +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='ident'>four_lines</span>.<span class='ident'>lines_any</span>().<span class='ident'>collect</span>(); + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"foo"</span>, <span class='string'>"bar"</span>, <span class='string'>""</span>, <span class='string'>"baz"</span>]); +</pre> + +<p>Leaving off the trailing character:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>four_lines</span> <span class='op'>=</span> <span class='string'>"foo\r\nbar\n\r\nbaz\n"</span>; +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='ident'>four_lines</span>.<span class='ident'>lines_any</span>().<span class='ident'>collect</span>(); + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"foo"</span>, <span class='string'>"bar"</span>, <span class='string'>""</span>, <span class='string'>"baz"</span>]); +</pre> +</div><h4 id='method.nfd_chars' class='method'><code>fn <a href='#method.nfd_chars' class='fnname'>nfd_chars</a>(&self) -> <a class='struct' href='http://doc.rust-lang.org/nightly/collections/str/struct.Decompositions.html' title='collections::str::Decompositions'>Decompositions</a></code></h4> +<div class='stability'><em class='stab unstable deprecated'>Deprecated since 1.0.0<p>: use the crates.io <code>unicode-normalization</code> library instead</p> +</em></div><div class='docblock'><p>Returns an iterator over the string in Unicode Normalization Form D +(canonical decomposition).</p> +</div><h4 id='method.nfkd_chars' class='method'><code>fn <a href='#method.nfkd_chars' class='fnname'>nfkd_chars</a>(&self) -> <a class='struct' href='http://doc.rust-lang.org/nightly/collections/str/struct.Decompositions.html' title='collections::str::Decompositions'>Decompositions</a></code></h4> +<div class='stability'><em class='stab unstable deprecated'>Deprecated since 1.0.0<p>: use the crates.io <code>unicode-normalization</code> library instead</p> +</em></div><div class='docblock'><p>Returns an iterator over the string in Unicode Normalization Form KD +(compatibility decomposition).</p> +</div><h4 id='method.nfc_chars' class='method'><code>fn <a href='#method.nfc_chars' class='fnname'>nfc_chars</a>(&self) -> <a class='struct' href='http://doc.rust-lang.org/nightly/collections/str/struct.Recompositions.html' title='collections::str::Recompositions'>Recompositions</a></code></h4> +<div class='stability'><em class='stab unstable deprecated'>Deprecated since 1.0.0<p>: use the crates.io <code>unicode-normalization</code> library instead</p> +</em></div><div class='docblock'><p>An Iterator over the string in Unicode Normalization Form C +(canonical decomposition followed by canonical composition).</p> +</div><h4 id='method.nfkc_chars' class='method'><code>fn <a href='#method.nfkc_chars' class='fnname'>nfkc_chars</a>(&self) -> <a class='struct' href='http://doc.rust-lang.org/nightly/collections/str/struct.Recompositions.html' title='collections::str::Recompositions'>Recompositions</a></code></h4> +<div class='stability'><em class='stab unstable deprecated'>Deprecated since 1.0.0<p>: use the crates.io <code>unicode-normalization</code> library instead</p> +</em></div><div class='docblock'><p>An Iterator over the string in Unicode Normalization Form KC +(compatibility decomposition followed by canonical composition).</p> +</div><h4 id='method.graphemes' class='method'><code>fn <a href='#method.graphemes' class='fnname'>graphemes</a>(&self, is_extended: <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a>) -> <a class='struct' href='http://doc.rust-lang.org/nightly/rustc_unicode/u_str/struct.Graphemes.html' title='rustc_unicode::u_str::Graphemes'>Graphemes</a></code></h4> +<div class='stability'><em class='stab unstable deprecated'>Deprecated since 1.0.0<p>: use the crates.io <code>unicode-segmentation</code> library instead</p> +</em></div><div class='docblock'><p>Returns an iterator over the <a href="http://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries">grapheme clusters</a> of <code>self</code>.</p> + +<p>If <code>is_extended</code> is true, the iterator is over the +<em>extended grapheme clusters</em>; +otherwise, the iterator is over the <em>legacy grapheme clusters</em>. +<a href="http://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries">UAX#29</a> +recommends extended grapheme cluster boundaries for general processing.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>gr1</span> <span class='op'>=</span> <span class='string'>"a\u{310}e\u{301}o\u{308}\u{332}"</span>.<span class='ident'>graphemes</span>(<span class='boolval'>true</span>).<span class='ident'>collect</span>::<span class='op'><</span><span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>>></span>(); +<span class='kw'>let</span> <span class='ident'>b</span>: <span class='kw-2'>&</span>[_] <span class='op'>=</span> <span class='kw-2'>&</span>[<span class='string'>"a\u{310}"</span>, <span class='string'>"e\u{301}"</span>, <span class='string'>"o\u{308}\u{332}"</span>]; + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='kw-2'>&</span><span class='ident'>gr1</span>[..], <span class='ident'>b</span>); + +<span class='kw'>let</span> <span class='ident'>gr2</span> <span class='op'>=</span> <span class='string'>"a\r\nb🇷🇺🇸🇹"</span>.<span class='ident'>graphemes</span>(<span class='boolval'>true</span>).<span class='ident'>collect</span>::<span class='op'><</span><span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>>></span>(); +<span class='kw'>let</span> <span class='ident'>b</span>: <span class='kw-2'>&</span>[_] <span class='op'>=</span> <span class='kw-2'>&</span>[<span class='string'>"a"</span>, <span class='string'>"\r\n"</span>, <span class='string'>"b"</span>, <span class='string'>"🇷🇺🇸🇹"</span>]; + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='kw-2'>&</span><span class='ident'>gr2</span>[..], <span class='ident'>b</span>); +</pre> +</div><h4 id='method.grapheme_indices' class='method'><code>fn <a href='#method.grapheme_indices' class='fnname'>grapheme_indices</a>(&self, is_extended: <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a>) -> <a class='struct' href='http://doc.rust-lang.org/nightly/rustc_unicode/u_str/struct.GraphemeIndices.html' title='rustc_unicode::u_str::GraphemeIndices'>GraphemeIndices</a></code></h4> +<div class='stability'><em class='stab unstable deprecated'>Deprecated since 1.0.0<p>: use the crates.io <code>unicode-segmentation</code> library instead</p> +</em></div><div class='docblock'><p>Returns an iterator over the grapheme clusters of <code>self</code> and their +byte offsets. See +<code>graphemes()</code> for more information.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>gr_inds</span> <span class='op'>=</span> <span class='string'>"a̐éö̲\r\n"</span>.<span class='ident'>grapheme_indices</span>(<span class='boolval'>true</span>).<span class='ident'>collect</span>::<span class='op'><</span><span class='ident'>Vec</span><span class='op'><</span>(<span class='ident'>usize</span>, <span class='kw-2'>&</span><span class='ident'>str</span>)<span class='op'>>></span>(); +<span class='kw'>let</span> <span class='ident'>b</span>: <span class='kw-2'>&</span>[_] <span class='op'>=</span> <span class='kw-2'>&</span>[(<span class='number'>0</span>, <span class='string'>"a̐"</span>), (<span class='number'>3</span>, <span class='string'>"é"</span>), (<span class='number'>6</span>, <span class='string'>"ö̲"</span>), (<span class='number'>11</span>, <span class='string'>"\r\n"</span>)]; + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='kw-2'>&</span><span class='ident'>gr_inds</span>[..], <span class='ident'>b</span>); +</pre> +</div><h4 id='method.utf16_units' class='method'><code>fn <a href='#method.utf16_units' class='fnname'>utf16_units</a>(&self) -> <a class='struct' href='http://doc.rust-lang.org/nightly/collections/str/struct.Utf16Units.html' title='collections::str::Utf16Units'>Utf16Units</a></code></h4> +<div class='stability'><em class='stab unstable'>Unstable<p>: this functionality may only be provided by libunicode</p> +</em></div><div class='docblock'><p>Returns an iterator of <code>u16</code> over the string encoded as UTF-16.</p> +</div><h4 id='method.contains' class='method'><code>fn <a href='#method.contains' class='fnname'>contains</a><'a, P>(&'a self, pat: P) -> <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a> <span class='where'>where P: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Pattern</a><'a></span></code></h4> +<div class='docblock'><p>Returns <code>true</code> if <code>self</code> contains another <code>&str</code>.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='macro'>assert</span><span class='macro'>!</span>(<span class='string'>"bananas"</span>.<span class='ident'>contains</span>(<span class='string'>"nana"</span>)); + +<span class='macro'>assert</span><span class='macro'>!</span>(<span class='op'>!</span><span class='string'>"bananas"</span>.<span class='ident'>contains</span>(<span class='string'>"foobar"</span>)); +</pre> +</div><h4 id='method.starts_with' class='method'><code>fn <a href='#method.starts_with' class='fnname'>starts_with</a><'a, P>(&'a self, pat: P) -> <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a> <span class='where'>where P: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Pattern</a><'a></span></code></h4> +<div class='docblock'><p>Returns <code>true</code> if the given <code>&str</code> is a prefix of the string.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='macro'>assert</span><span class='macro'>!</span>(<span class='string'>"banana"</span>.<span class='ident'>starts_with</span>(<span class='string'>"ba"</span>)); +</pre> +</div><h4 id='method.ends_with' class='method'><code>fn <a href='#method.ends_with' class='fnname'>ends_with</a><'a, P>(&'a self, pat: P) -> <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a> <span class='where'>where P: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Pattern</a><'a>, P::<a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Searcher</a>: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.ReverseSearcher.html' title='core::str::pattern::ReverseSearcher'>ReverseSearcher</a><'a></span></code></h4> +<div class='docblock'><p>Returns true if the given <code>&str</code> is a suffix of the string.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='macro'>assert</span><span class='macro'>!</span>(<span class='string'>"banana"</span>.<span class='ident'>ends_with</span>(<span class='string'>"nana"</span>)); +</pre> +</div><h4 id='method.find' class='method'><code>fn <a href='#method.find' class='fnname'>find</a><'a, P>(&'a self, pat: P) -> <a class='enum' href='http://doc.rust-lang.org/nightly/core/option/enum.Option.html' title='core::option::Option'>Option</a><<a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>> <span class='where'>where P: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Pattern</a><'a></span></code></h4> +<div class='docblock'><p>Returns the byte index of the first character of <code>self</code> that matches +the pattern, if it +exists.</p> + +<p>Returns <code>None</code> if it doesn't exist.</p> + +<p>The pattern can be a simple <code>&str</code>, <code>char</code>, or a closure that +determines the +split.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1> +<p>Simple patterns:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"Löwe 老虎 Léopard"</span>; + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>find</span>(<span class='string'>'L'</span>), <span class='prelude-val'>Some</span>(<span class='number'>0</span>)); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>find</span>(<span class='string'>'é'</span>), <span class='prelude-val'>Some</span>(<span class='number'>14</span>)); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>find</span>(<span class='string'>"Léopard"</span>), <span class='prelude-val'>Some</span>(<span class='number'>13</span>)); +</pre> + +<p>More complex patterns with closures:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"Löwe 老虎 Léopard"</span>; + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>find</span>(<span class='ident'>char</span>::<span class='ident'>is_whitespace</span>), <span class='prelude-val'>Some</span>(<span class='number'>5</span>)); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>find</span>(<span class='ident'>char</span>::<span class='ident'>is_lowercase</span>), <span class='prelude-val'>Some</span>(<span class='number'>1</span>)); +</pre> + +<p>Not finding the pattern:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"Löwe 老虎 Léopard"</span>; +<span class='kw'>let</span> <span class='ident'>x</span>: <span class='kw-2'>&</span>[_] <span class='op'>=</span> <span class='kw-2'>&</span>[<span class='string'>'1'</span>, <span class='string'>'2'</span>]; + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>find</span>(<span class='ident'>x</span>), <span class='prelude-val'>None</span>); +</pre> +</div><h4 id='method.rfind' class='method'><code>fn <a href='#method.rfind' class='fnname'>rfind</a><'a, P>(&'a self, pat: P) -> <a class='enum' href='http://doc.rust-lang.org/nightly/core/option/enum.Option.html' title='core::option::Option'>Option</a><<a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>> <span class='where'>where P: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Pattern</a><'a>, P::<a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Searcher</a>: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.ReverseSearcher.html' title='core::str::pattern::ReverseSearcher'>ReverseSearcher</a><'a></span></code></h4> +<div class='docblock'><p>Returns the byte index of the last character of <code>self</code> that +matches the pattern, if it +exists.</p> + +<p>Returns <code>None</code> if it doesn't exist.</p> + +<p>The pattern can be a simple <code>&str</code>, <code>char</code>, +or a closure that determines the split.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1> +<p>Simple patterns:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"Löwe 老虎 Léopard"</span>; + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>rfind</span>(<span class='string'>'L'</span>), <span class='prelude-val'>Some</span>(<span class='number'>13</span>)); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>rfind</span>(<span class='string'>'é'</span>), <span class='prelude-val'>Some</span>(<span class='number'>14</span>)); +</pre> + +<p>More complex patterns with closures:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"Löwe 老虎 Léopard"</span>; + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>rfind</span>(<span class='ident'>char</span>::<span class='ident'>is_whitespace</span>), <span class='prelude-val'>Some</span>(<span class='number'>12</span>)); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>rfind</span>(<span class='ident'>char</span>::<span class='ident'>is_lowercase</span>), <span class='prelude-val'>Some</span>(<span class='number'>20</span>)); +</pre> + +<p>Not finding the pattern:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"Löwe 老虎 Léopard"</span>; +<span class='kw'>let</span> <span class='ident'>x</span>: <span class='kw-2'>&</span>[_] <span class='op'>=</span> <span class='kw-2'>&</span>[<span class='string'>'1'</span>, <span class='string'>'2'</span>]; + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>rfind</span>(<span class='ident'>x</span>), <span class='prelude-val'>None</span>); +</pre> +</div><h4 id='method.split' class='method'><code>fn <a href='#method.split' class='fnname'>split</a><'a, P>(&'a self, pat: P) -> <a class='struct' href='http://doc.rust-lang.org/nightly/core/str/struct.Split.html' title='core::str::Split'>Split</a><'a, P> <span class='where'>where P: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Pattern</a><'a></span></code></h4> +<div class='docblock'><p>An iterator over substrings of <code>self</code>, separated by characters +matched by a pattern.</p> + +<p>The pattern can be a simple <code>&str</code>, <code>char</code>, or a closure that +determines the split. Additional libraries might provide more complex +patterns like regular expressions.</p> + +<h1 id="iterator-behavior" class='section-header'><a + href="#iterator-behavior">Iterator behavior</a></h1> +<p>The returned iterator will be double ended if the pattern allows a +reverse search and forward/reverse search yields the same elements. +This is true for, eg, <code>char</code> but not +for <code>&str</code>.</p> + +<p>If the pattern allows a reverse search but its results might differ +from a forward search, <code>rsplit()</code> can be used.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1> +<p>Simple patterns:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"Mary had a little lamb"</span>.<span class='ident'>split</span>(<span class='string'>' '</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"Mary"</span>, <span class='string'>"had"</span>, <span class='string'>"a"</span>, <span class='string'>"little"</span>, <span class='string'>"lamb"</span>]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>""</span>.<span class='ident'>split</span>(<span class='string'>'X'</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>""</span>]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"lionXXtigerXleopard"</span>.<span class='ident'>split</span>(<span class='string'>'X'</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"lion"</span>, <span class='string'>""</span>, <span class='string'>"tiger"</span>, <span class='string'>"leopard"</span>]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"lion::tiger::leopard"</span>.<span class='ident'>split</span>(<span class='string'>"::"</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"lion"</span>, <span class='string'>"tiger"</span>, <span class='string'>"leopard"</span>]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"abc1def2ghi"</span>.<span class='ident'>split</span>(<span class='ident'>char</span>::<span class='ident'>is_numeric</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"abc"</span>, <span class='string'>"def"</span>, <span class='string'>"ghi"</span>]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"lionXtigerXleopard"</span>.<span class='ident'>split</span>(<span class='ident'>char</span>::<span class='ident'>is_uppercase</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"lion"</span>, <span class='string'>"tiger"</span>, <span class='string'>"leopard"</span>]); +</pre> + +<p>A more complex pattern, using a closure:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"abc1defXghi"</span>.<span class='ident'>split</span>(<span class='op'>|</span><span class='ident'>c</span><span class='op'>|</span> <span class='ident'>c</span> <span class='op'>==</span> <span class='string'>'1'</span> <span class='op'>||</span> <span class='ident'>c</span> <span class='op'>==</span> <span class='string'>'X'</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"abc"</span>, <span class='string'>"def"</span>, <span class='string'>"ghi"</span>]); +</pre> + +<p>If a string contains multiple contiguous separators, you will end up +with empty strings in the output:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>x</span> <span class='op'>=</span> <span class='string'>"||||a||b|c"</span>.<span class='ident'>to_string</span>(); +<span class='kw'>let</span> <span class='ident'>d</span>: <span class='ident'>Vec</span><span class='op'><</span>_<span class='op'>></span> <span class='op'>=</span> <span class='ident'>x</span>.<span class='ident'>split</span>(<span class='string'>'|'</span>).<span class='ident'>collect</span>(); + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>d</span>, <span class='kw-2'>&</span>[<span class='string'>""</span>, <span class='string'>""</span>, <span class='string'>""</span>, <span class='string'>""</span>, <span class='string'>"a"</span>, <span class='string'>""</span>, <span class='string'>"b"</span>, <span class='string'>"c"</span>]); +</pre> + +<p>This can lead to possibly surprising behavior when whitespace is used +as the separator. This code is correct:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>x</span> <span class='op'>=</span> <span class='string'>" a b c"</span>.<span class='ident'>to_string</span>(); +<span class='kw'>let</span> <span class='ident'>d</span>: <span class='ident'>Vec</span><span class='op'><</span>_<span class='op'>></span> <span class='op'>=</span> <span class='ident'>x</span>.<span class='ident'>split</span>(<span class='string'>' '</span>).<span class='ident'>collect</span>(); + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>d</span>, <span class='kw-2'>&</span>[<span class='string'>""</span>, <span class='string'>""</span>, <span class='string'>""</span>, <span class='string'>""</span>, <span class='string'>"a"</span>, <span class='string'>""</span>, <span class='string'>"b"</span>, <span class='string'>"c"</span>]); +</pre> + +<p>It does <em>not</em> give you:</p> +<pre class='rust rust-example-rendered'> +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>d</span>, <span class='kw-2'>&</span>[<span class='string'>"a"</span>, <span class='string'>"b"</span>, <span class='string'>"c"</span>]); +</pre> +</div><h4 id='method.rsplit' class='method'><code>fn <a href='#method.rsplit' class='fnname'>rsplit</a><'a, P>(&'a self, pat: P) -> <a class='struct' href='http://doc.rust-lang.org/nightly/core/str/struct.RSplit.html' title='core::str::RSplit'>RSplit</a><'a, P> <span class='where'>where P: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Pattern</a><'a>, P::<a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Searcher</a>: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.ReverseSearcher.html' title='core::str::pattern::ReverseSearcher'>ReverseSearcher</a><'a></span></code></h4> +<div class='docblock'><p>An iterator over substrings of <code>self</code>, separated by characters +matched by a pattern and yielded in reverse order.</p> + +<p>The pattern can be a simple <code>&str</code>, <code>char</code>, or a closure that +determines the split. +Additional libraries might provide more complex patterns like +regular expressions.</p> + +<h1 id="iterator-behavior" class='section-header'><a + href="#iterator-behavior">Iterator behavior</a></h1> +<p>The returned iterator requires that the pattern supports a +reverse search, +and it will be double ended if a forward/reverse search yields +the same elements.</p> + +<p>For iterating from the front, <code>split()</code> can be used.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1> +<p>Simple patterns:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"Mary had a little lamb"</span>.<span class='ident'>rsplit</span>(<span class='string'>' '</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"lamb"</span>, <span class='string'>"little"</span>, <span class='string'>"a"</span>, <span class='string'>"had"</span>, <span class='string'>"Mary"</span>]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>""</span>.<span class='ident'>rsplit</span>(<span class='string'>'X'</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>""</span>]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"lionXXtigerXleopard"</span>.<span class='ident'>rsplit</span>(<span class='string'>'X'</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"leopard"</span>, <span class='string'>"tiger"</span>, <span class='string'>""</span>, <span class='string'>"lion"</span>]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"lion::tiger::leopard"</span>.<span class='ident'>rsplit</span>(<span class='string'>"::"</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"leopard"</span>, <span class='string'>"tiger"</span>, <span class='string'>"lion"</span>]); +</pre> + +<p>A more complex pattern, using a closure:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"abc1defXghi"</span>.<span class='ident'>rsplit</span>(<span class='op'>|</span><span class='ident'>c</span><span class='op'>|</span> <span class='ident'>c</span> <span class='op'>==</span> <span class='string'>'1'</span> <span class='op'>||</span> <span class='ident'>c</span> <span class='op'>==</span> <span class='string'>'X'</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"ghi"</span>, <span class='string'>"def"</span>, <span class='string'>"abc"</span>]); +</pre> +</div><h4 id='method.split_terminator' class='method'><code>fn <a href='#method.split_terminator' class='fnname'>split_terminator</a><'a, P>(&'a self, pat: P) -> <a class='struct' href='http://doc.rust-lang.org/nightly/core/str/struct.SplitTerminator.html' title='core::str::SplitTerminator'>SplitTerminator</a><'a, P> <span class='where'>where P: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Pattern</a><'a></span></code></h4> +<div class='docblock'><p>An iterator over substrings of <code>self</code>, separated by characters +matched by a pattern.</p> + +<p>The pattern can be a simple <code>&str</code>, <code>char</code>, or a closure that +determines the split. +Additional libraries might provide more complex patterns +like regular expressions.</p> + +<p>Equivalent to <code>split</code>, except that the trailing substring +is skipped if empty.</p> + +<p>This method can be used for string data that is <em>terminated</em>, +rather than <em>separated</em> by a pattern.</p> + +<h1 id="iterator-behavior" class='section-header'><a + href="#iterator-behavior">Iterator behavior</a></h1> +<p>The returned iterator will be double ended if the pattern allows a +reverse search +and forward/reverse search yields the same elements. This is true +for, eg, <code>char</code> but not for <code>&str</code>.</p> + +<p>If the pattern allows a reverse search but its results might differ +from a forward search, <code>rsplit_terminator()</code> can be used.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"A.B."</span>.<span class='ident'>split_terminator</span>(<span class='string'>'.'</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"A"</span>, <span class='string'>"B"</span>]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"A..B.."</span>.<span class='ident'>split_terminator</span>(<span class='string'>"."</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"A"</span>, <span class='string'>""</span>, <span class='string'>"B"</span>, <span class='string'>""</span>]); +</pre> +</div><h4 id='method.rsplit_terminator' class='method'><code>fn <a href='#method.rsplit_terminator' class='fnname'>rsplit_terminator</a><'a, P>(&'a self, pat: P) -> <a class='struct' href='http://doc.rust-lang.org/nightly/core/str/struct.RSplitTerminator.html' title='core::str::RSplitTerminator'>RSplitTerminator</a><'a, P> <span class='where'>where P: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Pattern</a><'a>, P::<a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Searcher</a>: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.ReverseSearcher.html' title='core::str::pattern::ReverseSearcher'>ReverseSearcher</a><'a></span></code></h4> +<div class='docblock'><p>An iterator over substrings of <code>self</code>, separated by characters +matched by a pattern and yielded in reverse order.</p> + +<p>The pattern can be a simple <code>&str</code>, <code>char</code>, or a closure that +determines the split. +Additional libraries might provide more complex patterns like +regular expressions.</p> + +<p>Equivalent to <code>split</code>, except that the trailing substring is +skipped if empty.</p> + +<p>This method can be used for string data that is <em>terminated</em>, +rather than <em>separated</em> by a pattern.</p> + +<h1 id="iterator-behavior" class='section-header'><a + href="#iterator-behavior">Iterator behavior</a></h1> +<p>The returned iterator requires that the pattern supports a +reverse search, and it will be double ended if a forward/reverse +search yields the same elements.</p> + +<p>For iterating from the front, <code>split_terminator()</code> can be used.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"A.B."</span>.<span class='ident'>rsplit_terminator</span>(<span class='string'>'.'</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"B"</span>, <span class='string'>"A"</span>]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"A..B.."</span>.<span class='ident'>rsplit_terminator</span>(<span class='string'>"."</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>""</span>, <span class='string'>"B"</span>, <span class='string'>""</span>, <span class='string'>"A"</span>]); +</pre> +</div><h4 id='method.splitn' class='method'><code>fn <a href='#method.splitn' class='fnname'>splitn</a><'a, P>(&'a self, count: <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>, pat: P) -> <a class='struct' href='http://doc.rust-lang.org/nightly/core/str/struct.SplitN.html' title='core::str::SplitN'>SplitN</a><'a, P> <span class='where'>where P: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Pattern</a><'a></span></code></h4> +<div class='docblock'><p>An iterator over substrings of <code>self</code>, separated by a pattern, +restricted to returning +at most <code>count</code> items.</p> + +<p>The last element returned, if any, will contain the remainder of the +string. +The pattern can be a simple <code>&str</code>, <code>char</code>, or a closure that +determines the split. +Additional libraries might provide more complex patterns like +regular expressions.</p> + +<h1 id="iterator-behavior" class='section-header'><a + href="#iterator-behavior">Iterator behavior</a></h1> +<p>The returned iterator will not be double ended, because it is +not efficient to support.</p> + +<p>If the pattern allows a reverse search, <code>rsplitn()</code> can be used.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1> +<p>Simple patterns:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"Mary had a little lambda"</span>.<span class='ident'>splitn</span>(<span class='number'>3</span>, <span class='string'>' '</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"Mary"</span>, <span class='string'>"had"</span>, <span class='string'>"a little lambda"</span>]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"lionXXtigerXleopard"</span>.<span class='ident'>splitn</span>(<span class='number'>3</span>, <span class='string'>"X"</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"lion"</span>, <span class='string'>""</span>, <span class='string'>"tigerXleopard"</span>]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"abcXdef"</span>.<span class='ident'>splitn</span>(<span class='number'>1</span>, <span class='string'>'X'</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"abcXdef"</span>]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>""</span>.<span class='ident'>splitn</span>(<span class='number'>1</span>, <span class='string'>'X'</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>""</span>]); +</pre> + +<p>A more complex pattern, using a closure:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"abc1defXghi"</span>.<span class='ident'>splitn</span>(<span class='number'>2</span>, <span class='op'>|</span><span class='ident'>c</span><span class='op'>|</span> <span class='ident'>c</span> <span class='op'>==</span> <span class='string'>'1'</span> <span class='op'>||</span> <span class='ident'>c</span> <span class='op'>==</span> <span class='string'>'X'</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"abc"</span>, <span class='string'>"defXghi"</span>]); +</pre> +</div><h4 id='method.rsplitn' class='method'><code>fn <a href='#method.rsplitn' class='fnname'>rsplitn</a><'a, P>(&'a self, count: <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>, pat: P) -> <a class='struct' href='http://doc.rust-lang.org/nightly/core/str/struct.RSplitN.html' title='core::str::RSplitN'>RSplitN</a><'a, P> <span class='where'>where P: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Pattern</a><'a>, P::<a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Searcher</a>: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.ReverseSearcher.html' title='core::str::pattern::ReverseSearcher'>ReverseSearcher</a><'a></span></code></h4> +<div class='docblock'><p>An iterator over substrings of <code>self</code>, separated by a pattern, +starting from the end of the string, restricted to returning +at most <code>count</code> items.</p> + +<p>The last element returned, if any, will contain the remainder of the +string.</p> + +<p>The pattern can be a simple <code>&str</code>, <code>char</code>, or a closure that +determines the split. +Additional libraries might provide more complex patterns like +regular expressions.</p> + +<h1 id="iterator-behavior" class='section-header'><a + href="#iterator-behavior">Iterator behavior</a></h1> +<p>The returned iterator will not be double ended, because it is not +efficient to support.</p> + +<p><code>splitn()</code> can be used for splitting from the front.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1> +<p>Simple patterns:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"Mary had a little lamb"</span>.<span class='ident'>rsplitn</span>(<span class='number'>3</span>, <span class='string'>' '</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"lamb"</span>, <span class='string'>"little"</span>, <span class='string'>"Mary had a"</span>]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"lionXXtigerXleopard"</span>.<span class='ident'>rsplitn</span>(<span class='number'>3</span>, <span class='string'>'X'</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"leopard"</span>, <span class='string'>"tiger"</span>, <span class='string'>"lionX"</span>]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"lion::tiger::leopard"</span>.<span class='ident'>rsplitn</span>(<span class='number'>2</span>, <span class='string'>"::"</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"leopard"</span>, <span class='string'>"lion::tiger"</span>]); +</pre> + +<p>A more complex pattern, using a closure:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"abc1defXghi"</span>.<span class='ident'>rsplitn</span>(<span class='number'>2</span>, <span class='op'>|</span><span class='ident'>c</span><span class='op'>|</span> <span class='ident'>c</span> <span class='op'>==</span> <span class='string'>'1'</span> <span class='op'>||</span> <span class='ident'>c</span> <span class='op'>==</span> <span class='string'>'X'</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"ghi"</span>, <span class='string'>"abc1def"</span>]); +</pre> +</div><h4 id='method.matches' class='method'><code>fn <a href='#method.matches' class='fnname'>matches</a><'a, P>(&'a self, pat: P) -> <a class='struct' href='http://doc.rust-lang.org/nightly/core/str/struct.Matches.html' title='core::str::Matches'>Matches</a><'a, P> <span class='where'>where P: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Pattern</a><'a></span></code></h4> +<div class='docblock'><p>An iterator over the matches of a pattern within <code>self</code>.</p> + +<p>The pattern can be a simple <code>&str</code>, <code>char</code>, or a closure that +determines the split. +Additional libraries might provide more complex patterns like +regular expressions.</p> + +<h1 id="iterator-behavior" class='section-header'><a + href="#iterator-behavior">Iterator behavior</a></h1> +<p>The returned iterator will be double ended if the pattern allows +a reverse search +and forward/reverse search yields the same elements. This is true +for, eg, <code>char</code> but not +for <code>&str</code>.</p> + +<p>If the pattern allows a reverse search but its results might differ +from a forward search, <code>rmatches()</code> can be used.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"abcXXXabcYYYabc"</span>.<span class='ident'>matches</span>(<span class='string'>"abc"</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"abc"</span>, <span class='string'>"abc"</span>, <span class='string'>"abc"</span>]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"1abc2abc3"</span>.<span class='ident'>matches</span>(<span class='ident'>char</span>::<span class='ident'>is_numeric</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"1"</span>, <span class='string'>"2"</span>, <span class='string'>"3"</span>]); +</pre> +</div><h4 id='method.rmatches' class='method'><code>fn <a href='#method.rmatches' class='fnname'>rmatches</a><'a, P>(&'a self, pat: P) -> <a class='struct' href='http://doc.rust-lang.org/nightly/core/str/struct.RMatches.html' title='core::str::RMatches'>RMatches</a><'a, P> <span class='where'>where P: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Pattern</a><'a>, P::<a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Searcher</a>: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.ReverseSearcher.html' title='core::str::pattern::ReverseSearcher'>ReverseSearcher</a><'a></span></code></h4> +<div class='docblock'><p>An iterator over the matches of a pattern within <code>self</code>, yielded in +reverse order.</p> + +<p>The pattern can be a simple <code>&str</code>, <code>char</code>, or a closure that +determines the split. +Additional libraries might provide more complex patterns like +regular expressions.</p> + +<h1 id="iterator-behavior" class='section-header'><a + href="#iterator-behavior">Iterator behavior</a></h1> +<p>The returned iterator requires that the pattern supports a +reverse search, +and it will be double ended if a forward/reverse search yields +the same elements.</p> + +<p>For iterating from the front, <code>matches()</code> can be used.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"abcXXXabcYYYabc"</span>.<span class='ident'>rmatches</span>(<span class='string'>"abc"</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"abc"</span>, <span class='string'>"abc"</span>, <span class='string'>"abc"</span>]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='string'>"1abc2abc3"</span>.<span class='ident'>rmatches</span>(<span class='ident'>char</span>::<span class='ident'>is_numeric</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [<span class='string'>"3"</span>, <span class='string'>"2"</span>, <span class='string'>"1"</span>]); +</pre> +</div><h4 id='method.match_indices' class='method'><code>fn <a href='#method.match_indices' class='fnname'>match_indices</a><'a, P>(&'a self, pat: P) -> <a class='struct' href='http://doc.rust-lang.org/nightly/core/str/struct.MatchIndices.html' title='core::str::MatchIndices'>MatchIndices</a><'a, P> <span class='where'>where P: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Pattern</a><'a></span></code></h4> +<div class='stability'><em class='stab unstable'>Unstable<p>: might have its iterator type changed</p> +</em></div><div class='docblock'><p>An iterator over the start and end indices of the disjoint matches +of a pattern within <code>self</code>.</p> + +<p>For matches of <code>pat</code> within <code>self</code> that overlap, only the indices +corresponding to the first +match are returned.</p> + +<p>The pattern can be a simple <code>&str</code>, <code>char</code>, or a closure that +determines +the split. +Additional libraries might provide more complex patterns like +regular expressions.</p> + +<h1 id="iterator-behavior" class='section-header'><a + href="#iterator-behavior">Iterator behavior</a></h1> +<p>The returned iterator will be double ended if the pattern allows a +reverse search +and forward/reverse search yields the same elements. This is true for, +eg, <code>char</code> but not +for <code>&str</code>.</p> + +<p>If the pattern allows a reverse search but its results might differ +from a forward search, <code>rmatch_indices()</code> can be used.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span>(<span class='ident'>usize</span>, <span class='ident'>usize</span>)<span class='op'>></span> <span class='op'>=</span> <span class='string'>"abcXXXabcYYYabc"</span>.<span class='ident'>match_indices</span>(<span class='string'>"abc"</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [(<span class='number'>0</span>, <span class='number'>3</span>), (<span class='number'>6</span>, <span class='number'>9</span>), (<span class='number'>12</span>, <span class='number'>15</span>)]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span>(<span class='ident'>usize</span>, <span class='ident'>usize</span>)<span class='op'>></span> <span class='op'>=</span> <span class='string'>"1abcabc2"</span>.<span class='ident'>match_indices</span>(<span class='string'>"abc"</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [(<span class='number'>1</span>, <span class='number'>4</span>), (<span class='number'>4</span>, <span class='number'>7</span>)]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span>(<span class='ident'>usize</span>, <span class='ident'>usize</span>)<span class='op'>></span> <span class='op'>=</span> <span class='string'>"ababa"</span>.<span class='ident'>match_indices</span>(<span class='string'>"aba"</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [(<span class='number'>0</span>, <span class='number'>3</span>)]); <span class='comment'>// only the first `aba`</span> +</pre> +</div><h4 id='method.rmatch_indices' class='method'><code>fn <a href='#method.rmatch_indices' class='fnname'>rmatch_indices</a><'a, P>(&'a self, pat: P) -> <a class='struct' href='http://doc.rust-lang.org/nightly/core/str/struct.RMatchIndices.html' title='core::str::RMatchIndices'>RMatchIndices</a><'a, P> <span class='where'>where P: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Pattern</a><'a>, P::<a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Searcher</a>: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.ReverseSearcher.html' title='core::str::pattern::ReverseSearcher'>ReverseSearcher</a><'a></span></code></h4> +<div class='stability'><em class='stab unstable'>Unstable<p>: might have its iterator type changed</p> +</em></div><div class='docblock'><p>An iterator over the start and end indices of the disjoint matches of +a pattern within +<code>self</code>, yielded in reverse order.</p> + +<p>For matches of <code>pat</code> within <code>self</code> that overlap, only the indices +corresponding to the last +match are returned.</p> + +<p>The pattern can be a simple <code>&str</code>, <code>char</code>, or a closure that +determines +the split. +Additional libraries might provide more complex patterns like +regular expressions.</p> + +<h1 id="iterator-behavior" class='section-header'><a + href="#iterator-behavior">Iterator behavior</a></h1> +<p>The returned iterator requires that the pattern supports a +reverse search, +and it will be double ended if a forward/reverse search yields +the same elements.</p> + +<p>For iterating from the front, <code>match_indices()</code> can be used.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span>(<span class='ident'>usize</span>, <span class='ident'>usize</span>)<span class='op'>></span> <span class='op'>=</span> <span class='string'>"abcXXXabcYYYabc"</span>.<span class='ident'>rmatch_indices</span>(<span class='string'>"abc"</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [(<span class='number'>12</span>, <span class='number'>15</span>), (<span class='number'>6</span>, <span class='number'>9</span>), (<span class='number'>0</span>, <span class='number'>3</span>)]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span>(<span class='ident'>usize</span>, <span class='ident'>usize</span>)<span class='op'>></span> <span class='op'>=</span> <span class='string'>"1abcabc2"</span>.<span class='ident'>rmatch_indices</span>(<span class='string'>"abc"</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [(<span class='number'>4</span>, <span class='number'>7</span>), (<span class='number'>1</span>, <span class='number'>4</span>)]); + +<span class='kw'>let</span> <span class='ident'>v</span>: <span class='ident'>Vec</span><span class='op'><</span>(<span class='ident'>usize</span>, <span class='ident'>usize</span>)<span class='op'>></span> <span class='op'>=</span> <span class='string'>"ababa"</span>.<span class='ident'>rmatch_indices</span>(<span class='string'>"aba"</span>).<span class='ident'>collect</span>(); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>v</span>, [(<span class='number'>2</span>, <span class='number'>5</span>)]); <span class='comment'>// only the last `aba`</span> +</pre> +</div><h4 id='method.subslice_offset' class='method'><code>fn <a href='#method.subslice_offset' class='fnname'>subslice_offset</a>(&self, inner: &<a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> <a href='http://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a></code></h4> +<div class='stability'><em class='stab unstable'>Unstable<p>: awaiting convention about comparability of arbitrary slices</p> +</em></div><div class='docblock'><p>Returns the byte offset of an inner slice relative to an enclosing +outer slice.</p> + +<h1 id="panics" class='section-header'><a + href="#panics">Panics</a></h1> +<p>Panics if <code>inner</code> is not a direct slice contained within self.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>string</span> <span class='op'>=</span> <span class='string'>"a\nb\nc"</span>; +<span class='kw'>let</span> <span class='ident'>lines</span>: <span class='ident'>Vec</span><span class='op'><</span><span class='kw-2'>&</span><span class='ident'>str</span><span class='op'>></span> <span class='op'>=</span> <span class='ident'>string</span>.<span class='ident'>lines</span>().<span class='ident'>collect</span>(); + +<span class='macro'>assert</span><span class='macro'>!</span>(<span class='ident'>string</span>.<span class='ident'>subslice_offset</span>(<span class='ident'>lines</span>[<span class='number'>0</span>]) <span class='op'>==</span> <span class='number'>0</span>); <span class='comment'>// &"a"</span> +<span class='macro'>assert</span><span class='macro'>!</span>(<span class='ident'>string</span>.<span class='ident'>subslice_offset</span>(<span class='ident'>lines</span>[<span class='number'>1</span>]) <span class='op'>==</span> <span class='number'>2</span>); <span class='comment'>// &"b"</span> +<span class='macro'>assert</span><span class='macro'>!</span>(<span class='ident'>string</span>.<span class='ident'>subslice_offset</span>(<span class='ident'>lines</span>[<span class='number'>2</span>]) <span class='op'>==</span> <span class='number'>4</span>); <span class='comment'>// &"c"</span> +</pre> +</div><h4 id='method.trim' class='method'><code>fn <a href='#method.trim' class='fnname'>trim</a>(&self) -> &<a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a></code></h4> +<div class='docblock'><p>Returns a <code>&str</code> with leading and trailing whitespace removed.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>" Hello\tworld\t"</span>; +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>trim</span>(), <span class='string'>"Hello\tworld"</span>); +</pre> +</div><h4 id='method.trim_left' class='method'><code>fn <a href='#method.trim_left' class='fnname'>trim_left</a>(&self) -> &<a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a></code></h4> +<div class='docblock'><p>Returns a <code>&str</code> with leading whitespace removed.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>" Hello\tworld\t"</span>; +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>trim_left</span>(), <span class='string'>"Hello\tworld\t"</span>); +</pre> +</div><h4 id='method.trim_right' class='method'><code>fn <a href='#method.trim_right' class='fnname'>trim_right</a>(&self) -> &<a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a></code></h4> +<div class='docblock'><p>Returns a <code>&str</code> with trailing whitespace removed.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>" Hello\tworld\t"</span>; +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>trim_right</span>(), <span class='string'>" Hello\tworld"</span>); +</pre> +</div><h4 id='method.trim_matches' class='method'><code>fn <a href='#method.trim_matches' class='fnname'>trim_matches</a><'a, P>(&'a self, pat: P) -> &'a <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a> <span class='where'>where P: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Pattern</a><'a>, P::<a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Searcher</a>: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.DoubleEndedSearcher.html' title='core::str::pattern::DoubleEndedSearcher'>DoubleEndedSearcher</a><'a></span></code></h4> +<div class='docblock'><p>Returns a string with all pre- and suffixes that match a pattern +repeatedly removed.</p> + +<p>The pattern can be a simple <code>char</code>, or a closure that determines +the split.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1> +<p>Simple patterns:</p> +<pre class='rust rust-example-rendered'> +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='string'>"11foo1bar11"</span>.<span class='ident'>trim_matches</span>(<span class='string'>'1'</span>), <span class='string'>"foo1bar"</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='string'>"123foo1bar123"</span>.<span class='ident'>trim_matches</span>(<span class='ident'>char</span>::<span class='ident'>is_numeric</span>), <span class='string'>"foo1bar"</span>); + +<span class='kw'>let</span> <span class='ident'>x</span>: <span class='kw-2'>&</span>[_] <span class='op'>=</span> <span class='kw-2'>&</span>[<span class='string'>'1'</span>, <span class='string'>'2'</span>]; +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='string'>"12foo1bar12"</span>.<span class='ident'>trim_matches</span>(<span class='ident'>x</span>), <span class='string'>"foo1bar"</span>); +</pre> + +<p>A more complex pattern, using a closure:</p> +<pre class='rust rust-example-rendered'> +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='string'>"1foo1barXX"</span>.<span class='ident'>trim_matches</span>(<span class='op'>|</span><span class='ident'>c</span><span class='op'>|</span> <span class='ident'>c</span> <span class='op'>==</span> <span class='string'>'1'</span> <span class='op'>||</span> <span class='ident'>c</span> <span class='op'>==</span> <span class='string'>'X'</span>), <span class='string'>"foo1bar"</span>); +</pre> +</div><h4 id='method.trim_left_matches' class='method'><code>fn <a href='#method.trim_left_matches' class='fnname'>trim_left_matches</a><'a, P>(&'a self, pat: P) -> &'a <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a> <span class='where'>where P: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Pattern</a><'a></span></code></h4> +<div class='docblock'><p>Returns a string with all prefixes that match a pattern +repeatedly removed.</p> + +<p>The pattern can be a simple <code>&str</code>, <code>char</code>, or a closure that +determines the split.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='string'>"11foo1bar11"</span>.<span class='ident'>trim_left_matches</span>(<span class='string'>'1'</span>), <span class='string'>"foo1bar11"</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='string'>"123foo1bar123"</span>.<span class='ident'>trim_left_matches</span>(<span class='ident'>char</span>::<span class='ident'>is_numeric</span>), <span class='string'>"foo1bar123"</span>); + +<span class='kw'>let</span> <span class='ident'>x</span>: <span class='kw-2'>&</span>[_] <span class='op'>=</span> <span class='kw-2'>&</span>[<span class='string'>'1'</span>, <span class='string'>'2'</span>]; +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='string'>"12foo1bar12"</span>.<span class='ident'>trim_left_matches</span>(<span class='ident'>x</span>), <span class='string'>"foo1bar12"</span>); +</pre> +</div><h4 id='method.trim_right_matches' class='method'><code>fn <a href='#method.trim_right_matches' class='fnname'>trim_right_matches</a><'a, P>(&'a self, pat: P) -> &'a <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a> <span class='where'>where P: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Pattern</a><'a>, P::<a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.Pattern.html' title='core::str::pattern::Pattern'>Searcher</a>: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/pattern/trait.ReverseSearcher.html' title='core::str::pattern::ReverseSearcher'>ReverseSearcher</a><'a></span></code></h4> +<div class='docblock'><p>Returns a string with all suffixes that match a pattern +repeatedly removed.</p> + +<p>The pattern can be a simple <code>&str</code>, <code>char</code>, or a closure that +determines the split.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1> +<p>Simple patterns:</p> +<pre class='rust rust-example-rendered'> +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='string'>"11foo1bar11"</span>.<span class='ident'>trim_right_matches</span>(<span class='string'>'1'</span>), <span class='string'>"11foo1bar"</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='string'>"123foo1bar123"</span>.<span class='ident'>trim_right_matches</span>(<span class='ident'>char</span>::<span class='ident'>is_numeric</span>), <span class='string'>"123foo1bar"</span>); + +<span class='kw'>let</span> <span class='ident'>x</span>: <span class='kw-2'>&</span>[_] <span class='op'>=</span> <span class='kw-2'>&</span>[<span class='string'>'1'</span>, <span class='string'>'2'</span>]; +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='string'>"12foo1bar12"</span>.<span class='ident'>trim_right_matches</span>(<span class='ident'>x</span>), <span class='string'>"12foo1bar"</span>); +</pre> + +<p>A more complex pattern, using a closure:</p> +<pre class='rust rust-example-rendered'> +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='string'>"1fooX"</span>.<span class='ident'>trim_left_matches</span>(<span class='op'>|</span><span class='ident'>c</span><span class='op'>|</span> <span class='ident'>c</span> <span class='op'>==</span> <span class='string'>'1'</span> <span class='op'>||</span> <span class='ident'>c</span> <span class='op'>==</span> <span class='string'>'X'</span>), <span class='string'>"fooX"</span>); +</pre> +</div><h4 id='method.parse' class='method'><code>fn <a href='#method.parse' class='fnname'>parse</a><F>(&self) -> <a class='enum' href='http://doc.rust-lang.org/nightly/core/result/enum.Result.html' title='core::result::Result'>Result</a><F, F::<a class='trait' href='http://doc.rust-lang.org/nightly/core/str/trait.FromStr.html' title='core::str::FromStr'>Err</a>> <span class='where'>where F: <a class='trait' href='http://doc.rust-lang.org/nightly/core/str/trait.FromStr.html' title='core::str::FromStr'>FromStr</a></span></code></h4> +<div class='docblock'><p>Parses <code>self</code> into the specified type.</p> + +<h1 id="failure" class='section-header'><a + href="#failure">Failure</a></h1> +<p>Will return <code>Err</code> if it's not possible to parse <code>self</code> into the type.</p> + +<h1 id="example" class='section-header'><a + href="#example">Example</a></h1><pre class='rust rust-example-rendered'> +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='string'>"4"</span>.<span class='ident'>parse</span>::<span class='op'><</span><span class='ident'>u32</span><span class='op'>></span>(), <span class='prelude-val'>Ok</span>(<span class='number'>4</span>)); +</pre> + +<p>Failing:</p> +<pre class='rust rust-example-rendered'> +<span class='macro'>assert</span><span class='macro'>!</span>(<span class='string'>"j"</span>.<span class='ident'>parse</span>::<span class='op'><</span><span class='ident'>u32</span><span class='op'>></span>().<span class='ident'>is_err</span>()); +</pre> +</div><h4 id='method.replace' class='method'><code>fn <a href='#method.replace' class='fnname'>replace</a>(&self, from: &<a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>, to: &<a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a>) -> <a class='struct' href='http://doc.rust-lang.org/nightly/collections/string/struct.String.html' title='collections::string::String'>String</a></code></h4> +<div class='docblock'><p>Replaces all occurrences of one string with another.</p> + +<p><code>replace</code> takes two arguments, a sub-<code>&str</code> to find in <code>self</code>, and a +second <code>&str</code> to +replace it with. If the original <code>&str</code> isn't found, no change occurs.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"this is old"</span>; + +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>replace</span>(<span class='string'>"old"</span>, <span class='string'>"new"</span>), <span class='string'>"this is new"</span>); +</pre> + +<p>When a <code>&str</code> isn't found:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"this is old"</span>; +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>replace</span>(<span class='string'>"cookie monster"</span>, <span class='string'>"little lamb"</span>), <span class='ident'>s</span>); +</pre> +</div><h4 id='method.to_lowercase' class='method'><code>fn <a href='#method.to_lowercase' class='fnname'>to_lowercase</a>(&self) -> <a class='struct' href='http://doc.rust-lang.org/nightly/collections/string/struct.String.html' title='collections::string::String'>String</a></code></h4> +<div class='docblock'><p>Returns the lowercase equivalent of this string.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>feature</span>(<span class='ident'>str_casing</span>)]</span> + +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"HELLO"</span>; +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>to_lowercase</span>(), <span class='string'>"hello"</span>); +</pre> +</div><h4 id='method.to_uppercase' class='method'><code>fn <a href='#method.to_uppercase' class='fnname'>to_uppercase</a>(&self) -> <a class='struct' href='http://doc.rust-lang.org/nightly/collections/string/struct.String.html' title='collections::string::String'>String</a></code></h4> +<div class='docblock'><p>Returns the uppercase equivalent of this string.</p> + +<h1 id="examples" class='section-header'><a + href="#examples">Examples</a></h1><pre class='rust rust-example-rendered'> +<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>feature</span>(<span class='ident'>str_casing</span>)]</span> + +<span class='kw'>let</span> <span class='ident'>s</span> <span class='op'>=</span> <span class='string'>"hello"</span>; +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>s</span>.<span class='ident'>to_uppercase</span>(), <span class='string'>"HELLO"</span>); +</pre> +</div><h4 id='method.escape_default' class='method'><code>fn <a href='#method.escape_default' class='fnname'>escape_default</a>(&self) -> <a class='struct' href='http://doc.rust-lang.org/nightly/collections/string/struct.String.html' title='collections::string::String'>String</a></code></h4> +<div class='stability'><em class='stab unstable'>Unstable<p>: return type may change to be an iterator</p> +</em></div><div class='docblock'><p>Escapes each char in <code>s</code> with <code>char::escape_default</code>.</p> +</div><h4 id='method.escape_unicode' class='method'><code>fn <a href='#method.escape_unicode' class='fnname'>escape_unicode</a>(&self) -> <a class='struct' href='http://doc.rust-lang.org/nightly/collections/string/struct.String.html' title='collections::string::String'>String</a></code></h4> +<div class='stability'><em class='stab unstable'>Unstable<p>: return type may change to be an iterator</p> +</em></div><div class='docblock'><p>Escapes each char in <code>s</code> with <code>char::escape_unicode</code>.</p> +</div></div><h2 id='implementations'>Trait Implementations</h2><h3 class='impl'><code>impl<'s> <a class='trait' href='http://doc.rust-lang.org/nightly/core/ops/trait.Drop.html' title='core::ops::Drop'>Drop</a> for <a class='struct' href='../../openssl/x509/struct.SslString.html' title='openssl::x509::SslString'>SslString</a></code></h3><div class='impl-items'><h4 id='method.drop' class='method'><code>fn <a href='http://doc.rust-lang.org/nightly/core/ops/trait.Drop.html#method.drop' class='fnname'>drop</a>(&mut self)</code></h4> +</div><h3 class='impl'><code>impl <a class='trait' href='http://doc.rust-lang.org/nightly/core/ops/trait.Deref.html' title='core::ops::Deref'>Deref</a> for <a class='struct' href='../../openssl/x509/struct.SslString.html' title='openssl::x509::SslString'>SslString</a></code></h3><div class='impl-items'><h4 id='assoc_type.Target' class='type'><code>type Target = <a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a></code></h4> +<h4 id='method.deref' class='method'><code>fn <a href='http://doc.rust-lang.org/nightly/core/ops/trait.Deref.html#method.deref' class='fnname'>deref</a>(&self) -> &<a href='http://doc.rust-lang.org/nightly/std/primitive.str.html'>str</a></code></h4> +</div><h3 class='impl'><code>impl <a class='trait' href='http://doc.rust-lang.org/nightly/core/fmt/trait.Display.html' title='core::fmt::Display'>Display</a> for <a class='struct' href='../../openssl/x509/struct.SslString.html' title='openssl::x509::SslString'>SslString</a></code></h3><div class='impl-items'><h4 id='method.fmt' class='method'><code>fn <a href='http://doc.rust-lang.org/nightly/core/fmt/trait.Display.html#method.fmt' class='fnname'>fmt</a>(&self, f: &mut <a class='struct' href='http://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html' title='core::fmt::Formatter'>Formatter</a>) -> <a class='type' href='http://doc.rust-lang.org/nightly/core/fmt/type.Result.html' title='core::fmt::Result'>Result</a></code></h4> +</div><h3 class='impl'><code>impl <a class='trait' href='http://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html' title='core::fmt::Debug'>Debug</a> for <a class='struct' href='../../openssl/x509/struct.SslString.html' title='openssl::x509::SslString'>SslString</a></code></h3><div class='impl-items'><h4 id='method.fmt' class='method'><code>fn <a href='http://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#method.fmt' class='fnname'>fmt</a>(&self, f: &mut <a class='struct' href='http://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html' title='core::fmt::Formatter'>Formatter</a>) -> <a class='type' href='http://doc.rust-lang.org/nightly/core/fmt/type.Result.html' title='core::fmt::Result'>Result</a></code></h4> +</div></section> + <section id='search' class="content hidden"></section> + + <section class="footer"></section> + + <div id="help" class="hidden"> + <div class="shortcuts"> + <h1>Keyboard shortcuts</h1> + <dl> + <dt>?</dt> + <dd>Show this help dialog</dd> + <dt>S</dt> + <dd>Focus the search field</dd> + <dt>⇤</dt> + <dd>Move up in search results</dd> + <dt>⇥</dt> + <dd>Move down in search results</dd> + <dt>⏎</dt> + <dd>Go to active search result</dd> + </dl> + </div> + <div class="infos"> + <h1>Search tricks</h1> + <p> + Prefix searches with a type followed by a colon (e.g. + <code>fn:</code>) to restrict the search to a given type. + </p> + <p> + Accepted types are: <code>fn</code>, <code>mod</code>, + <code>struct</code>, <code>enum</code>, + <code>trait</code>, <code>typedef</code> (or + <code>tdef</code>). + </p> + <p> + Search functions by type signature (e.g. + <code>vec -> usize</code>) + </p> + </div> + </div> + + + + <script> + window.rootPath = "../../"; + window.currentCrate = "openssl"; + window.playgroundUrl = ""; + </script> + <script src="../../jquery.js"></script> + <script src="../../main.js"></script> + + <script async src="../../search-index.js"></script> +</body> +</html>
\ No newline at end of file |