codeUnits

Returns a foreachable struct which can bidirectionally iterate over all code units in a code point.

The input to this function MUST be a valid code point. This is enforced by the function's in-contract.

The type of the output cannot be deduced. Therefore, it is necessary to explicitly specify the encoding type in the template parameter.

Supersedes: This function supersedes std.utf.encode().

CodeUnits!(E)
codeUnits
(
E
)
(
dchar c
)

Parameters

c dchar

the code point to be encoded

Examples

char[] a;
foreach (c;codeUnits!(char)(cast(dchar)'\u20AC'))
{
    a ~= c;
}
assert(a.length == 3);
assert(a[0] == 0xE2);
assert(a[1] == 0x82);
assert(a[2] == 0xAC);

Meta

Standards

Unicode 5.0, ASCII, ISO-8859-1, ISO-8859-2, WINDOWS-1250, WINDOWS-1251, WINDOWS-1252