parseStdEntityRef

This parses one of the five, predefined entity references mention in the XML spec from the front of a range of characters.

If the given range starts with one of the five, predefined entity references, then it is removed from the range, and the corresponding character is returned.

If the range does not start with one of those references, then the return value is null, and the range is unchanged.

Std Entity RefConverts To
&&
>>
&lt;<
&apos;'
&quot;"

Any other entity references would require processing a DTD section in order to be handled and are untouched by parseStdEntityRef as are any other types of references.

Nullable!dchar
parseStdEntityRef
(
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 predefined entity reference that was parsed from the front of the given range or null if the range did not start with one of the five predefined entity references.

Examples

{
    auto range = "&amp;foo";
    assert(range.parseStdEntityRef() == '&');
    assert(range == "foo");
}
{
    auto range = "&gt;bar";
    assert(range.parseStdEntityRef() == '>');
    assert(range == "bar");
}
{
    auto range = "&lt;baz";
    assert(range.parseStdEntityRef() == '<');
    assert(range == "baz");
}
{
    auto range = "&apos;dlang";
    assert(range.parseStdEntityRef() == '\'');
    assert(range == "dlang");
}
{
    auto range = "&quot;rocks";
    assert(range.parseStdEntityRef() == '"');
    assert(range == "rocks");
}
{
    auto range = " &amp;foo";
    assert(range.parseStdEntityRef().isNull);
    assert(range == " &amp;foo");
}
{
    auto range = "&Amp;hello";
    assert(range.parseStdEntityRef().isNull);
    assert(range == "&Amp;hello");
}
{
    auto range = "&nbsp;foo";
    assert(range.parseStdEntityRef().isNull);
    assert(range == "&nbsp;foo");
}
{
    auto range = "hello world";
    assert(range.parseStdEntityRef().isNull);
    assert(range == "hello world");
}

See Also

Meta