summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-25 22:04:37 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-25 22:04:37 +0000
commit7e2639413fc87b91d1327a57303493d84823f070 (patch)
tree2c8f494e45fbd787ca2c1efbbbbee72826afd045 /base
parent7fe2c0b8630fabd9919dc61757392ea2aac9d72b (diff)
downloadchromium_src-7e2639413fc87b91d1327a57303493d84823f070.zip
chromium_src-7e2639413fc87b91d1327a57303493d84823f070.tar.gz
chromium_src-7e2639413fc87b91d1327a57303493d84823f070.tar.bz2
Append a trailing slash on file directory URLs. Thus a link to /directory will work just as well as a link to /directory/
Review URL: http://codereview.chromium.org/12620 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5999 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/file_util.cc35
-rw-r--r--base/file_util.h11
2 files changed, 34 insertions, 12 deletions
diff --git a/base/file_util.cc b/base/file_util.cc
index 0f7b683..10ab164 100644
--- a/base/file_util.cc
+++ b/base/file_util.cc
@@ -26,7 +26,7 @@ void PathComponents(const std::wstring& path,
std::wstring::size_type end = path.find(kPathSeparator, start);
// Special case the "/" or "\" directory. On Windows with a drive letter,
- // this code path won't hit, but the right thing should still happen.
+ // this code path won't hit, but the right thing should still happen.
// "E:\foo" will turn into "E:","foo".
if (end == start) {
components->push_back(std::wstring(path, 0, 1));
@@ -42,17 +42,28 @@ void PathComponents(const std::wstring& path,
std::wstring component = std::wstring(path, start);
components->push_back(component);
}
-
-bool EndsWithSeparator(std::wstring* path) {
- return EndsWithSeparator(*path);
-}
-
-bool EndsWithSeparator(const std::wstring& path) {
- bool is_sep = (path.length() > 0 &&
- (path)[path.length() - 1] == kPathSeparator);
+
+bool EndsWithSeparator(const FilePath& file_path) {
+ std::wstring path = file_path.ToWStringHack();
+ bool is_sep = (path.length() > 0 &&
+ path[path.length() - 1] == kPathSeparator);
return is_sep;
}
+bool EnsureEndsWithSeparator(FilePath* path) {
+ if (!DirectoryExists(*path))
+ return false;
+
+ if (EndsWithSeparator(*path))
+ return true;
+
+ FilePath::StringType& path_str =
+ const_cast<FilePath::StringType&>(path->value());
+ path_str.append(&FilePath::kSeparators[0], 1);
+
+ return true;
+}
+
void TrimTrailingSeparator(std::wstring* dir) {
while (dir->length() > 1 && EndsWithSeparator(dir))
dir->resize(dir->length() - 1);
@@ -315,6 +326,12 @@ bool AbsolutePath(std::wstring* path_str) {
bool Delete(const std::wstring& path, bool recursive) {
return Delete(FilePath::FromWStringHack(path), recursive);
}
+bool EndsWithSeparator(std::wstring* path) {
+ return EndsWithSeparator(FilePath::FromWStringHack(*path));
+}
+bool EndsWithSeparator(const std::wstring& path) {
+ return EndsWithSeparator(FilePath::FromWStringHack(path));
+}
bool Move(const std::wstring& from_path, const std::wstring& to_path) {
return Move(FilePath::FromWStringHack(from_path),
FilePath::FromWStringHack(to_path));
diff --git a/base/file_util.h b/base/file_util.h
index 0103003..3fa6773 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -41,12 +41,17 @@ extern const wchar_t kPathSeparator;
// Returns a vector of all of the components of the provided path.
void PathComponents(const std::wstring& path,
std::vector<std::wstring>* components);
-
+
// Returns true if the given path ends with a path separator character.
-// TODO(erikkay): remove this pointer version
+bool EndsWithSeparator(const FilePath& path);
+// These two versions are both deprecated. TODO(estade): remove them.
bool EndsWithSeparator(std::wstring* path);
bool EndsWithSeparator(const std::wstring& path);
-
+
+// Makes sure that |path| ends with a separator IFF path is a directory that
+// exists. Returns true if |path| is an existing directory, false otherwise.
+bool EnsureEndsWithSeparator(FilePath* path);
+
// Modifies a string by trimming all trailing separators from the end.
void TrimTrailingSeparator(std::wstring* dir);