| 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 | 6 |
| 7 // These includes are just for the *Hack functions, and should be removed | 7 // These includes are just for the *Hack functions, and should be removed |
| 8 // when those functions are removed. | 8 // when those functions are removed. |
| 9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| 11 | 11 |
| 12 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 12 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 13 const FilePath::CharType FilePath::kSeparators[] = FILE_PATH_LITERAL("\\/"); | 13 const FilePath::CharType FilePath::kSeparators[] = FILE_PATH_LITERAL("\\/"); |
| 14 #else // FILE_PATH_USES_WIN_SEPARATORS | 14 #else // FILE_PATH_USES_WIN_SEPARATORS |
| 15 const FilePath::CharType FilePath::kSeparators[] = FILE_PATH_LITERAL("/"); | 15 const FilePath::CharType FilePath::kSeparators[] = FILE_PATH_LITERAL("/"); |
| 16 #endif // FILE_PATH_USES_WIN_SEPARATORS | 16 #endif // FILE_PATH_USES_WIN_SEPARATORS |
| 17 | 17 |
| 18 const FilePath::CharType FilePath::kCurrentDirectory[] = FILE_PATH_LITERAL("."); | 18 const FilePath::CharType FilePath::kCurrentDirectory[] = FILE_PATH_LITERAL("."); |
| 19 const FilePath::CharType FilePath::kParentDirectory[] = FILE_PATH_LITERAL(".."); | 19 const FilePath::CharType FilePath::kParentDirectory[] = FILE_PATH_LITERAL(".."); |
| 20 | 20 |
| 21 // Returns true if |character| is in kSeparators. | 21 bool FilePath::IsSeparator(CharType character) { |
| 22 static bool IsSeparator(FilePath::CharType character) { | 22 for (size_t i = 0; i < arraysize(kSeparators) - 1; ++i) { |
| 23 for (size_t i = 0; i < arraysize(FilePath::kSeparators) - 1; ++i) { | 23 if (character == kSeparators[i]) { |
| 24 if (character == FilePath::kSeparators[i]) { | |
| 25 return true; | 24 return true; |
| 26 } | 25 } |
| 27 } | 26 } |
| 28 | 27 |
| 29 return false; | 28 return false; |
| 30 } | 29 } |
| 31 | 30 |
| 32 // libgen's dirname and basename aren't guaranteed to be thread-safe and aren't | 31 // libgen's dirname and basename aren't guaranteed to be thread-safe and aren't |
| 33 // guaranteed to not modify their input strings, and in fact are implmeneted | 32 // guaranteed to not modify their input strings, and in fact are implmeneted |
| 34 // differently in this regard on different platforms. Don't use them, but | 33 // differently in this regard on different platforms. Don't use them, but |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 --pos) { | 193 --pos) { |
| 195 // If the string only has two separators and they're at the beginning, | 194 // If the string only has two separators and they're at the beginning, |
| 196 // don't strip them, unless the string began with more than two separators. | 195 // don't strip them, unless the string began with more than two separators. |
| 197 if (pos != start + 1 || last_stripped == start + 2 || | 196 if (pos != start + 1 || last_stripped == start + 2 || |
| 198 !IsSeparator(path_[start - 1])) { | 197 !IsSeparator(path_[start - 1])) { |
| 199 path_.resize(pos - 1); | 198 path_.resize(pos - 1); |
| 200 last_stripped = pos; | 199 last_stripped = pos; |
| 201 } | 200 } |
| 202 } | 201 } |
| 203 } | 202 } |
| OLD | NEW |