linol/lsp/Lsp/Import/String/index.html
2024-05-08 15:15:46 +00:00

9 lines
47 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>String (lsp.Lsp.Import.String)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 2.4.2"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../../../index.html">lsp</a> &#x00BB; <a href="../../index.html">Lsp</a> &#x00BB; <a href="../index.html">Import</a> &#x00BB; String</nav><header class="odoc-preamble"><h1>Module <code><span>Import.String</span></code></h1></header><div class="odoc-content"><div class="odoc-include"><details open="open"><summary class="spec include"><code><span><span class="keyword">include</span> <span class="keyword">module</span> <span class="keyword">type</span> <span class="keyword">of</span> <span class="keyword">struct</span> <span class="keyword">include</span> <a href="../../../../ocaml/Stdlib/StringLabels/index.html">Stdlib.StringLabels</a> <span class="keyword">end</span></span></code></summary><h2 id="strings"><a href="#strings" class="anchor"></a>Strings</h2><div class="odoc-spec"><div class="spec type anchored" id="type-t"><a href="#type-t" class="anchor"></a><code><span><span class="keyword">type</span> t</span><span> = string</span></code></div><div class="spec-doc"><p>The type for strings.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-make"><a href="#val-make" class="anchor"></a><code><span><span class="keyword">val</span> make : <span>int <span class="arrow">&#45;&gt;</span></span> <span>char <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p><code>make n c</code> is a string of length <code>n</code> with each index holding the character <code>c</code>.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Invalid_argument</code> <p>if <code>n &lt; 0</code> or <code>n &gt; </code><code>Sys.max_string_length</code>.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-init"><a href="#val-init" class="anchor"></a><code><span><span class="keyword">val</span> init : <span>int <span class="arrow">&#45;&gt;</span></span> <span><span class="label">f</span>:<span>(<span>int <span class="arrow">&#45;&gt;</span></span> char)</span> <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p><code>init n ~f</code> is a string of length <code>n</code> with index <code>i</code> holding the character <code>f i</code> (called in increasing index order).</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Invalid_argument</code> <p>if <code>n &lt; 0</code> or <code>n &gt; </code><code>Sys.max_string_length</code>.</p></li></ul><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.02</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-empty"><a href="#val-empty" class="anchor"></a><code><span><span class="keyword">val</span> empty : string</span></code></div><div class="spec-doc"><p>The empty string.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value external anchored" id="val-length"><a href="#val-length" class="anchor"></a><code><span><span class="keyword">val</span> length : <span>string <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p><code>length s</code> is the length (number of bytes/characters) of <code>s</code>.</p></div></div><div class="odoc-spec"><div class="spec value external anchored" id="val-get"><a href="#val-get" class="anchor"></a><code><span><span class="keyword">val</span> get : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> char</span></code></div><div class="spec-doc"><p><code>get s i</code> is the character at index <code>i</code> in <code>s</code>. This is the same as writing <code>s.[i]</code>.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Invalid_argument</code> <p>if <code>i</code> not an index of <code>s</code>.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_bytes"><a href="#val-of_bytes" class="anchor"></a><code><span><span class="keyword">val</span> of_bytes : <span>bytes <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p>Return a new string that contains the same bytes as the given byte sequence.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_bytes"><a href="#val-to_bytes" class="anchor"></a><code><span><span class="keyword">val</span> to_bytes : <span>string <span class="arrow">&#45;&gt;</span></span> bytes</span></code></div><div class="spec-doc"><p>Return a new byte sequence that contains the same bytes as the given string.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-blit"><a href="#val-blit" class="anchor"></a><code><span><span class="keyword">val</span> blit :
<span><span class="label">src</span>:string <span class="arrow">&#45;&gt;</span></span>
<span><span class="label">src_pos</span>:int <span class="arrow">&#45;&gt;</span></span>
<span><span class="label">dst</span>:bytes <span class="arrow">&#45;&gt;</span></span>
<span><span class="label">dst_pos</span>:int <span class="arrow">&#45;&gt;</span></span>
<span><span class="label">len</span>:int <span class="arrow">&#45;&gt;</span></span>
unit</span></code></div><div class="spec-doc"><p>Same as <code>Bytes.blit_string</code> which should be preferred.</p></div></div><h2 id="concat"><a href="#concat" class="anchor"></a>Concatenating</h2><p><b>Note.</b> The <a href="../../../../ocaml/Stdlib/index.html#val-(^)"><code>Stdlib.(^)</code></a> binary operator concatenates two strings.</p><div class="odoc-spec"><div class="spec value anchored" id="val-concat"><a href="#val-concat" class="anchor"></a><code><span><span class="keyword">val</span> concat : <span><span class="label">sep</span>:string <span class="arrow">&#45;&gt;</span></span> <span><span>string list</span> <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p><code>concat ~sep ss</code> concatenates the list of strings <code>ss</code>, inserting the separator string <code>sep</code> between each.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Invalid_argument</code> <p>if the result is longer than <code>Sys.max_string_length</code> bytes.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-cat"><a href="#val-cat" class="anchor"></a><code><span><span class="keyword">val</span> cat : <span>string <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p><code>cat s1 s2</code> concatenates s1 and s2 (<code>s1 ^ s2</code>).</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Invalid_argument</code> <p>if the result is longer than <code>Sys.max_string_length</code> bytes.</p></li></ul><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><h2 id="predicates"><a href="#predicates" class="anchor"></a>Predicates and comparisons</h2><div class="odoc-spec"><div class="spec value anchored" id="val-equal"><a href="#val-equal" class="anchor"></a><code><span><span class="keyword">val</span> equal : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>equal s0 s1</code> is <code>true</code> if and only if <code>s0</code> and <code>s1</code> are character-wise equal.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-compare"><a href="#val-compare" class="anchor"></a><code><span><span class="keyword">val</span> compare : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p><code>compare s0 s1</code> sorts <code>s0</code> and <code>s1</code> in lexicographical order. <code>compare</code> behaves like <a href="../../../../ocaml/Stdlib/index.html#val-compare"><code>Stdlib.compare</code></a> on strings but may be more efficient.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-starts_with"><a href="#val-starts_with" class="anchor"></a><code><span><span class="keyword">val</span> starts_with : <span><span class="label">prefix</span>:string <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>starts_with </code><code>~prefix s</code> is <code>true</code> if and only if <code>s</code> starts with <code>prefix</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-ends_with"><a href="#val-ends_with" class="anchor"></a><code><span><span class="keyword">val</span> ends_with : <span><span class="label">suffix</span>:string <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>ends_with </code><code>~suffix s</code> is <code>true</code> if and only if <code>s</code> ends with <code>suffix</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-contains_from"><a href="#val-contains_from" class="anchor"></a><code><span><span class="keyword">val</span> contains_from : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> <span>char <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>contains_from s start c</code> is <code>true</code> if and only if <code>c</code> appears in <code>s</code> after position <code>start</code>.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Invalid_argument</code> <p>if <code>start</code> is not a valid position in <code>s</code>.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-rcontains_from"><a href="#val-rcontains_from" class="anchor"></a><code><span><span class="keyword">val</span> rcontains_from : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> <span>char <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>rcontains_from s stop c</code> is <code>true</code> if and only if <code>c</code> appears in <code>s</code> before position <code>stop+1</code>.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Invalid_argument</code> <p>if <code>stop &lt; 0</code> or <code>stop+1</code> is not a valid position in <code>s</code>.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-contains"><a href="#val-contains" class="anchor"></a><code><span><span class="keyword">val</span> contains : <span>string <span class="arrow">&#45;&gt;</span></span> <span>char <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>contains s c</code> is <a href="#val-contains_from"><code>String.contains_from</code></a><code> s 0 c</code>.</p></div></div><h2 id="extract"><a href="#extract" class="anchor"></a>Extracting substrings</h2><div class="odoc-spec"><div class="spec value anchored" id="val-sub"><a href="#val-sub" class="anchor"></a><code><span><span class="keyword">val</span> sub : <span>string <span class="arrow">&#45;&gt;</span></span> <span><span class="label">pos</span>:int <span class="arrow">&#45;&gt;</span></span> <span><span class="label">len</span>:int <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p><code>sub s ~pos ~len</code> is a string of length <code>len</code>, containing the substring of <code>s</code> that starts at position <code>pos</code> and has length <code>len</code>.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Invalid_argument</code> <p>if <code>pos</code> and <code>len</code> do not designate a valid substring of <code>s</code>.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-split_on_char"><a href="#val-split_on_char" class="anchor"></a><code><span><span class="keyword">val</span> split_on_char : <span><span class="label">sep</span>:char <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> <span>string list</span></span></code></div><div class="spec-doc"><p><code>split_on_char ~sep s</code> is the list of all (possibly empty) substrings of <code>s</code> that are delimited by the character <code>sep</code>.</p><p>The function's result is specified by the following invariants:</p><ul><li>The list is not empty.</li><li>Concatenating its elements using <code>sep</code> as a separator returns a string equal to the input (<code>concat (make 1 sep)
(split_on_char sep s) = s</code>).</li><li>No string in the result contains the <code>sep</code> character.</li></ul><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><h2 id="transforming"><a href="#transforming" class="anchor"></a>Transforming</h2><div class="odoc-spec"><div class="spec value anchored" id="val-map"><a href="#val-map" class="anchor"></a><code><span><span class="keyword">val</span> map : <span><span class="label">f</span>:<span>(<span>char <span class="arrow">&#45;&gt;</span></span> char)</span> <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p><code>map f s</code> is the string resulting from applying <code>f</code> to all the characters of <code>s</code> in increasing order.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.00</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-mapi"><a href="#val-mapi" class="anchor"></a><code><span><span class="keyword">val</span> mapi : <span><span class="label">f</span>:<span>(<span>int <span class="arrow">&#45;&gt;</span></span> <span>char <span class="arrow">&#45;&gt;</span></span> char)</span> <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p><code>mapi ~f s</code> is like <a href="#val-map"><code>map</code></a> but the index of the character is also passed to <code>f</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.02</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-fold_left"><a href="#val-fold_left" class="anchor"></a><code><span><span class="keyword">val</span> fold_left : <span><span class="label">f</span>:<span>(<span><span class="type-var">'acc</span> <span class="arrow">&#45;&gt;</span></span> <span>char <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'acc</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="label">init</span>:<span class="type-var">'acc</span> <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'acc</span></span></code></div><div class="spec-doc"><p><code>fold_left f x s</code> computes <code>f (... (f (f x s.[0]) s.[1]) ...) s.[n-1]</code>, where <code>n</code> is the length of the string <code>s</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-fold_right"><a href="#val-fold_right" class="anchor"></a><code><span><span class="keyword">val</span> fold_right : <span><span class="label">f</span>:<span>(<span>char <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'acc</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'acc</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> <span><span class="label">init</span>:<span class="type-var">'acc</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'acc</span></span></code></div><div class="spec-doc"><p><code>fold_right f s x</code> computes <code>f s.[0] (f s.[1] ( ... (f s.[n-1] x) ...))</code>, where <code>n</code> is the length of the string <code>s</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-for_all"><a href="#val-for_all" class="anchor"></a><code><span><span class="keyword">val</span> for_all : <span><span class="label">f</span>:<span>(<span>char <span class="arrow">&#45;&gt;</span></span> bool)</span> <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>for_all p s</code> checks if all characters in <code>s</code> satisfy the predicate <code>p</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-exists"><a href="#val-exists" class="anchor"></a><code><span><span class="keyword">val</span> exists : <span><span class="label">f</span>:<span>(<span>char <span class="arrow">&#45;&gt;</span></span> bool)</span> <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>exists p s</code> checks if at least one character of <code>s</code> satisfies the predicate <code>p</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-trim"><a href="#val-trim" class="anchor"></a><code><span><span class="keyword">val</span> trim : <span>string <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p><code>trim s</code> is <code>s</code> without leading and trailing whitespace. Whitespace characters are: <code>' '</code>, <code>'\x0C'</code> (form feed), <code>'\n'</code>, <code>'\r'</code>, and <code>'\t'</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.00</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-escaped"><a href="#val-escaped" class="anchor"></a><code><span><span class="keyword">val</span> escaped : <span>string <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p><code>escaped s</code> is <code>s</code> with special characters represented by escape sequences, following the lexical conventions of OCaml.</p><p>All characters outside the US-ASCII printable range [0x20;0x7E] are escaped, as well as backslash (0x2F) and double-quote (0x22).</p><p>The function <code>Scanf.unescaped</code> is a left inverse of <code>escaped</code>, i.e. <code>Scanf.unescaped (escaped s) = s</code> for any string <code>s</code> (unless <code>escaped s</code> fails).</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Invalid_argument</code> <p>if the result is longer than <code>Sys.max_string_length</code> bytes.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-uppercase_ascii"><a href="#val-uppercase_ascii" class="anchor"></a><code><span><span class="keyword">val</span> uppercase_ascii : <span>string <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p><code>uppercase_ascii s</code> is <code>s</code> with all lowercase letters translated to uppercase, using the US-ASCII character set.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-lowercase_ascii"><a href="#val-lowercase_ascii" class="anchor"></a><code><span><span class="keyword">val</span> lowercase_ascii : <span>string <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p><code>lowercase_ascii s</code> is <code>s</code> with all uppercase letters translated to lowercase, using the US-ASCII character set.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-capitalize_ascii"><a href="#val-capitalize_ascii" class="anchor"></a><code><span><span class="keyword">val</span> capitalize_ascii : <span>string <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p><code>capitalize_ascii s</code> is <code>s</code> with the first character set to uppercase, using the US-ASCII character set.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-uncapitalize_ascii"><a href="#val-uncapitalize_ascii" class="anchor"></a><code><span><span class="keyword">val</span> uncapitalize_ascii : <span>string <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p><code>uncapitalize_ascii s</code> is <code>s</code> with the first character set to lowercase, using the US-ASCII character set.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><h2 id="traversing"><a href="#traversing" class="anchor"></a>Traversing</h2><div class="odoc-spec"><div class="spec value anchored" id="val-iter"><a href="#val-iter" class="anchor"></a><code><span><span class="keyword">val</span> iter : <span><span class="label">f</span>:<span>(<span>char <span class="arrow">&#45;&gt;</span></span> unit)</span> <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>iter ~f s</code> applies function <code>f</code> in turn to all the characters of <code>s</code>. It is equivalent to <code>f s.[0]; f s.[1]; ...; f s.[length s - 1]; ()</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-iteri"><a href="#val-iteri" class="anchor"></a><code><span><span class="keyword">val</span> iteri : <span><span class="label">f</span>:<span>(<span>int <span class="arrow">&#45;&gt;</span></span> <span>char <span class="arrow">&#45;&gt;</span></span> unit)</span> <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>iteri</code> is like <a href="#val-iter"><code>iter</code></a>, but the function is also given the corresponding character index.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.00</li></ul></div></div><h2 id="searching"><a href="#searching" class="anchor"></a>Searching</h2><div class="odoc-spec"><div class="spec value anchored" id="val-index_from"><a href="#val-index_from" class="anchor"></a><code><span><span class="keyword">val</span> index_from : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> <span>char <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p><code>index_from s i c</code> is the index of the first occurrence of <code>c</code> in <code>s</code> after position <code>i</code>.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Not_found</code> <p>if <code>c</code> does not occur in <code>s</code> after position <code>i</code>.</p></li></ul><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Invalid_argument</code> <p>if <code>i</code> is not a valid position in <code>s</code>.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-index_from_opt"><a href="#val-index_from_opt" class="anchor"></a><code><span><span class="keyword">val</span> index_from_opt : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> <span>char <span class="arrow">&#45;&gt;</span></span> <span>int option</span></span></code></div><div class="spec-doc"><p><code>index_from_opt s i c</code> is the index of the first occurrence of <code>c</code> in <code>s</code> after position <code>i</code> (if any).</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Invalid_argument</code> <p>if <code>i</code> is not a valid position in <code>s</code>.</p></li></ul><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-rindex_from"><a href="#val-rindex_from" class="anchor"></a><code><span><span class="keyword">val</span> rindex_from : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> <span>char <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p><code>rindex_from s i c</code> is the index of the last occurrence of <code>c</code> in <code>s</code> before position <code>i+1</code>.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Not_found</code> <p>if <code>c</code> does not occur in <code>s</code> before position <code>i+1</code>.</p></li></ul><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Invalid_argument</code> <p>if <code>i+1</code> is not a valid position in <code>s</code>.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-rindex_from_opt"><a href="#val-rindex_from_opt" class="anchor"></a><code><span><span class="keyword">val</span> rindex_from_opt : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> <span>char <span class="arrow">&#45;&gt;</span></span> <span>int option</span></span></code></div><div class="spec-doc"><p><code>rindex_from_opt s i c</code> is the index of the last occurrence of <code>c</code> in <code>s</code> before position <code>i+1</code> (if any).</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Invalid_argument</code> <p>if <code>i+1</code> is not a valid position in <code>s</code>.</p></li></ul><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-index_opt"><a href="#val-index_opt" class="anchor"></a><code><span><span class="keyword">val</span> index_opt : <span>string <span class="arrow">&#45;&gt;</span></span> <span>char <span class="arrow">&#45;&gt;</span></span> <span>int option</span></span></code></div><div class="spec-doc"><p><code>index_opt s c</code> is <a href="#val-index_from_opt"><code>String.index_from_opt</code></a><code> s 0 c</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-rindex"><a href="#val-rindex" class="anchor"></a><code><span><span class="keyword">val</span> rindex : <span>string <span class="arrow">&#45;&gt;</span></span> <span>char <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p><code>rindex s c</code> is <a href="#val-rindex_from"><code>String.rindex_from</code></a><code> s (length s - 1) c</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-rindex_opt"><a href="#val-rindex_opt" class="anchor"></a><code><span><span class="keyword">val</span> rindex_opt : <span>string <span class="arrow">&#45;&gt;</span></span> <span>char <span class="arrow">&#45;&gt;</span></span> <span>int option</span></span></code></div><div class="spec-doc"><p><code>rindex_opt s c</code> is <a href="#val-rindex_from_opt"><code>String.rindex_from_opt</code></a><code> s (length s - 1) c</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05</li></ul></div></div><h2 id="strings-and-sequences"><a href="#strings-and-sequences" class="anchor"></a>Strings and Sequences</h2><div class="odoc-spec"><div class="spec value anchored" id="val-to_seq"><a href="#val-to_seq" class="anchor"></a><code><span><span class="keyword">val</span> to_seq : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span>char <a href="../../../../ocaml/Stdlib/Seq/index.html#type-t">Stdlib.Seq.t</a></span></span></code></div><div class="spec-doc"><p><code>to_seq s</code> is a sequence made of the string's characters in increasing order. In <code>&quot;unsafe-string&quot;</code> mode, modifications of the string during iteration will be reflected in the sequence.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.07</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_seqi"><a href="#val-to_seqi" class="anchor"></a><code><span><span class="keyword">val</span> to_seqi : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><span>(int * char)</span> <a href="../../../../ocaml/Stdlib/Seq/index.html#type-t">Stdlib.Seq.t</a></span></span></code></div><div class="spec-doc"><p><code>to_seqi s</code> is like <a href="#val-to_seq"><code>to_seq</code></a> but also tuples the corresponding index.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.07</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_seq"><a href="#val-of_seq" class="anchor"></a><code><span><span class="keyword">val</span> of_seq : <span><span>char <a href="../../../../ocaml/Stdlib/Seq/index.html#type-t">Stdlib.Seq.t</a></span> <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p><code>of_seq s</code> is a string made of the sequence's characters.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.07</li></ul></div></div><h2 id="utf"><a href="#utf" class="anchor"></a>UTF decoding and validations</h2><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.14</li></ul><h3 id="utf_8"><a href="#utf_8" class="anchor"></a>UTF-8</h3><div class="odoc-spec"><div class="spec value anchored" id="val-get_utf_8_uchar"><a href="#val-get_utf_8_uchar" class="anchor"></a><code><span><span class="keyword">val</span> get_utf_8_uchar : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> <a href="../../../../ocaml/Stdlib/Uchar/index.html#type-utf_decode">Stdlib.Uchar.utf_decode</a></span></code></div><div class="spec-doc"><p><code>get_utf_8_uchar b i</code> decodes an UTF-8 character at index <code>i</code> in <code>b</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-is_valid_utf_8"><a href="#val-is_valid_utf_8" class="anchor"></a><code><span><span class="keyword">val</span> is_valid_utf_8 : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>is_valid_utf_8 b</code> is <code>true</code> if and only if <code>b</code> contains valid UTF-8 data.</p></div></div><h3 id="utf_16be"><a href="#utf_16be" class="anchor"></a>UTF-16BE</h3><div class="odoc-spec"><div class="spec value anchored" id="val-get_utf_16be_uchar"><a href="#val-get_utf_16be_uchar" class="anchor"></a><code><span><span class="keyword">val</span> get_utf_16be_uchar : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> <a href="../../../../ocaml/Stdlib/Uchar/index.html#type-utf_decode">Stdlib.Uchar.utf_decode</a></span></code></div><div class="spec-doc"><p><code>get_utf_16be_uchar b i</code> decodes an UTF-16BE character at index <code>i</code> in <code>b</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-is_valid_utf_16be"><a href="#val-is_valid_utf_16be" class="anchor"></a><code><span><span class="keyword">val</span> is_valid_utf_16be : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>is_valid_utf_16be b</code> is <code>true</code> if and only if <code>b</code> contains valid UTF-16BE data.</p></div></div><h3 id="utf_16le"><a href="#utf_16le" class="anchor"></a>UTF-16LE</h3><div class="odoc-spec"><div class="spec value anchored" id="val-get_utf_16le_uchar"><a href="#val-get_utf_16le_uchar" class="anchor"></a><code><span><span class="keyword">val</span> get_utf_16le_uchar : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> <a href="../../../../ocaml/Stdlib/Uchar/index.html#type-utf_decode">Stdlib.Uchar.utf_decode</a></span></code></div><div class="spec-doc"><p><code>get_utf_16le_uchar b i</code> decodes an UTF-16LE character at index <code>i</code> in <code>b</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-is_valid_utf_16le"><a href="#val-is_valid_utf_16le" class="anchor"></a><code><span><span class="keyword">val</span> is_valid_utf_16le : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>is_valid_utf_16le b</code> is <code>true</code> if and only if <code>b</code> contains valid UTF-16LE data.</p></div></div><h2 id="binary-decoding-of-integers"><a href="#binary-decoding-of-integers" class="anchor"></a>Binary decoding of integers</h2><p>The functions in this section binary decode integers from strings.</p><p>All following functions raise <code>Invalid_argument</code> if the characters needed at index <code>i</code> to decode the integer are not available.</p><p>Little-endian (resp. big-endian) encoding means that least (resp. most) significant bytes are stored first. Big-endian is also known as network byte order. Native-endian encoding is either little-endian or big-endian depending on <code>Sys.big_endian</code>.</p><p>32-bit and 64-bit integers are represented by the <code>int32</code> and <code>int64</code> types, which can be interpreted either as signed or unsigned numbers.</p><p>8-bit and 16-bit integers are represented by the <code>int</code> type, which has more bits than the binary encoding. These extra bits are sign-extended (or zero-extended) for functions which decode 8-bit or 16-bit integers and represented them with <code>int</code> values.</p><div class="odoc-spec"><div class="spec value anchored" id="val-get_uint8"><a href="#val-get_uint8" class="anchor"></a><code><span><span class="keyword">val</span> get_uint8 : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p><code>get_uint8 b i</code> is <code>b</code>'s unsigned 8-bit integer starting at character index <code>i</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_int8"><a href="#val-get_int8" class="anchor"></a><code><span><span class="keyword">val</span> get_int8 : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p><code>get_int8 b i</code> is <code>b</code>'s signed 8-bit integer starting at character index <code>i</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_uint16_ne"><a href="#val-get_uint16_ne" class="anchor"></a><code><span><span class="keyword">val</span> get_uint16_ne : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p><code>get_uint16_ne b i</code> is <code>b</code>'s native-endian unsigned 16-bit integer starting at character index <code>i</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_uint16_be"><a href="#val-get_uint16_be" class="anchor"></a><code><span><span class="keyword">val</span> get_uint16_be : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p><code>get_uint16_be b i</code> is <code>b</code>'s big-endian unsigned 16-bit integer starting at character index <code>i</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_uint16_le"><a href="#val-get_uint16_le" class="anchor"></a><code><span><span class="keyword">val</span> get_uint16_le : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p><code>get_uint16_le b i</code> is <code>b</code>'s little-endian unsigned 16-bit integer starting at character index <code>i</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_int16_ne"><a href="#val-get_int16_ne" class="anchor"></a><code><span><span class="keyword">val</span> get_int16_ne : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p><code>get_int16_ne b i</code> is <code>b</code>'s native-endian signed 16-bit integer starting at character index <code>i</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_int16_be"><a href="#val-get_int16_be" class="anchor"></a><code><span><span class="keyword">val</span> get_int16_be : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p><code>get_int16_be b i</code> is <code>b</code>'s big-endian signed 16-bit integer starting at character index <code>i</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_int16_le"><a href="#val-get_int16_le" class="anchor"></a><code><span><span class="keyword">val</span> get_int16_le : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p><code>get_int16_le b i</code> is <code>b</code>'s little-endian signed 16-bit integer starting at character index <code>i</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_int32_ne"><a href="#val-get_int32_ne" class="anchor"></a><code><span><span class="keyword">val</span> get_int32_ne : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> int32</span></code></div><div class="spec-doc"><p><code>get_int32_ne b i</code> is <code>b</code>'s native-endian 32-bit integer starting at character index <code>i</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-hash"><a href="#val-hash" class="anchor"></a><code><span><span class="keyword">val</span> hash : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p>An unseeded hash function for strings, with the same output value as <code>Hashtbl.hash</code>. This function allows this module to be passed as argument to the functor <code>Hashtbl.Make</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 5.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-seeded_hash"><a href="#val-seeded_hash" class="anchor"></a><code><span><span class="keyword">val</span> seeded_hash : <span>int <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p>A seeded hash function for strings, with the same output value as <code>Hashtbl.seeded_hash</code>. This function allows this module to be passed as argument to the functor <code>Hashtbl.MakeSeeded</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 5.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_int32_be"><a href="#val-get_int32_be" class="anchor"></a><code><span><span class="keyword">val</span> get_int32_be : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> int32</span></code></div><div class="spec-doc"><p><code>get_int32_be b i</code> is <code>b</code>'s big-endian 32-bit integer starting at character index <code>i</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_int32_le"><a href="#val-get_int32_le" class="anchor"></a><code><span><span class="keyword">val</span> get_int32_le : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> int32</span></code></div><div class="spec-doc"><p><code>get_int32_le b i</code> is <code>b</code>'s little-endian 32-bit integer starting at character index <code>i</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_int64_ne"><a href="#val-get_int64_ne" class="anchor"></a><code><span><span class="keyword">val</span> get_int64_ne : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> int64</span></code></div><div class="spec-doc"><p><code>get_int64_ne b i</code> is <code>b</code>'s native-endian 64-bit integer starting at character index <code>i</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_int64_be"><a href="#val-get_int64_be" class="anchor"></a><code><span><span class="keyword">val</span> get_int64_be : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> int64</span></code></div><div class="spec-doc"><p><code>get_int64_be b i</code> is <code>b</code>'s big-endian 64-bit integer starting at character index <code>i</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_int64_le"><a href="#val-get_int64_le" class="anchor"></a><code><span><span class="keyword">val</span> get_int64_le : <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> int64</span></code></div><div class="spec-doc"><p><code>get_int64_le b i</code> is <code>b</code>'s little-endian 64-bit integer starting at character index <code>i</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.13</li></ul></div></div></details></div><div class="odoc-spec"><div class="spec value anchored" id="val-index"><a href="#val-index" class="anchor"></a><code><span><span class="keyword">val</span> index : <span>string <span class="arrow">&#45;&gt;</span></span> <span>char <span class="arrow">&#45;&gt;</span></span> <span>int option</span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-is_empty"><a href="#val-is_empty" class="anchor"></a><code><span><span class="keyword">val</span> is_empty : <span>string <span class="arrow">&#45;&gt;</span></span> bool</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-check_prefix"><a href="#val-check_prefix" class="anchor"></a><code><span><span class="keyword">val</span> check_prefix : <span>string <span class="arrow">&#45;&gt;</span></span> <span><span class="label">prefix</span>:string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> bool</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-lsplit2"><a href="#val-lsplit2" class="anchor"></a><code><span><span class="keyword">val</span> lsplit2 : <span>string <span class="arrow">&#45;&gt;</span></span> <span><span class="label">on</span>:char <span class="arrow">&#45;&gt;</span></span> <span><span>(string * string)</span> option</span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-is_prefix"><a href="#val-is_prefix" class="anchor"></a><code><span><span class="keyword">val</span> is_prefix : <span>string <span class="arrow">&#45;&gt;</span></span> <span><span class="label">prefix</span>:string <span class="arrow">&#45;&gt;</span></span> bool</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add_prefix_if_not_exists"><a href="#val-add_prefix_if_not_exists" class="anchor"></a><code><span><span class="keyword">val</span> add_prefix_if_not_exists : <span>string <span class="arrow">&#45;&gt;</span></span> <span><span class="label">prefix</span>:string <span class="arrow">&#45;&gt;</span></span> string</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-next_occurrence"><a href="#val-next_occurrence" class="anchor"></a><code><span><span class="keyword">val</span> next_occurrence : <span><span class="label">pattern</span>:string <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> int</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-replace_all"><a href="#val-replace_all" class="anchor"></a><code><span><span class="keyword">val</span> replace_all : <span><span class="label">pattern</span>:string <span class="arrow">&#45;&gt;</span></span> <span><span class="label">with_</span>:string <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> string</span></code></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Map"><a href="#module-Map" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Map/index.html">Map</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div></div></div></body></html>