Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/file_path.h" | 5 #include "base/file_path.h" |
| 6 #include "base/file_util.h" | |
|
Erik does not do reviews
2009/01/12 17:14:05
maybe it's worth adding a comment here so that oth
| |
| 7 #include "base/logging.h" | 6 #include "base/logging.h" |
| 8 | 7 |
| 9 // These includes are just for the *Hack functions, and should be removed | 8 // These includes are just for the *Hack functions, and should be removed |
| 10 // when those functions are removed. | 9 // when those functions are removed. |
| 11 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
| 12 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 13 #include "base/sys_string_conversions.h" | 12 #include "base/sys_string_conversions.h" |
| 14 | 13 |
| 15 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 14 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 16 const FilePath::CharType FilePath::kSeparators[] = FILE_PATH_LITERAL("\\/"); | 15 const FilePath::CharType FilePath::kSeparators[] = FILE_PATH_LITERAL("\\/"); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 } | 249 } |
| 251 | 250 |
| 252 FilePath FilePath::Append(const FilePath& component) const { | 251 FilePath FilePath::Append(const FilePath& component) const { |
| 253 return Append(component.value()); | 252 return Append(component.value()); |
| 254 } | 253 } |
| 255 | 254 |
| 256 bool FilePath::IsAbsolute() const { | 255 bool FilePath::IsAbsolute() const { |
| 257 return IsPathAbsolute(path_); | 256 return IsPathAbsolute(path_); |
| 258 } | 257 } |
| 259 | 258 |
| 260 bool FilePath::Contains(const FilePath &other) const { | |
| 261 FilePath parent = FilePath(*this); | |
| 262 FilePath child = FilePath(other); | |
| 263 | |
| 264 if (!file_util::AbsolutePath(&parent) || !file_util::AbsolutePath(&child)) | |
| 265 return false; | |
| 266 | |
| 267 #if defined(OS_WIN) | |
| 268 // file_util::AbsolutePath() does not flatten case on Windows, so we must do | |
| 269 // a case-insensitive compare. | |
| 270 if (!StartsWith(child.value(), parent.value(), false)) | |
| 271 #else | |
| 272 if (!StartsWithASCII(child.value(), parent.value(), true)) | |
| 273 #endif | |
| 274 return false; | |
| 275 | |
| 276 // file_util::AbsolutePath() normalizes '/' to '\' on Windows, so we only need | |
| 277 // to check kSeparators[0]. | |
| 278 if (child.value().length() <= parent.value().length() || | |
| 279 child.value()[parent.value().length()] != kSeparators[0]) | |
| 280 return false; | |
| 281 | |
| 282 return true; | |
| 283 } | |
| 284 | |
| 285 #if defined(OS_POSIX) | 259 #if defined(OS_POSIX) |
| 286 // See file_path.h for a discussion of the encoding of paths on POSIX | 260 // See file_path.h for a discussion of the encoding of paths on POSIX |
| 287 // platforms. These *Hack() functions are not quite correct, but they're | 261 // platforms. These *Hack() functions are not quite correct, but they're |
| 288 // only temporary while we fix the remainder of the code. | 262 // only temporary while we fix the remainder of the code. |
| 289 // Remember to remove the #includes at the top when you remove these. | 263 // Remember to remove the #includes at the top when you remove these. |
| 290 | 264 |
| 291 // static | 265 // static |
| 292 FilePath FilePath::FromWStringHack(const std::wstring& wstring) { | 266 FilePath FilePath::FromWStringHack(const std::wstring& wstring) { |
| 293 return FilePath(base::SysWideToNativeMB(wstring)); | 267 return FilePath(base::SysWideToNativeMB(wstring)); |
| 294 } | 268 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 --pos) { | 300 --pos) { |
| 327 // If the string only has two separators and they're at the beginning, | 301 // If the string only has two separators and they're at the beginning, |
| 328 // don't strip them, unless the string began with more than two separators. | 302 // don't strip them, unless the string began with more than two separators. |
| 329 if (pos != start + 1 || last_stripped == start + 2 || | 303 if (pos != start + 1 || last_stripped == start + 2 || |
| 330 !IsSeparator(path_[start - 1])) { | 304 !IsSeparator(path_[start - 1])) { |
| 331 path_.resize(pos - 1); | 305 path_.resize(pos - 1); |
| 332 last_stripped = pos; | 306 last_stripped = pos; |
| 333 } | 307 } |
| 334 } | 308 } |
| 335 } | 309 } |
| OLD | NEW |