The OpenD Programming Language

canEncode

Returns true iff it is possible to represent the specified codepoint in the encoding.

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

bool
canEncode
(
E
)
(
dchar c
)

Examples

assert( canEncode!(Latin1Char)('A'));
assert( canEncode!(Latin2Char)('A'));
assert(!canEncode!(AsciiChar)('\u00A0'));
assert( canEncode!(Latin1Char)('\u00A0'));
assert( canEncode!(Latin2Char)('\u00A0'));
assert( canEncode!(Windows1250Char)('\u20AC'));
assert(!canEncode!(Windows1250Char)('\u20AD'));
assert(!canEncode!(Windows1250Char)('\uFFFD'));
assert( canEncode!(Windows1251Char)('\u0402'));
assert(!canEncode!(Windows1251Char)('\u20AD'));
assert(!canEncode!(Windows1251Char)('\uFFFD'));
assert( canEncode!(Windows1252Char)('\u20AC'));
assert(!canEncode!(Windows1252Char)('\u20AD'));
assert(!canEncode!(Windows1252Char)('\uFFFD'));
assert(!canEncode!(char)(cast(dchar) 0x110000));

How to check an entire string

import std.algorithm.searching : find;
import std.utf : byDchar;

assert("The quick brown fox"
    .byDchar
    .find!(x => !canEncode!AsciiChar(x))
    .empty);

Meta

Standards

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