include method

List<String> include(
  1. List<String>? list, {
  2. void added(
    1. String path
    )?,
  3. void removed(
    1. String path
    )?,
})

Returns a list of paths from which will be removed elements that do not match this filter.

Parameters: list List of paths. added A function that is called whenever an item is added. removed A function that is called whenever an item is removed.

Implementation

List<String> include(List<String>? list,
    {void Function(String path)? added,
    void Function(String path)? removed}) {
  if (list == null) {
    throw ArgumentError.notNull('list');
  }

  final result = <String>[];
  for (var element in list) {
    var path = element;
    if (_isWindows) {
      path = path.replaceAll('\\', '/');
    }

    if (_onlyDirectory!) {
      if (_isDirectory(path)) {
        path += '/';
      }
    }

    if (_glob.match(path)) {
      result.add(element);
      if (added != null) {
        added(path);
      }
    } else {
      if (removed != null) {
        removed(path);
      }
    }
  }

  return result;
}