<commit_before>part of domnode;

/**
 * This class allows operating with CSS attributes.
 */
abstract class CssCapable {
  List<Element> get elements;

  String getCssAttr(String name) {
    String ret = '';

    if (elements.length > 0) {
      Map<String, String> attrs = _getCssAttrMap(elements[0]);

      name = name.toLowerCase();
      if (attrs.containsKey(name)) {
        ret = attrs[name];
      }
    }

    return ret;
  }

  void setCssAttr(String name, String value) {
    elements.forEach((Element element) {
      Map<String, String> attrs = _getCssAttrMap(element);

      attrs[name] = value;
      _setCssAttrMap(element, attrs);
    });
  }

  Map<String, String> _getCssAttrMap(Element element) {
    Map<String, String> ret = new Map<String, String>();
    String css = element.getAttribute('style');

    if (css != null) {
      css.split(';').forEach((String cssAttr) {
        List<String> item = cssAttr.split(':');
        String key = item.length > 0 ? item[0].trim().toLowerCase() : '';
        String value = item.length > 1 ? item[1].trim() : '';

        if (key.length > 0 && value.length > 0) {
          ret[key] = value;
        }
      });
    }

    return ret;
  }

  void _setCssAttrMap(Element element, Map<String, String> attrs) {
    List<String> arr = new List<String>();

    attrs.keys.forEach((String key) {
      if (key != null && key.length > 0) {
        arr.add(key.toLowerCase() + ': ' + attrs[key]);
      }
    });

    element.setAttribute('style', arr.join('; '));
  }
}<commit_msg>css attribute<commit_after>part of domnode;

/**
 * This class allows operating with CSS attributes.
 */
abstract class CssCapable {
  Map<String, Object> get css => new _CssAttrManager(this);

  List<Element> get elements;
}

class _CssAttrManager extends MapBase<String, Object> {
  final DomNode _target;

  _CssAttrManager(this._target);

  Iterable<String> get keys {
    Iterable<String> ret;
    for (Element element in _target.elements) {
      Map<String, String> attrs = _getCssAttrMap(element);
      ret = attrs.keys;
      break;
    }
    return ret;
  }

  String operator [](Object key) {
    String ret;
    for (Element element in _target.elements) {
      Map<String, String> attrs = _getCssAttrMap(element);
      ret = attrs[key.toString()];
      break;
    }
    return ret;
  }

  void operator []=(String key, Object value) {
    for (Element element in _target.elements) {
      Map<String, String> attrs = _getCssAttrMap(element);
      attrs[key] = value.toString();
      _setCssAttrMap(element, attrs);
    }
  }

  void clear() {
    for (Element element in _target.elements) {
      _setCssAttrMap(element, {});
    }
  }

  String remove(Object key) {
    String ret = null;
    for (Element element in _target.elements) {
      Map<String, String> attrs = _getCssAttrMap(element);
      ret = attrs.remove(key.toString());
      _setCssAttrMap(element, attrs);
    }
    return ret;
  }

  // TODO: si el atributo no existe, debería devolver null
  Map<String, String> _getCssAttrMap(Element element) {
    Map<String, String> ret = new Map<String, String>();
    String css = element.getAttribute('style');

    if (css != null) {
      css.split(';').forEach((String cssAttr) {
        List<String> item = cssAttr.split(':');
        String key = item.length > 0 ? item[0].trim().toLowerCase() : '';
        String value = item.length > 1 ? item[1].trim() : '';

        if (key.length > 0 && value.length > 0) {
          ret[key] = value;
        }
      });
    }

    return ret;
  }

  void _setCssAttrMap(Element element, Map<String, String> attrs) {
    List<String> arr = [];

    attrs.keys.forEach((String key) {
      if (key != null && key.length > 0) {
        arr.add(key.toLowerCase() + ': ' + attrs[key]);
      }
    });

    element.setAttribute('style', arr.join('; '));
  }
}
{'fraction_non_alphanumeric': 0.14695247933884298, 'fraction_numerical': 0.004132231404958678, 'mean_word_length': 2.7097701149425286, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5797604', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1253, 'n_words': 299}