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

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: 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
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::AsUTF8() const {
531 return WideToUTF8(base::SysNativeMBToWide(value()));
532 }
533
530 // The *Hack functions are temporary while we fix the remainder of the code. 534 // 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. 535 // Remember to remove the #includes at the top when you remove these.
532 536
533 // static 537 // static
534 FilePath FilePath::FromWStringHack(const std::wstring& wstring) { 538 FilePath FilePath::FromWStringHack(const std::wstring& wstring) {
535 return FilePath(base::SysWideToNativeMB(wstring)); 539 return FilePath(base::SysWideToNativeMB(wstring));
536 } 540 }
541
542 // static
543 FilePath FilePath::FromUTF8(const std::string& utf8) {
544 return FilePath(base::SysWideToNativeMB(UTF8ToWide(utf8)));
545 }
546
537 #elif defined(OS_WIN) 547 #elif defined(OS_WIN)
538 string16 FilePath::LossyDisplayName() const { 548 string16 FilePath::LossyDisplayName() const {
539 return path_; 549 return path_;
540 } 550 }
541 551
542 std::string FilePath::MaybeAsASCII() const { 552 std::string FilePath::MaybeAsASCII() const {
543 if (IsStringASCII(path_)) 553 if (IsStringASCII(path_))
544 return WideToASCII(path_); 554 return WideToASCII(path_);
545 return ""; 555 return "";
546 } 556 }
547 557
558 std::string FilePath::AsUTF8() const {
559 return WideToUTF8(value());
560 }
561
548 // static 562 // static
549 FilePath FilePath::FromWStringHack(const std::wstring& wstring) { 563 FilePath FilePath::FromWStringHack(const std::wstring& wstring) {
550 return FilePath(wstring); 564 return FilePath(wstring);
551 } 565 }
566
567 // static
568 FilePath FilePath::FromUTF8(const std::string& utf8) {
569 return FilePath(UTF8ToWide(utf8));
570 }
552 #endif 571 #endif
553 572
554 void FilePath::WriteToPickle(Pickle* pickle) { 573 void FilePath::WriteToPickle(Pickle* pickle) {
555 #if defined(OS_WIN) 574 #if defined(OS_WIN)
556 pickle->WriteString16(path_); 575 pickle->WriteString16(path_);
557 #else 576 #else
558 pickle->WriteString(path_); 577 pickle->WriteString(path_);
559 #endif 578 #endif
560 } 579 }
561 580
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 1204
1186 #if defined(FILE_PATH_USES_WIN_SEPARATORS) 1205 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
1187 FilePath FilePath::NormalizeWindowsPathSeparators() const { 1206 FilePath FilePath::NormalizeWindowsPathSeparators() const {
1188 StringType copy = path_; 1207 StringType copy = path_;
1189 for (size_t i = 1; i < arraysize(kSeparators); ++i) { 1208 for (size_t i = 1; i < arraysize(kSeparators); ++i) {
1190 std::replace(copy.begin(), copy.end(), kSeparators[i], kSeparators[0]); 1209 std::replace(copy.begin(), copy.end(), kSeparators[i], kSeparators[0]);
1191 } 1210 }
1192 return FilePath(copy); 1211 return FilePath(copy);
1193 } 1212 }
1194 #endif 1213 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698