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

Side by Side Diff: base/file_path.cc

Issue 8402008: Add FilePath::FromUTF8Unsafe() and FilePath::AsUTF8Unsafe(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « base/file_path.h ('k') | base/file_path_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/file_path.h" 5 #include "base/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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 string16 FilePath::LossyDisplayName() const { 520 string16 FilePath::LossyDisplayName() const {
521 return WideToUTF16(base::SysNativeMBToWide(path_)); 521 return WideToUTF16(base::SysNativeMBToWide(path_));
522 } 522 }
523 523
524 std::string FilePath::MaybeAsASCII() const { 524 std::string FilePath::MaybeAsASCII() const {
525 if (IsStringASCII(path_)) 525 if (IsStringASCII(path_))
526 return path_; 526 return path_;
527 return ""; 527 return "";
528 } 528 }
529 529
530 std::string FilePath::AsUTF8Unsafe() const {
531 #if defined(OS_MACOSX) || defined(OS_CHROMEOS)
532 return value();
533 #else
534 return WideToUTF8(base::SysNativeMBToWide(value()));
535 #endif
536 }
537
530 // The *Hack functions are temporary while we fix the remainder of the code. 538 // The *Hack functions are temporary while we fix the remainder of the code.
531 // Remember to remove the #includes at the top when you remove these. 539 // Remember to remove the #includes at the top when you remove these.
532 540
533 // static 541 // static
534 FilePath FilePath::FromWStringHack(const std::wstring& wstring) { 542 FilePath FilePath::FromWStringHack(const std::wstring& wstring) {
535 return FilePath(base::SysWideToNativeMB(wstring)); 543 return FilePath(base::SysWideToNativeMB(wstring));
536 } 544 }
545
546 // static
547 FilePath FilePath::FromUTF8Unsafe(const std::string& utf8) {
548 #if defined(OS_MACOSX) || defined(OS_CHROMEOS)
549 return FilePath(utf8);
550 #else
551 return FilePath(base::SysWideToNativeMB(UTF8ToWide(utf8)));
552 #endif
553 }
554
537 #elif defined(OS_WIN) 555 #elif defined(OS_WIN)
538 string16 FilePath::LossyDisplayName() const { 556 string16 FilePath::LossyDisplayName() const {
539 return path_; 557 return path_;
540 } 558 }
541 559
542 std::string FilePath::MaybeAsASCII() const { 560 std::string FilePath::MaybeAsASCII() const {
543 if (IsStringASCII(path_)) 561 if (IsStringASCII(path_))
544 return WideToASCII(path_); 562 return WideToASCII(path_);
545 return ""; 563 return "";
546 } 564 }
547 565
566 std::string FilePath::AsUTF8Unsafe() const {
567 return WideToUTF8(value());
568 }
569
548 // static 570 // static
549 FilePath FilePath::FromWStringHack(const std::wstring& wstring) { 571 FilePath FilePath::FromWStringHack(const std::wstring& wstring) {
550 return FilePath(wstring); 572 return FilePath(wstring);
551 } 573 }
574
575 // static
576 FilePath FilePath::FromUTF8Unsafe(const std::string& utf8) {
577 return FilePath(UTF8ToWide(utf8));
578 }
552 #endif 579 #endif
553 580
554 void FilePath::WriteToPickle(Pickle* pickle) { 581 void FilePath::WriteToPickle(Pickle* pickle) {
555 #if defined(OS_WIN) 582 #if defined(OS_WIN)
556 pickle->WriteString16(path_); 583 pickle->WriteString16(path_);
557 #else 584 #else
558 pickle->WriteString(path_); 585 pickle->WriteString(path_);
559 #endif 586 #endif
560 } 587 }
561 588
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 1212
1186 #if defined(FILE_PATH_USES_WIN_SEPARATORS) 1213 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
1187 FilePath FilePath::NormalizeWindowsPathSeparators() const { 1214 FilePath FilePath::NormalizeWindowsPathSeparators() const {
1188 StringType copy = path_; 1215 StringType copy = path_;
1189 for (size_t i = 1; i < arraysize(kSeparators); ++i) { 1216 for (size_t i = 1; i < arraysize(kSeparators); ++i) {
1190 std::replace(copy.begin(), copy.end(), kSeparators[i], kSeparators[0]); 1217 std::replace(copy.begin(), copy.end(), kSeparators[i], kSeparators[0]);
1191 } 1218 }
1192 return FilePath(copy); 1219 return FilePath(copy);
1193 } 1220 }
1194 #endif 1221 #endif
OLDNEW
« no previous file with comments | « base/file_path.h ('k') | base/file_path_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698