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/logging.h" | 10 #include "base/logging.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // returns npos. | 46 // returns npos. |
47 StringPieceType::size_type FindDriveLetter(StringPieceType path) { | 47 StringPieceType::size_type FindDriveLetter(StringPieceType path) { |
48 #if defined(FILE_PATH_USES_DRIVE_LETTERS) | 48 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
49 // This is dependent on an ASCII-based character set, but that's a | 49 // This is dependent on an ASCII-based character set, but that's a |
50 // reasonable assumption. iswalpha can be too inclusive here. | 50 // reasonable assumption. iswalpha can be too inclusive here. |
51 if (path.length() >= 2 && path[1] == L':' && | 51 if (path.length() >= 2 && path[1] == L':' && |
52 ((path[0] >= L'A' && path[0] <= L'Z') || | 52 ((path[0] >= L'A' && path[0] <= L'Z') || |
53 (path[0] >= L'a' && path[0] <= L'z'))) { | 53 (path[0] >= L'a' && path[0] <= L'z'))) { |
54 return 1; | 54 return 1; |
55 } | 55 } |
| 56 #else |
| 57 (void)path; // Avoid an unused warning. |
56 #endif // FILE_PATH_USES_DRIVE_LETTERS | 58 #endif // FILE_PATH_USES_DRIVE_LETTERS |
57 return StringType::npos; | 59 return StringType::npos; |
58 } | 60 } |
59 | 61 |
60 #if defined(FILE_PATH_USES_DRIVE_LETTERS) | 62 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
61 bool EqualDriveLetterCaseInsensitive(StringPieceType a, StringPieceType b) { | 63 bool EqualDriveLetterCaseInsensitive(StringPieceType a, StringPieceType b) { |
62 size_t a_letter_pos = FindDriveLetter(a); | 64 size_t a_letter_pos = FindDriveLetter(a); |
63 size_t b_letter_pos = FindDriveLetter(b); | 65 size_t b_letter_pos = FindDriveLetter(b); |
64 | 66 |
65 if (a_letter_pos == StringType::npos || b_letter_pos == StringType::npos) | 67 if (a_letter_pos == StringType::npos || b_letter_pos == StringType::npos) |
(...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1312 FilePath FilePath::NormalizePathSeparatorsTo(CharType separator) const { | 1314 FilePath FilePath::NormalizePathSeparatorsTo(CharType separator) const { |
1313 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 1315 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
1314 DCHECK_NE(kSeparators + kSeparatorsLength, | 1316 DCHECK_NE(kSeparators + kSeparatorsLength, |
1315 std::find(kSeparators, kSeparators + kSeparatorsLength, separator)); | 1317 std::find(kSeparators, kSeparators + kSeparatorsLength, separator)); |
1316 StringType copy = path_; | 1318 StringType copy = path_; |
1317 for (size_t i = 0; i < kSeparatorsLength; ++i) { | 1319 for (size_t i = 0; i < kSeparatorsLength; ++i) { |
1318 std::replace(copy.begin(), copy.end(), kSeparators[i], separator); | 1320 std::replace(copy.begin(), copy.end(), kSeparators[i], separator); |
1319 } | 1321 } |
1320 return FilePath(copy); | 1322 return FilePath(copy); |
1321 #else | 1323 #else |
| 1324 (void)separator; // Avoid an unused warning. |
1322 return *this; | 1325 return *this; |
1323 #endif | 1326 #endif |
1324 } | 1327 } |
1325 | 1328 |
1326 #if defined(OS_ANDROID) | 1329 #if defined(OS_ANDROID) |
1327 bool FilePath::IsContentUri() const { | 1330 bool FilePath::IsContentUri() const { |
1328 return StartsWith(path_, "content://", base::CompareCase::INSENSITIVE_ASCII); | 1331 return StartsWith(path_, "content://", base::CompareCase::INSENSITIVE_ASCII); |
1329 } | 1332 } |
1330 #endif | 1333 #endif |
1331 | 1334 |
1332 } // namespace base | 1335 } // namespace base |
OLD | NEW |