Skip to main content

normalize_attribute_value

Function normalize_attribute_value 

Source
pub fn normalize_attribute_value<'input, 'entity, C, E, F>(
    value: &'input str,
    depth: usize,
    is_normalization_char: C,
    normalize_eol_step: E,
    resolve_entity: F,
) -> Result<Cow<'input, str>, EscapeError>
where C: Fn(&u8) -> bool, E: Fn(&mut String, &str, usize, char) -> usize, F: FnMut(&str) -> Option<&'entity str>,
Expand description

Returns the attribute value normalized as per the XML specification, using a custom entity resolver.

Do not use this method with HTML attributes.

Escape sequences such as &gt; are replaced with their unescaped equivalents such as > and the characters \t, \r, \n are replaced with whitespace characters. A function for resolving entities can be provided as resolve_entity. Builtin entities will still take precedence.

This will allocate unless the raw attribute value does not require normalization.

§Parameters

  • value: unnormalized attribute value
  • depth: maximum number of nested entities that can be expanded. If expansion chain will be more that this value, the function will return EscapeError::TooManyNestedEntities
  • is_normalization_char: a function to check if byte is the start byte of character that should be normalized (UTF-8 encoding is assumed)
  • normalize_eol_step: a function that performs EOL normalization of a character
  • resolve_entity: a function to resolve entity. This function could be called multiple times on the same input and can return different values in each case for the same input, although it is not recommended

§Lifetimes

  • 'input: lifetime of the unnormalized attribute. If normalization is not required, the input returned unchanged with the same lifetime
  • 'entity: lifetime of all entities that is returned by the entity resolution routine