The OpenD Programming Language

parse

Parses typeof(null) from a character range if the range spells "null". This function is case insensitive.

Parameters

Target

the type to convert to

s Source

the lvalue of an input range

doCount

the flag for deciding to report the number of consumed characters

Return Value

Type: auto
  • null if doCount is set to No.doCount
  • A tuple containing null and a size_t if doCount is set to Yes.doCount

Throws

A ConvException if the range doesn't represent null.

Examples

import std.exception : assertThrown;
import std.typecons : Flag, Yes, No;

alias NullType = typeof(null);
auto s1 = "null";
assert(parse!NullType(s1) is null);
assert(s1 == "");

auto s2 = "NUll"d;
assert(parse!NullType(s2) is null);
assert(s2 == "");

auto s3 = "nuLlNULl";
assert(parse!(NullType, string, No.doCount)(s3) is null);
auto r = parse!(NullType, string, Yes.doCount)(s3);
assert(r.data is null && r.count == 4);

auto m = "maybe";
assertThrown!ConvException(parse!NullType(m));
assertThrown!ConvException(parse!(NullType, string, Yes.doCount)(m));
assert(m == "maybe");  // m shouldn't change on failure

auto s = "NULL";
assert(parse!(const NullType)(s) is null);

Meta