View source code Display the source code in std/utf.d from which this page was generated on github. 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. Page wiki View or edit the community-maintained wiki page associated with this page.

Function std.utf.toUTFindex

Given a UCS index n into str, returns the UTF index. So, n is how many code points into the string the code point is, and the array index of the code unit is returned.

Prototype

size_t toUTFindex(C)(
  const(C)[] str,
  size_t n
) pure @safe
if (isSomeChar!C);

Example

assert(toUTFindex(hello world, 7) == 7);
assert(toUTFindex(hello worldw, 7) == 7);
assert(toUTFindex(hello worldd, 7) == 7);

assert(toUTFindex(Ma Chérie, 6) == 7);
assert(toUTFindex(Ma Chériew, 7) == 7);
assert(toUTFindex(Ma Chéried, 7) == 7);

assert(toUTFindex(さいごの果実 / ミツバチと科学者, 3) == 9);
assert(toUTFindex(さいごの果実 / ミツバチと科学者w, 9) == 9);
assert(toUTFindex(さいごの果実 / ミツバチと科学者d, 9) == 9);

Authors

Walter Bright and Jonathan M Davis

License

Boost License 1.0.

Comments