| 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 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 } | 570 } |
| 571 | 571 |
| 572 std::string FilePath::AsUTF8Unsafe() const { | 572 std::string FilePath::AsUTF8Unsafe() const { |
| 573 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) | 573 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 574 return value(); | 574 return value(); |
| 575 #else | 575 #else |
| 576 return WideToUTF8(SysNativeMBToWide(value())); | 576 return WideToUTF8(SysNativeMBToWide(value())); |
| 577 #endif | 577 #endif |
| 578 } | 578 } |
| 579 | 579 |
| 580 string16 FilePath::AsUTF16Unsafe() const { |
| 581 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 582 return UTF8ToUTF16(value()); |
| 583 #else |
| 584 return WideToUTF16(SysNativeMBToWide(value())); |
| 585 #endif |
| 586 } |
| 587 |
| 580 // The *Hack functions are temporary while we fix the remainder of the code. | 588 // The *Hack functions are temporary while we fix the remainder of the code. |
| 581 // Remember to remove the #includes at the top when you remove these. | 589 // Remember to remove the #includes at the top when you remove these. |
| 582 | 590 |
| 583 // static | 591 // static |
| 584 FilePath FilePath::FromWStringHack(const std::wstring& wstring) { | 592 FilePath FilePath::FromWStringHack(const std::wstring& wstring) { |
| 585 return FilePath(SysWideToNativeMB(wstring)); | 593 return FilePath(SysWideToNativeMB(wstring)); |
| 586 } | 594 } |
| 587 | 595 |
| 588 // static | 596 // static |
| 589 FilePath FilePath::FromUTF8Unsafe(const std::string& utf8) { | 597 FilePath FilePath::FromUTF8Unsafe(const std::string& utf8) { |
| 590 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) | 598 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 591 return FilePath(utf8); | 599 return FilePath(utf8); |
| 592 #else | 600 #else |
| 593 return FilePath(SysWideToNativeMB(UTF8ToWide(utf8))); | 601 return FilePath(SysWideToNativeMB(UTF8ToWide(utf8))); |
| 594 #endif | 602 #endif |
| 595 } | 603 } |
| 596 | 604 |
| 605 // static |
| 606 FilePath FilePath::FromUTF16Unsafe(const string16& utf16) { |
| 607 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 608 return FilePath(UTF16ToUTF8(utf16)); |
| 609 #else |
| 610 return FilePath(SysWideToNativeMB(UTF16ToWide(utf16))); |
| 611 #endif |
| 612 } |
| 613 |
| 597 #elif defined(OS_WIN) | 614 #elif defined(OS_WIN) |
| 598 string16 FilePath::LossyDisplayName() const { | 615 string16 FilePath::LossyDisplayName() const { |
| 599 return path_; | 616 return path_; |
| 600 } | 617 } |
| 601 | 618 |
| 602 std::string FilePath::MaybeAsASCII() const { | 619 std::string FilePath::MaybeAsASCII() const { |
| 603 if (IsStringASCII(path_)) | 620 if (IsStringASCII(path_)) |
| 604 return WideToASCII(path_); | 621 return WideToASCII(path_); |
| 605 return ""; | 622 return ""; |
| 606 } | 623 } |
| 607 | 624 |
| 608 std::string FilePath::AsUTF8Unsafe() const { | 625 std::string FilePath::AsUTF8Unsafe() const { |
| 609 return WideToUTF8(value()); | 626 return WideToUTF8(value()); |
| 610 } | 627 } |
| 611 | 628 |
| 629 string16 FilePath::AsUTF16Unsafe() const { |
| 630 return value(); |
| 631 } |
| 632 |
| 612 // static | 633 // static |
| 613 FilePath FilePath::FromWStringHack(const std::wstring& wstring) { | 634 FilePath FilePath::FromWStringHack(const std::wstring& wstring) { |
| 614 return FilePath(wstring); | 635 return FilePath(wstring); |
| 615 } | 636 } |
| 616 | 637 |
| 617 // static | 638 // static |
| 618 FilePath FilePath::FromUTF8Unsafe(const std::string& utf8) { | 639 FilePath FilePath::FromUTF8Unsafe(const std::string& utf8) { |
| 619 return FilePath(UTF8ToWide(utf8)); | 640 return FilePath(UTF8ToWide(utf8)); |
| 620 } | 641 } |
| 642 |
| 643 // static |
| 644 FilePath FilePath::FromUTF16Unsafe(const string16& utf16) { |
| 645 return FilePath(utf16); |
| 646 } |
| 621 #endif | 647 #endif |
| 622 | 648 |
| 623 void FilePath::WriteToPickle(Pickle* pickle) const { | 649 void FilePath::WriteToPickle(Pickle* pickle) const { |
| 624 #if defined(OS_WIN) | 650 #if defined(OS_WIN) |
| 625 pickle->WriteString16(path_); | 651 pickle->WriteString16(path_); |
| 626 #else | 652 #else |
| 627 pickle->WriteString(path_); | 653 pickle->WriteString(path_); |
| 628 #endif | 654 #endif |
| 629 } | 655 } |
| 630 | 656 |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 #else | 1291 #else |
| 1266 return *this; | 1292 return *this; |
| 1267 #endif | 1293 #endif |
| 1268 } | 1294 } |
| 1269 | 1295 |
| 1270 } // namespace base | 1296 } // namespace base |
| 1271 | 1297 |
| 1272 void PrintTo(const base::FilePath& path, std::ostream* out) { | 1298 void PrintTo(const base::FilePath& path, std::ostream* out) { |
| 1273 *out << path.value(); | 1299 *out << path.value(); |
| 1274 } | 1300 } |
| OLD | NEW |