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
Type: 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

1 {
2     auto range = "&amp;foo";
3     assert(range.parseStdEntityRef() == '&');
4     assert(range == "foo");
5 }
6 {
7     auto range = "&gt;bar";
8     assert(range.parseStdEntityRef() == '>');
9     assert(range == "bar");
10 }
11 {
12     auto range = "&lt;baz";
13     assert(range.parseStdEntityRef() == '<');
14     assert(range == "baz");
15 }
16 {
17     auto range = "&apos;dlang";
18     assert(range.parseStdEntityRef() == '\'');
19     assert(range == "dlang");
20 }
21 {
22     auto range = "&quot;rocks";
23     assert(range.parseStdEntityRef() == '"');
24     assert(range == "rocks");
25 }
26 {
27     auto range = " &amp;foo";
28     assert(range.parseStdEntityRef().isNull);
29     assert(range == " &amp;foo");
30 }
31 {
32     auto range = "&Amp;hello";
33     assert(range.parseStdEntityRef().isNull);
34     assert(range == "&Amp;hello");
35 }
36 {
37     auto range = "&nbsp;foo";
38     assert(range.parseStdEntityRef().isNull);
39     assert(range == "&nbsp;foo");
40 }
41 {
42     auto range = "hello world";
43     assert(range.parseStdEntityRef().isNull);
44     assert(range == "hello world");
45 }

See Also

Meta