diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-10 02:04:40 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-10 02:04:40 +0000 |
commit | d9034ed2e96d3910c1f4d4d0f9ad3c7ce048679a (patch) | |
tree | cb4454406c639bc0aa5c5a520e5967619ac50109 /base | |
parent | 554efaa8b3220e675ad3743eca7f699ad52e2c82 (diff) | |
download | chromium_src-d9034ed2e96d3910c1f4d4d0f9ad3c7ce048679a.zip chromium_src-d9034ed2e96d3910c1f4d4d0f9ad3c7ce048679a.tar.gz chromium_src-d9034ed2e96d3910c1f4d4d0f9ad3c7ce048679a.tar.bz2 |
Define FilePath::NormalizePathSeparators on all platforms
I assume the method FilePath::NormalizeWindowsPathSeparators() is intentionally defined only on Windows, but recently I found myself trying to add a static method (named NormalizePathSeparators()) which calls NormalizeWindowsPathSeparators() or does nothing with platform ifdefs, and then found that there's another place defining the same static method.
Maybe we could just add the common method in FilePath then? It'd at least make the code cleaner at several callsites. I don't think this has visible negative performance impact with optimization build.
BUG=none
TEST=FilePathTest.NormalizePathSeparators and all other existing tests
Review URL: https://chromiumcodereview.appspot.com/9320059
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121380 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/file_path.cc | 8 | ||||
-rw-r--r-- | base/file_path.h | 9 | ||||
-rw-r--r-- | base/file_path_unittest.cc | 6 |
3 files changed, 12 insertions, 11 deletions
diff --git a/base/file_path.cc b/base/file_path.cc index 3666ff2..c4f1c54 100644 --- a/base/file_path.cc +++ b/base/file_path.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -1210,12 +1210,14 @@ void FilePath::StripTrailingSeparatorsInternal() { } } +FilePath FilePath::NormalizePathSeparators() const { #if defined(FILE_PATH_USES_WIN_SEPARATORS) -FilePath FilePath::NormalizeWindowsPathSeparators() const { StringType copy = path_; for (size_t i = 1; i < arraysize(kSeparators); ++i) { std::replace(copy.begin(), copy.end(), kSeparators[i], kSeparators[0]); } return FilePath(copy); -} +#else + return *this; #endif +} diff --git a/base/file_path.h b/base/file_path.h index 8342c30..bde3cec 100644 --- a/base/file_path.h +++ b/base/file_path.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -341,10 +341,9 @@ class BASE_EXPORT FilePath { void WriteToPickle(Pickle* pickle); bool ReadFromPickle(Pickle* pickle, void** iter); -#if defined(FILE_PATH_USES_WIN_SEPARATORS) - // Normalize all path separators to backslash. - FilePath NormalizeWindowsPathSeparators() const; -#endif + // Normalize all path separators to backslash on Windows + // (if FILE_PATH_USES_WIN_SEPARATORS is true), or do nothing on POSIX systems. + FilePath NormalizePathSeparators() const; // Compare two strings in the same way the file system does. // Note that these always ignore case, even on file systems that are case- diff --git a/base/file_path_unittest.cc b/base/file_path_unittest.cc index 9890e80..49fd1e0 100644 --- a/base/file_path_unittest.cc +++ b/base/file_path_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -1074,7 +1074,7 @@ TEST_F(FilePathTest, FromUTF8Unsafe_And_AsUTF8Unsafe) { } #if defined(FILE_PATH_USES_WIN_SEPARATORS) -TEST_F(FilePathTest, NormalizeWindowsPathSeparators) { +TEST_F(FilePathTest, NormalizePathSeparators) { const struct UnaryTestData cases[] = { { FPL("foo/bar"), FPL("foo\\bar") }, { FPL("foo/bar\\betz"), FPL("foo\\bar\\betz") }, @@ -1110,7 +1110,7 @@ TEST_F(FilePathTest, NormalizeWindowsPathSeparators) { }; for (size_t i = 0; i < arraysize(cases); ++i) { FilePath input(cases[i].input); - FilePath observed = input.NormalizeWindowsPathSeparators(); + FilePath observed = input.NormalizePathSeparators(); EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) << "i: " << i << ", input: " << input.value(); } |