<commit_before>library xml_events.converters.subtree_selector;

import 'dart:convert' show ChunkedConversionSink;

import '../../xml/utils/exceptions.dart';
import '../../xml/utils/predicate.dart';
import '../event.dart';
import '../events/end_element_event.dart';
import '../events/start_element_event.dart';
import 'list_converter.dart';

class XmlSubtreeSelector extends XmlListConverter<XmlEvent, XmlEvent> {
  final Predicate<XmlStartElementEvent> predicate;

  const XmlSubtreeSelector(this.predicate);

  @override
  ChunkedConversionSink<List<XmlEvent>> startChunkedConversion(
          Sink<List<XmlEvent>> sink) =>
      _XmlSubtreeSelectorSink(sink, predicate);
}

class _XmlSubtreeSelectorSink extends ChunkedConversionSink<List<XmlEvent>> {
  final Sink<List<XmlEvent>> sink;
  final Predicate<XmlStartElementEvent> predicate;
  final List<XmlStartElementEvent> stack = [];<commit_msg>Add missing comment for XmlSubtreeSelector.<commit_after>library xml_events.converters.subtree_selector;

import 'dart:convert' show ChunkedConversionSink;

import '../../xml/utils/exceptions.dart';
import '../../xml/utils/predicate.dart';
import '../event.dart';
import '../events/end_element_event.dart';
import '../events/start_element_event.dart';
import 'list_converter.dart';

/// A converter that selects [XmlEvent] objects that are part of a subtree
/// started by an [XmlStartElementEvent] satisfying the provided predicate.
class XmlSubtreeSelector extends XmlListConverter<XmlEvent, XmlEvent> {
  final Predicate<XmlStartElementEvent> predicate;

  const XmlSubtreeSelector(this.predicate);

  @override
  ChunkedConversionSink<List<XmlEvent>> startChunkedConversion(
          Sink<List<XmlEvent>> sink) =>
      _XmlSubtreeSelectorSink(sink, predicate);
}

class _XmlSubtreeSelectorSink extends ChunkedConversionSink<List<XmlEvent>> {
  final Sink<List<XmlEvent>> sink;
  final Predicate<XmlStartElementEvent> predicate;
  final List<XmlStartElementEvent> stack = [];
{'fraction_non_alphanumeric': 0.11622031328954018, 'fraction_numerical': 0.0, 'mean_word_length': 5.947368421052632, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '4621421', 'n_tokens_mistral': 610, 'n_tokens_neox': 599, 'n_words': 120}