decode

Decodes and returns the code point starting at str[index]. index is advanced to one past the decoded code point. If the code point is not well-formed, then a UTFException is thrown and index remains unchanged.

decode will only work with strings and random access ranges of code units with length and slicing, whereas decodeFront will work with any input range of code units.

  1. dchar decode(S str, size_t index)
    dchar
    decode
    (
    UseReplacementDchar useReplacementDchar = No.useReplacementDchar
    S
    )
    (
    auto ref S str
    ,
    ref size_t index
    )
    if (
    isRandomAccessRange!S
    &&
    hasSlicing!S
    &&
    hasLength!S
    &&
    isSomeChar!(ElementType!S)
    )
    out (result) { assert (isValidDchar(result)); }
  2. dchar decode(S str, size_t index)

Parameters

useReplacementDchar

if invalid UTF, return replacementDchar rather than throwing

str S

input string or indexable Range

index size_t

starting index into s[]; incremented by number of code units processed

Return Value

Type: dchar

decoded character

Throws

UTFException if str[index] is not the start of a valid UTF sequence and useReplacementDchar is No.useReplacementDchar

Examples

size_t i;

assert("a".decode(i) == 'a' && i == 1);
i = 0;
assert("å".decode(i) == 'å' && i == 2);
i = 1;
assert("aå".decode(i) == 'å' && i == 3);
i = 0;
assert("å"w.decode(i) == 'å' && i == 1);

// ë as a multi-code point grapheme
i = 0;
assert("e\u0308".decode(i) == 'e' && i == 1);
// ë as a single code point grapheme
i = 0;
assert("ë".decode(i) == 'ë' && i == 2);
i = 0;
assert("ë"w.decode(i) == 'ë' && i == 1);

Meta