View source code
Display the source code in std/utf.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Function std.utf.stride
Calculate the length of the UTF sequence starting at index
in str
.
uint stride(S)
(
auto ref S str,
size_t index
)
if (is(S : const(char[])) || isRandomAccessRange!S && is(Unqual!(ElementType!S) == char));
uint stride(S)
(
auto ref S str
)
if (is(S : const(char[])) || isInputRange!S && is(Unqual!(ElementType!S) == char));
uint stride(S)
(
auto ref S str,
size_t index
)
if (is(S : const(wchar[])) || isRandomAccessRange!S && is(Unqual!(ElementType!S) == wchar));
uint stride(S)
(
auto ref S str
) pure @safe
if (is(S : const(wchar[])));
uint stride(S)
(
auto ref S str
)
if (isInputRange!S && is(Unqual!(ElementType!S) == wchar));
uint stride(S)
(
auto ref S str,
size_t index = 0
)
if (is(S : const(dchar[])) || isInputRange!S && is(Unqual!(ElementEncodingType!S) == dchar));
Parameters
Name | Description |
---|---|
str | input range
of UTF code units. Must be random access if index is passed |
index | starting index of UTF sequence (default: 0 ) |
Returns
The number of code units in the UTF sequence. For UTF-8, this is a value between 1 and 4 (as per RFC 3629, section 3). For UTF-16, it is either 1 or 2. For UTF-32, it is always 1.
Throws
May throw a UTFException
if str[index]
is not the start of a
valid UTF sequence.
Note
stride
will only analyze the first str[index]
element. It
will not fully verify the validity of the UTF sequence, nor even verify
the presence of the sequence: it will not actually guarantee that
index + stride(str, index) <= str
.
Example
writeln("a" .stride); // 1
writeln("λ" .stride); // 2
writeln("aλ" .stride); // 1
writeln("aλ" .stride(1)); // 2
writeln("𐐷" .stride); // 4
Authors
License
Copyright © 1999-2018 by the D Language Foundation | Page generated by ddox.