summaryrefslogtreecommitdiffstats
path: root/base/file_path.cc
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-18 08:38:16 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-18 08:38:16 +0000
commit406810e402674f6ef1f8248c12a6b4f4a0223a8d (patch)
tree22d715c0e61f34f4679fa54bb5889010e07fde7e /base/file_path.cc
parent5940ca44ad8aedc988f87e879089e45ac266db2a (diff)
downloadchromium_src-406810e402674f6ef1f8248c12a6b4f4a0223a8d.zip
chromium_src-406810e402674f6ef1f8248c12a6b4f4a0223a8d.tar.gz
chromium_src-406810e402674f6ef1f8248c12a6b4f4a0223a8d.tar.bz2
Rather than create a TODO that will never be done, I went ahead and implemented FilePath::Contains().
Review URL: http://codereview.chromium.org/14827 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7208 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_path.cc')
-rw-r--r--base/file_path.cc27
1 files changed, 27 insertions, 0 deletions
diff --git a/base/file_path.cc b/base/file_path.cc
index a938ca6..45f6e327 100644
--- a/base/file_path.cc
+++ b/base/file_path.cc
@@ -3,11 +3,13 @@
// found in the LICENSE file.
#include "base/file_path.h"
+#include "base/file_util.h"
#include "base/logging.h"
// These includes are just for the *Hack functions, and should be removed
// when those functions are removed.
#include "base/string_piece.h"
+#include "base/string_util.h"
#include "base/sys_string_conversions.h"
#if defined(FILE_PATH_USES_WIN_SEPARATORS)
@@ -178,6 +180,31 @@ bool FilePath::IsAbsolute() const {
return IsPathAbsolute(path_);
}
+bool FilePath::Contains(const FilePath &other) const {
+ FilePath parent = FilePath(*this);
+ FilePath child = FilePath(other);
+
+ if (!file_util::AbsolutePath(&parent) || !file_util::AbsolutePath(&child))
+ return false;
+
+#if defined(OS_WIN)
+ // file_util::AbsolutePath() does not flatten case on Windows, so we must do
+ // a case-insensitive compare.
+ if (!StartsWith(child.value(), parent.value(), false))
+#else
+ if (!StartsWithASCII(child.value(), parent.value(), true))
+#endif
+ return false;
+
+ // file_util::AbsolutePath() normalizes '/' to '\' on Windows, so we only need
+ // to check kSeparators[0].
+ if (child.value().length() <= parent.value().length() ||
+ child.value()[parent.value().length()] != kSeparators[0])
+ return false;
+
+ return true;
+}
+
#if defined(OS_POSIX)
// See file_path.h for a discussion of the encoding of paths on POSIX
// platforms. These *Hack() functions are not quite correct, but they're