OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 } | 513 } |
514 | 514 |
515 #if defined(OS_POSIX) | 515 #if defined(OS_POSIX) |
516 // See file_path.h for a discussion of the encoding of paths on POSIX | 516 // See file_path.h for a discussion of the encoding of paths on POSIX |
517 // platforms. These encoding conversion functions are not quite correct. | 517 // platforms. These encoding conversion functions are not quite correct. |
518 | 518 |
519 string16 FilePath::LossyDisplayName() const { | 519 string16 FilePath::LossyDisplayName() const { |
520 return WideToUTF16(base::SysNativeMBToWide(path_)); | 520 return WideToUTF16(base::SysNativeMBToWide(path_)); |
521 } | 521 } |
522 | 522 |
| 523 std::string FilePath::MaybeAsASCII() const { |
| 524 if (IsStringASCII(path_)) |
| 525 return path_; |
| 526 return ""; |
| 527 } |
| 528 |
523 // The *Hack functions are temporary while we fix the remainder of the code. | 529 // The *Hack functions are temporary while we fix the remainder of the code. |
524 // Remember to remove the #includes at the top when you remove these. | 530 // Remember to remove the #includes at the top when you remove these. |
525 | 531 |
526 // static | 532 // static |
527 FilePath FilePath::FromWStringHack(const std::wstring& wstring) { | 533 FilePath FilePath::FromWStringHack(const std::wstring& wstring) { |
528 return FilePath(base::SysWideToNativeMB(wstring)); | 534 return FilePath(base::SysWideToNativeMB(wstring)); |
529 } | 535 } |
530 std::wstring FilePath::ToWStringHack() const { | 536 std::wstring FilePath::ToWStringHack() const { |
531 return base::SysNativeMBToWide(path_); | 537 return base::SysNativeMBToWide(path_); |
532 } | 538 } |
533 #elif defined(OS_WIN) | 539 #elif defined(OS_WIN) |
534 string16 FilePath::LossyDisplayName() const { | 540 string16 FilePath::LossyDisplayName() const { |
535 return path_; | 541 return path_; |
536 } | 542 } |
537 | 543 |
| 544 std::string FilePath::MaybeAsASCII() const { |
| 545 if (IsStringASCII(path_)) |
| 546 return WideToASCII(path_); |
| 547 return ""; |
| 548 } |
| 549 |
538 // static | 550 // static |
539 FilePath FilePath::FromWStringHack(const std::wstring& wstring) { | 551 FilePath FilePath::FromWStringHack(const std::wstring& wstring) { |
540 return FilePath(wstring); | 552 return FilePath(wstring); |
541 } | 553 } |
542 std::wstring FilePath::ToWStringHack() const { | 554 std::wstring FilePath::ToWStringHack() const { |
543 return path_; | 555 return path_; |
544 } | 556 } |
545 #endif | 557 #endif |
546 | 558 |
547 // static. | 559 // static. |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 | 1207 |
1196 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 1208 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
1197 FilePath FilePath::NormalizeWindowsPathSeparators() const { | 1209 FilePath FilePath::NormalizeWindowsPathSeparators() const { |
1198 StringType copy = path_; | 1210 StringType copy = path_; |
1199 for (size_t i = 1; i < arraysize(kSeparators); ++i) { | 1211 for (size_t i = 1; i < arraysize(kSeparators); ++i) { |
1200 std::replace(copy.begin(), copy.end(), kSeparators[i], kSeparators[0]); | 1212 std::replace(copy.begin(), copy.end(), kSeparators[i], kSeparators[0]); |
1201 } | 1213 } |
1202 return FilePath(copy); | 1214 return FilePath(copy); |
1203 } | 1215 } |
1204 #endif | 1216 #endif |
OLD | NEW |