diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-24 23:37:04 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-24 23:37:04 +0000 |
commit | 498c1a6b2dc98869e0703127565247830227d075 (patch) | |
tree | 24de83f7cde502e02b2a0f331154c28aee2ee6ac /net/base/net_util_posix.cc | |
parent | 0f3cb003bed09985526391ff19f22ef9e0958401 (diff) | |
download | chromium_src-498c1a6b2dc98869e0703127565247830227d075.zip chromium_src-498c1a6b2dc98869e0703127565247830227d075.tar.gz chromium_src-498c1a6b2dc98869e0703127565247830227d075.tar.bz2 |
Clean up some net/ code. Change a number of wstrings to FilePaths.
Review URL: http://codereview.chromium.org/12409
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5944 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_util_posix.cc')
-rw-r--r-- | net/base/net_util_posix.cc | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/net/base/net_util_posix.cc b/net/base/net_util_posix.cc index 2554e4b..4bfa1fd 100644 --- a/net/base/net_util_posix.cc +++ b/net/base/net_util_posix.cc @@ -4,42 +4,43 @@ #include "net/base/net_util.h" +#include "base/file_path.h" #include "base/string_util.h" #include "googleurl/src/gurl.h" #include "net/base/escape.h" namespace net { -bool FileURLToFilePath(const GURL& url, std::wstring* file_path) { - file_path->clear(); +bool FileURLToFilePath(const GURL& url, FilePath* path) { + *path = FilePath(); + std::string& file_path_str = const_cast<std::string&>(path->value()); + file_path_str.clear(); if (!url.is_valid()) return false; // Firefox seems to ignore the "host" of a file url if there is one. That is, // file://foo/bar.txt maps to /bar.txt. - std::string path = url.path(); + std::string old_path = url.path(); - if (path.empty()) + if (old_path.empty()) return false; // GURL stores strings as percent-encoded 8-bit, this will undo if possible. - path = UnescapeURLComponent(path, + old_path = UnescapeURLComponent(old_path, UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); // Collapse multiple path slashes into a single path slash. std::string new_path; do { - new_path = path; + new_path = old_path; ReplaceSubstringsAfterOffset(&new_path, 0, "//", "/"); - path.swap(new_path); - } while (new_path != path); + old_path.swap(new_path); + } while (new_path != old_path); - // TODO(tc): This should actually be 8-bit to wide. We may lose data if the - // string isn't UTF-8. - file_path->assign(UTF8ToWide(path)); + file_path_str.assign(old_path); - return !file_path->empty(); + return !file_path_str.empty(); } } // namespace net |