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

Side by Side Diff: base/files/file_path.cc

Issue 13196006: Move path functions from file_util to FilePath object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move AsAbsolute back out of FilePath Created 7 years, 8 months 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) 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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/pickle.h" 12 #include "base/pickle.h"
13 13
14 // These includes are just for the *Hack functions, and should be removed 14 // These includes are just for the *Hack functions, and should be removed
15 // when those functions are removed. 15 // when those functions are removed.
16 #include "base/string_piece.h" 16 #include "base/string_piece.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 #include "base/strings/sys_string_conversions.h" 18 #include "base/strings/sys_string_conversions.h"
19 #include "base/threading/thread_restrictions.h"
rvargas (doing something else) 2013/04/02 01:39:56 remove this.
19 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
20 21
21 #if defined(OS_MACOSX) 22 #if defined(OS_MACOSX)
22 #include "base/mac/scoped_cftyperef.h" 23 #include "base/mac/scoped_cftyperef.h"
23 #include "base/third_party/icu/icu_utf.h" 24 #include "base/third_party/icu/icu_utf.h"
24 #endif 25 #endif
25 26
26 #if defined(OS_WIN) 27 #if defined(OS_WIN)
27 #include <windows.h> 28 #include <windows.h>
28 #elif defined(OS_MACOSX) 29 #elif defined(OS_MACOSX)
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 return Append(ASCIIToUTF16(component.as_string())); 515 return Append(ASCIIToUTF16(component.as_string()));
515 #elif defined(OS_POSIX) 516 #elif defined(OS_POSIX)
516 return Append(component.as_string()); 517 return Append(component.as_string());
517 #endif 518 #endif
518 } 519 }
519 520
520 bool FilePath::IsAbsolute() const { 521 bool FilePath::IsAbsolute() const {
521 return IsPathAbsolute(path_); 522 return IsPathAbsolute(path_);
522 } 523 }
523 524
525 bool FilePath::EndsWithSeparator() const {
526 if (empty())
527 return false;
528 return IsSeparator(path_[path_.size() - 1]);
529 }
530
531 FilePath FilePath::AsEndingWithSeparator() const {
532 if (EndsWithSeparator())
533 return *this;
534
535 StringType path_str;
536 path_str.reserve(path_.length() + 1); // Only allocate string once.
537
538 path_str = path_;
539 path_str.append(&kSeparators[0], 1);
540 return FilePath(path_str);
541 }
542
524 FilePath FilePath::StripTrailingSeparators() const { 543 FilePath FilePath::StripTrailingSeparators() const {
525 FilePath new_path(path_); 544 FilePath new_path(path_);
526 new_path.StripTrailingSeparatorsInternal(); 545 new_path.StripTrailingSeparatorsInternal();
527 546
528 return new_path; 547 return new_path;
529 } 548 }
530 549
531 bool FilePath::ReferencesParent() const { 550 bool FilePath::ReferencesParent() const {
532 std::vector<StringType> components; 551 std::vector<StringType> components;
533 GetComponents(&components); 552 GetComponents(&components);
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 #else 1270 #else
1252 return *this; 1271 return *this;
1253 #endif 1272 #endif
1254 } 1273 }
1255 1274
1256 } // namespace base 1275 } // namespace base
1257 1276
1258 void PrintTo(const base::FilePath& path, std::ostream* out) { 1277 void PrintTo(const base::FilePath& path, std::ostream* out) {
1259 *out << path.value(); 1278 *out << path.value();
1260 } 1279 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698