OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 // don't strip them, unless the string began with more than two separators. | 1285 // don't strip them, unless the string began with more than two separators. |
1286 if (pos != start + 1 || last_stripped == start + 2 || | 1286 if (pos != start + 1 || last_stripped == start + 2 || |
1287 !IsSeparator(path_[start - 1])) { | 1287 !IsSeparator(path_[start - 1])) { |
1288 path_.resize(pos - 1); | 1288 path_.resize(pos - 1); |
1289 last_stripped = pos; | 1289 last_stripped = pos; |
1290 } | 1290 } |
1291 } | 1291 } |
1292 } | 1292 } |
1293 | 1293 |
1294 FilePath FilePath::NormalizePathSeparators() const { | 1294 FilePath FilePath::NormalizePathSeparators() const { |
| 1295 return NormalizePathSeparatorsTo(kSeparators[0]); |
| 1296 } |
| 1297 |
| 1298 FilePath FilePath::NormalizePathSeparatorsTo(CharType separator) const { |
1295 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 1299 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 1300 DCHECK_NE(kSeparators + kSeparatorsLength, |
| 1301 std::find(kSeparators, kSeparators + kSeparatorsLength, separator)); |
1296 StringType copy = path_; | 1302 StringType copy = path_; |
1297 for (size_t i = 1; i < kSeparatorsLength; ++i) { | 1303 for (size_t i = 0; i < kSeparatorsLength; ++i) { |
1298 std::replace(copy.begin(), copy.end(), kSeparators[i], kSeparators[0]); | 1304 std::replace(copy.begin(), copy.end(), kSeparators[i], separator); |
1299 } | 1305 } |
1300 return FilePath(copy); | 1306 return FilePath(copy); |
1301 #else | 1307 #else |
1302 return *this; | 1308 return *this; |
1303 #endif | 1309 #endif |
1304 } | 1310 } |
1305 | 1311 |
1306 #if defined(OS_ANDROID) | 1312 #if defined(OS_ANDROID) |
1307 bool FilePath::IsContentUri() const { | 1313 bool FilePath::IsContentUri() const { |
1308 return StartsWithASCII(path_, "content://", false /*case_sensitive*/); | 1314 return StartsWithASCII(path_, "content://", false /*case_sensitive*/); |
1309 } | 1315 } |
1310 #endif | 1316 #endif |
1311 | 1317 |
1312 } // namespace base | 1318 } // namespace base |
1313 | 1319 |
1314 void PrintTo(const base::FilePath& path, std::ostream* out) { | 1320 void PrintTo(const base::FilePath& path, std::ostream* out) { |
1315 *out << path.value(); | 1321 *out << path.value(); |
1316 } | 1322 } |
OLD | NEW |