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 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 | 603 |
604 string16 FilePath::AsUTF16Unsafe() const { | 604 string16 FilePath::AsUTF16Unsafe() const { |
605 #if defined(SYSTEM_NATIVE_UTF8) | 605 #if defined(SYSTEM_NATIVE_UTF8) |
606 return UTF8ToUTF16(value()); | 606 return UTF8ToUTF16(value()); |
607 #else | 607 #else |
608 return WideToUTF16(SysNativeMBToWide(value())); | 608 return WideToUTF16(SysNativeMBToWide(value())); |
609 #endif | 609 #endif |
610 } | 610 } |
611 | 611 |
612 // static | 612 // static |
613 FilePath FilePath::FromUTF8Unsafe(const std::string& utf8) { | 613 FilePath FilePath::FromUTF8Unsafe(StringPiece utf8) { |
614 #if defined(SYSTEM_NATIVE_UTF8) | 614 #if defined(SYSTEM_NATIVE_UTF8) |
615 return FilePath(utf8); | 615 return FilePath(utf8); |
616 #else | 616 #else |
617 return FilePath(SysWideToNativeMB(UTF8ToWide(utf8))); | 617 return FilePath(SysWideToNativeMB(UTF8ToWide(utf8))); |
618 #endif | 618 #endif |
619 } | 619 } |
620 | 620 |
621 // static | 621 // static |
622 FilePath FilePath::FromUTF16Unsafe(const string16& utf16) { | 622 FilePath FilePath::FromUTF16Unsafe(StringPiece16 utf16) { |
623 #if defined(SYSTEM_NATIVE_UTF8) | 623 #if defined(SYSTEM_NATIVE_UTF8) |
624 return FilePath(UTF16ToUTF8(utf16)); | 624 return FilePath(UTF16ToUTF8(utf16)); |
625 #else | 625 #else |
626 return FilePath(SysWideToNativeMB(UTF16ToWide(utf16))); | 626 return FilePath(SysWideToNativeMB(UTF16ToWide(utf16.as_string()))); |
627 #endif | 627 #endif |
628 } | 628 } |
629 | 629 |
630 #elif defined(OS_WIN) | 630 #elif defined(OS_WIN) |
631 string16 FilePath::LossyDisplayName() const { | 631 string16 FilePath::LossyDisplayName() const { |
632 return path_; | 632 return path_; |
633 } | 633 } |
634 | 634 |
635 std::string FilePath::MaybeAsASCII() const { | 635 std::string FilePath::MaybeAsASCII() const { |
636 if (base::IsStringASCII(path_)) | 636 if (base::IsStringASCII(path_)) |
637 return UTF16ToASCII(path_); | 637 return UTF16ToASCII(path_); |
638 return std::string(); | 638 return std::string(); |
639 } | 639 } |
640 | 640 |
641 std::string FilePath::AsUTF8Unsafe() const { | 641 std::string FilePath::AsUTF8Unsafe() const { |
642 return WideToUTF8(value()); | 642 return WideToUTF8(value()); |
643 } | 643 } |
644 | 644 |
645 string16 FilePath::AsUTF16Unsafe() const { | 645 string16 FilePath::AsUTF16Unsafe() const { |
646 return value(); | 646 return value(); |
647 } | 647 } |
648 | 648 |
649 // static | 649 // static |
650 FilePath FilePath::FromUTF8Unsafe(const std::string& utf8) { | 650 FilePath FilePath::FromUTF8Unsafe(StringPiece utf8) { |
651 return FilePath(UTF8ToWide(utf8)); | 651 return FilePath(UTF8ToWide(utf8)); |
652 } | 652 } |
653 | 653 |
654 // static | 654 // static |
655 FilePath FilePath::FromUTF16Unsafe(const string16& utf16) { | 655 FilePath FilePath::FromUTF16Unsafe(StringPiece16 utf16) { |
656 return FilePath(utf16); | 656 return FilePath(utf16); |
657 } | 657 } |
658 #endif | 658 #endif |
659 | 659 |
660 void FilePath::GetSizeForPickle(PickleSizer* sizer) const { | 660 void FilePath::GetSizeForPickle(PickleSizer* sizer) const { |
661 #if defined(OS_WIN) | 661 #if defined(OS_WIN) |
662 sizer->AddString16(path_); | 662 sizer->AddString16(path_); |
663 #else | 663 #else |
664 sizer->AddString(path_); | 664 sizer->AddString(path_); |
665 #endif | 665 #endif |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1321 #endif | 1321 #endif |
1322 } | 1322 } |
1323 | 1323 |
1324 #if defined(OS_ANDROID) | 1324 #if defined(OS_ANDROID) |
1325 bool FilePath::IsContentUri() const { | 1325 bool FilePath::IsContentUri() const { |
1326 return StartsWith(path_, "content://", base::CompareCase::INSENSITIVE_ASCII); | 1326 return StartsWith(path_, "content://", base::CompareCase::INSENSITIVE_ASCII); |
1327 } | 1327 } |
1328 #endif | 1328 #endif |
1329 | 1329 |
1330 } // namespace base | 1330 } // namespace base |
OLD | NEW |