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

1 import std.range.primitives : empty;
2 
3 {
4     auto range = "0 hello world";
5     assert(parseCharRef(range) == '0');
6     assert(range == " hello world");
7 }
8 {
9     auto range = "0 hello world";
10     assert(parseCharRef(range) == '0');
11     assert(range == " hello world");
12 }
13 {
14     auto range = "ディラン";
15     assert(parseCharRef(range) == 'デ');
16     assert(range == "ィラン");
17     assert(parseCharRef(range) == 'ィ');
18     assert(range == "ラン");
19     assert(parseCharRef(range) == 'ラ');
20     assert(range == "ン");
21     assert(parseCharRef(range) == 'ン');
22     assert(range.empty);
23 }
24 {
25     auto range = "&#x;foo";
26     assert(parseCharRef(range).isNull);
27     assert(range == "&#x;foo");
28 }
29 {
30     auto range = "foobar";
31     assert(parseCharRef(range).isNull);
32     assert(range == "foobar");
33 }
34 {
35     auto range = " &x48;";
36     assert(parseCharRef(range).isNull);
37     assert(range == " &x48;");
38 }

See Also

Meta