graphemeStride

Computes the length of grapheme cluster starting at index. Both the resulting length and the index are measured in code units.

version(!std_uni_bootstrap)
@safe pure
size_t
graphemeStride
(
C
)
(
const scope C[] input
,
size_t index
)
if (
is(C : dchar)
)

Parameters

C

type that is implicitly convertible to dchars

input C[]

array of grapheme clusters

index size_t

starting index into input[]

Return Value

Type: size_t

length of grapheme cluster

Examples

assert(graphemeStride("  ", 1) == 1);
// A + combing ring above
string city = "A\u030Arhus";
size_t first = graphemeStride(city, 0);
assert(first == 3); //\u030A has 2 UTF-8 code units
assert(city[0 .. first] == "A\u030A");
assert(city[first..$] == "rhus");

Meta