• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 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/safe_base_name.h"
6 
7 namespace base {
8 
9 // static
Create(const FilePath & path)10 absl::optional<SafeBaseName> SafeBaseName::Create(const FilePath& path) {
11   auto basename = path.BaseName();
12 
13   if (!basename.IsAbsolute() && !basename.ReferencesParent() &&
14       !basename.EndsWithSeparator()) {
15     return absl::make_optional(SafeBaseName(basename));
16   }
17 
18   return absl::nullopt;
19 }
20 
21 // static
Create(FilePath::StringPieceType path)22 absl::optional<SafeBaseName> SafeBaseName::Create(
23     FilePath::StringPieceType path) {
24   return Create(FilePath(path));
25 }
26 
SafeBaseName(const FilePath & path)27 SafeBaseName::SafeBaseName(const FilePath& path) : path_(path) {}
28 
operator ==(const SafeBaseName & that) const29 bool SafeBaseName::operator==(const SafeBaseName& that) const {
30   return path_ == that.path_;
31 }
32 
33 }  // namespace base
34