getAttrs

A helper function for processing start tag attributes.

It functions similarly to $(PHOBOS_REF getopt, std, getopt). It takes a range of attributes and a list of alternating strings and pointers where each string represents the name of the attribute to parse and the pointer immediately after it is assigned the value that corresponds to the attribute name (if present). If the given pointer does not point to the same type as the range of characters used in the attributes, then $(PHOBOS_REF to, std, conv) is used to convert the value to the type the pointer points to.

If a Nullable!T* is given rather than a T*, then it will be treated the same as if it had been T*. So, to!T will be used to convert the attribute value if the matching attribute name is present. The advantage of passing Nullable!T* instead of T* is that it's possible to distinguish between an attribute that wasn't present and one where it was present but was equivalent to T.init.

Unlike $(PHOBOS_REF getopt, std, getopt), the given range is consumed rather than taking it by $(K_REF) and leaving the attributes that weren't matched in the range (since that really doesn't work with an arbitrary range as opposed to a dynamic array). However, if the second argument of getAttrs is not a $(K_STRING) but is instead an output range that accepts the element type of the range, then any attributes which aren't matched are put into the output range.

  1. void getAttrs(R attrRange, Args args)
  2. void getAttrs(R attrRange, OR unmatched, Args args)
    void
    getAttrs
    (
    R
    OR
    Args...
    )
    (,
    ref OR unmatched
    ,
    Args args
    )
    if (
    isOutputRange!(OR, ElementType!R)
    &&
    Args.length % 2 == 0
    )

Parameters

attrRange R

A range of attributes (see isAttrRange).

unmatched OR

An output range that any _unmatched attributes from the range are put into (optional argument).

args Args

An alternating list of strings and pointers where the names represent the attribute names to get the value of, and the corresponding values get assigned to what the pointers point to.

Throws

XMLParsingException if $(PHOBOS_REF to, std, conv) fails to convert an attribute value.

See Also

Meta