if invalid UTF, return replacementDchar rather than throwing
input string or bidirectional Range
gives the number of code units processed
A decoded UTF character.
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).
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);
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.