The OpenD Programming Language

decodeBack

decodeBack is a variant of decode which specifically decodes the last code point. Unlike decode, decodeBack accepts any bidirectional range of code units (rather than just a string or random access range). It also takes the range by ref and pops off the elements as it decodes them. If numCodeUnits is passed in, it gets set to the number of code units which were in the code point which was decoded.

  1. dchar decodeBack(S str, size_t numCodeUnits)
  2. dchar decodeBack(S str, size_t numCodeUnits)
    dchar
    decodeBack
    (
    UseReplacementDchar useReplacementDchar = No.useReplacementDchar
    S
    )
    (
    ref S str
    ,
    out size_t numCodeUnits
    )
    if (
    isBidirectionalRange!S
    &&
    )
    out (result) { assert (isValidDchar(result)); }
  3. dchar decodeBack(S str)

Parameters

useReplacementDchar

if invalid UTF, return replacementDchar rather than throwing

str S

input string or bidirectional Range

numCodeUnits size_t

gives the number of code units processed

Return Value

Type: dchar

A decoded UTF character.

Throws

UTFException if str.back is not the end of a valid UTF sequence. If an exception is thrown, the str itself remains unchanged, but there is no guarantee as to the value of numCodeUnits (when passed).

Examples

import std.range.primitives;
string str = "Hello, World!";

assert(str.decodeBack == '!' && str == "Hello, World");
str = "å";
assert(str.decodeBack == 'å' && str.empty);
str = "å";
size_t i;
assert(str.decodeBack(i) == 'å' && i == 2 && str.empty);

Meta