addAttribute method

void addAttribute(
  1. String name,
  2. String? matcher,
  3. String? value
)

Implementation

void addAttribute(String name, String? matcher, String? value) {
  value = value?.toLowerCase();
  if (matcher == null) {
    attrs.add(SetAttributeMatcher(name));
  } else if (matcher == '=') {
    attrs.add(ExactAttributeMatcher(name, value));
  } else if (value!.isNotEmpty) {
    // The following attribute selectors match nothing if the attribute value
    // is the empty string, so we only add them if they can match.
    switch (matcher) {
      case '~=':
        attrs.add(ListAttributeMatcher(name, value));
        break;
      case '|=':
        attrs.add(HyphenAttributeMatcher(name, value));
        break;
      case '^=':
        attrs.add(PrefixAttributeMatcher(name, value));
        break;
      case r'$=':
        attrs.add(SuffixAttributeMatcher(name, value));
        break;
      case '*=':
        attrs.add(SubstringAttributeMatcher(name, value));
        break;
    }
  }
}