View source code
Display the source code in std/utf.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function std.utf.isValidCodepoint

Checks if a single character forms a valid code point.

bool isValidCodepoint(Char) (
  Char c
if (isSomeChar!Char);

When standing alone, some characters are invalid code points. For example the wchar 0xD800 is a so called high surrogate, which can only be interpreted together with a low surrogate following it. As a standalone character it is considered invalid.

See Unicode Standard, D90, D91 and D92 for more details.


c character to test
Char character type of c


true, if c forms a valid code point.


assert( isValidCodepoint(cast(char) 0x40));
assert(!isValidCodepoint(cast(char) 0x80));
assert( isValidCodepoint(cast(wchar) 0x1234));
assert(!isValidCodepoint(cast(wchar) 0xD800));
assert( isValidCodepoint(cast(dchar) 0x0010FFFF));
assert(!isValidCodepoint(cast(dchar) 0x12345678));


Walter Bright and Jonathan M Davis


Boost License 1.0.