The OpenD Programming Language

assumeUTF

Assume the given array of integers arr is a well-formed UTF string and return it typed as a UTF string.

ubyte becomes char, ushort becomes wchar and uint becomes dchar. Type qualifiers are preserved.

When compiled with debug mode, this function performs an extra check to make sure the return value is a valid Unicode string.

assumeUTF
(
T
)
(
T[] arr
)
if (
staticIndexOf!(immutable T, immutable ubyte, immutable ushort, immutable uint) != -1
)

Parameters

arr T[]

array of bytes, ubytes, shorts, ushorts, ints, or uints

Return Value

Type: auto

arr retyped as an array of chars, wchars, or dchars

Throws

In debug mode AssertError, when the result is not a well-formed UTF string.

Examples

string a = "Hölo World";
immutable(ubyte)[] b = a.representation;
string c = b.assumeUTF;

assert(c == "Hölo World");

See Also

Meta