parseCharRef

If the given range starts with a valid, XML, character reference, it is removed from the range, and the corresponding character is returned.

If the range does not start with a valid, XML, character reference, then the return value is null, and the range is unchanged.

Nullable!dchar
parseCharRef
(
R
)
(
ref R range
)
if (
isForwardRange!R &&
isSomeChar!(ElementType!R)
)

Parameters

range R

A range of characters.

Return Value

Type: Nullable!dchar

The character represented by the character reference that was parsed from the front of the given range or null if the range did not start with a valid, XML, character reference.

Examples

import std.range.primitives : empty;

{
    auto range = "0 hello world";
    assert(parseCharRef(range) == '0');
    assert(range == " hello world");
}
{
    auto range = "0 hello world";
    assert(parseCharRef(range) == '0');
    assert(range == " hello world");
}
{
    auto range = "ディラン";
    assert(parseCharRef(range) == 'デ');
    assert(range == "ィラン");
    assert(parseCharRef(range) == 'ィ');
    assert(range == "ラン");
    assert(parseCharRef(range) == 'ラ');
    assert(range == "ン");
    assert(parseCharRef(range) == 'ン');
    assert(range.empty);
}
{
    auto range = "&#x;foo";
    assert(parseCharRef(range).isNull);
    assert(range == "&#x;foo");
}
{
    auto range = "foobar";
    assert(parseCharRef(range).isNull);
    assert(range == "foobar");
}
{
    auto range = " &x48;";
    assert(parseCharRef(range).isNull);
    assert(range == " &x48;");
}

See Also

Meta