Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: base/files/file_path.cc

Issue 1997153002: libchrome: Several upstreamable fixes from libchrome Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: Also fix unit tests Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Avoid an unused warning.
58 (void)path;
56 #endif // FILE_PATH_USES_DRIVE_LETTERS 59 #endif // FILE_PATH_USES_DRIVE_LETTERS
57 return StringType::npos; 60 return StringType::npos;
58 } 61 }
59 62
60 #if defined(FILE_PATH_USES_DRIVE_LETTERS) 63 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
61 bool EqualDriveLetterCaseInsensitive(StringPieceType a, StringPieceType b) { 64 bool EqualDriveLetterCaseInsensitive(StringPieceType a, StringPieceType b) {
62 size_t a_letter_pos = FindDriveLetter(a); 65 size_t a_letter_pos = FindDriveLetter(a);
63 size_t b_letter_pos = FindDriveLetter(b); 66 size_t b_letter_pos = FindDriveLetter(b);
64 67
65 if (a_letter_pos == StringType::npos || b_letter_pos == StringType::npos) 68 if (a_letter_pos == StringType::npos || b_letter_pos == StringType::npos)
(...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 FilePath FilePath::NormalizePathSeparatorsTo(CharType separator) const { 1315 FilePath FilePath::NormalizePathSeparatorsTo(CharType separator) const {
1313 #if defined(FILE_PATH_USES_WIN_SEPARATORS) 1316 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
1314 DCHECK_NE(kSeparators + kSeparatorsLength, 1317 DCHECK_NE(kSeparators + kSeparatorsLength,
1315 std::find(kSeparators, kSeparators + kSeparatorsLength, separator)); 1318 std::find(kSeparators, kSeparators + kSeparatorsLength, separator));
1316 StringType copy = path_; 1319 StringType copy = path_;
1317 for (size_t i = 0; i < kSeparatorsLength; ++i) { 1320 for (size_t i = 0; i < kSeparatorsLength; ++i) {
1318 std::replace(copy.begin(), copy.end(), kSeparators[i], separator); 1321 std::replace(copy.begin(), copy.end(), kSeparators[i], separator);
1319 } 1322 }
1320 return FilePath(copy); 1323 return FilePath(copy);
1321 #else 1324 #else
1325 // Avoid an unused warning.
1326 (void)separator;
1322 return *this; 1327 return *this;
1323 #endif 1328 #endif
1324 } 1329 }
1325 1330
1326 #if defined(OS_ANDROID) 1331 #if defined(OS_ANDROID)
1327 bool FilePath::IsContentUri() const { 1332 bool FilePath::IsContentUri() const {
1328 return StartsWith(path_, "content://", base::CompareCase::INSENSITIVE_ASCII); 1333 return StartsWith(path_, "content://", base::CompareCase::INSENSITIVE_ASCII);
1329 } 1334 }
1330 #endif 1335 #endif
1331 1336
1332 } // namespace base 1337 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698