safe_base_name.cc 855 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/files/safe_base_name.h"
  5. namespace base {
  6. // static
  7. absl::optional<SafeBaseName> SafeBaseName::Create(const FilePath& path) {
  8. auto basename = path.BaseName();
  9. if (!basename.IsAbsolute() && !basename.ReferencesParent() &&
  10. !basename.EndsWithSeparator()) {
  11. return absl::make_optional(SafeBaseName(basename));
  12. }
  13. return absl::nullopt;
  14. }
  15. // static
  16. absl::optional<SafeBaseName> SafeBaseName::Create(
  17. FilePath::StringPieceType path) {
  18. return Create(FilePath(path));
  19. }
  20. SafeBaseName::SafeBaseName(const FilePath& path) : path_(path) {}
  21. bool SafeBaseName::operator==(const SafeBaseName& that) const {
  22. return path_ == that.path_;
  23. }
  24. } // namespace base