xref: /aosp_15_r20/external/cronet/base/files/file_enumerator.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/files/file_enumerator.h"
6 
7 #include "base/files/file_util.h"
8 #include "base/functional/function_ref.h"
9 
10 namespace base {
11 
12 FileEnumerator::FileInfo::~FileInfo() = default;
13 
ShouldSkip(const FilePath & path)14 bool FileEnumerator::ShouldSkip(const FilePath& path) {
15   FilePath::StringType basename = path.BaseName().value();
16   return basename == FILE_PATH_LITERAL(".") ||
17          (basename == FILE_PATH_LITERAL("..") &&
18           !(INCLUDE_DOT_DOT & file_type_));
19 }
20 
IsTypeMatched(bool is_dir) const21 bool FileEnumerator::IsTypeMatched(bool is_dir) const {
22   return (file_type_ &
23           (is_dir ? FileEnumerator::DIRECTORIES : FileEnumerator::FILES)) != 0;
24 }
25 
ForEach(FunctionRef<void (const FilePath & path)> ref)26 void FileEnumerator::ForEach(FunctionRef<void(const FilePath& path)> ref) {
27   for (FilePath name = Next(); !name.empty(); name = Next()) {
28     ref(name);
29   }
30 }
31 
32 }  // namespace base
33