diff options
author | license.bot <license.bot@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-24 00:55:55 +0000 |
---|---|---|
committer | license.bot <license.bot@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-24 00:55:55 +0000 |
commit | bf09a5036ccfb77d2277247c66dc55daf41df3fe (patch) | |
tree | 51d33e5972fe4bab331c399b33cf280554f5cbb9 /net/base/net_util_win.cc | |
parent | a6c9da873154602e26bd69a55bb09fdff9fbbbc8 (diff) | |
download | chromium_src-bf09a5036ccfb77d2277247c66dc55daf41df3fe.zip chromium_src-bf09a5036ccfb77d2277247c66dc55daf41df3fe.tar.gz chromium_src-bf09a5036ccfb77d2277247c66dc55daf41df3fe.tar.bz2 |
Use a more compact license header in source files.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1287 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_util_win.cc')
-rw-r--r-- | net/base/net_util_win.cc | 198 |
1 files changed, 87 insertions, 111 deletions
diff --git a/net/base/net_util_win.cc b/net/base/net_util_win.cc index 9295b7e..afc0f91 100644 --- a/net/base/net_util_win.cc +++ b/net/base/net_util_win.cc @@ -1,111 +1,87 @@ -// Copyright 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include "net/base/net_util.h" - -#include "base/string_piece.h" -#include "base/string_util.h" -#include "base/sys_string_conversions.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(); - - if (!url.is_valid()) - return false; - - std::string path; - std::string host = url.host(); - if (host.empty()) { - // URL contains no host, the path is the filename. In this case, the path - // will probably be preceeded with a slash, as in "/C:/foo.txt", so we - // trim out that here. - path = url.path(); - size_t first_non_slash = path.find_first_not_of("/\\"); - if (first_non_slash != std::string::npos && first_non_slash > 0) - path.erase(0, first_non_slash); - } else { - // URL contains a host: this means it's UNC. We keep the preceeding slash - // on the path. - path = "\\\\"; - path.append(host); - path.append(url.path()); - } - - if (path.empty()) - return false; - std::replace(path.begin(), path.end(), '/', '\\'); - - // GURL stores strings as percent-encoded UTF-8, this will undo if possible. - path = UnescapeURLComponent(path, - UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); - - if (!IsStringUTF8(path.c_str())) { - // Not UTF-8, assume encoding is native codepage and we're done. We know we - // are giving the conversion function a nonempty string, and it may fail if - // the given string is not in the current encoding and give us an empty - // string back. We detect this and report failure. - *file_path = base::SysNativeMBToWide(path); - return !file_path->empty(); - } - file_path->assign(UTF8ToWide(path)); - - // Now we have an unescaped filename, but are still not sure about its - // encoding. For example, each character could be part of a UTF-8 string. - if (file_path->empty() || !IsString8Bit(*file_path)) { - // assume our 16-bit encoding is correct if it won't fit into an 8-bit - // string - return true; - } - - // Convert our narrow string into the native wide path. - std::string narrow; - if (!WideToLatin1(*file_path, &narrow)) { - NOTREACHED() << "Should have filtered out non-8-bit strings above."; - return false; - } - if (IsStringUTF8(narrow.c_str())) { - // Our string actually looks like it could be UTF-8, convert to 8-bit - // UTF-8 and then to the corresponding wide string. - *file_path = UTF8ToWide(narrow); - } else { - // Our wide string contains only 8-bit characters and it's not UTF-8, so - // we assume it's in the native codepage. - *file_path = base::SysNativeMBToWide(narrow); - } - - // Fail if 8-bit -> wide conversion failed and gave us an empty string back - // (we already filtered out empty strings above). - return !file_path->empty(); -} - -} // namespace net +// Copyright (c) 2006-2008 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.
+
+#include "net/base/net_util.h"
+
+#include "base/string_piece.h"
+#include "base/string_util.h"
+#include "base/sys_string_conversions.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();
+
+ if (!url.is_valid())
+ return false;
+
+ std::string path;
+ std::string host = url.host();
+ if (host.empty()) {
+ // URL contains no host, the path is the filename. In this case, the path
+ // will probably be preceeded with a slash, as in "/C:/foo.txt", so we
+ // trim out that here.
+ path = url.path();
+ size_t first_non_slash = path.find_first_not_of("/\\");
+ if (first_non_slash != std::string::npos && first_non_slash > 0)
+ path.erase(0, first_non_slash);
+ } else {
+ // URL contains a host: this means it's UNC. We keep the preceeding slash
+ // on the path.
+ path = "\\\\";
+ path.append(host);
+ path.append(url.path());
+ }
+
+ if (path.empty())
+ return false;
+ std::replace(path.begin(), path.end(), '/', '\\');
+
+ // GURL stores strings as percent-encoded UTF-8, this will undo if possible.
+ path = UnescapeURLComponent(path,
+ UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS);
+
+ if (!IsStringUTF8(path.c_str())) {
+ // Not UTF-8, assume encoding is native codepage and we're done. We know we
+ // are giving the conversion function a nonempty string, and it may fail if
+ // the given string is not in the current encoding and give us an empty
+ // string back. We detect this and report failure.
+ *file_path = base::SysNativeMBToWide(path);
+ return !file_path->empty();
+ }
+ file_path->assign(UTF8ToWide(path));
+
+ // Now we have an unescaped filename, but are still not sure about its
+ // encoding. For example, each character could be part of a UTF-8 string.
+ if (file_path->empty() || !IsString8Bit(*file_path)) {
+ // assume our 16-bit encoding is correct if it won't fit into an 8-bit
+ // string
+ return true;
+ }
+
+ // Convert our narrow string into the native wide path.
+ std::string narrow;
+ if (!WideToLatin1(*file_path, &narrow)) {
+ NOTREACHED() << "Should have filtered out non-8-bit strings above.";
+ return false;
+ }
+ if (IsStringUTF8(narrow.c_str())) {
+ // Our string actually looks like it could be UTF-8, convert to 8-bit
+ // UTF-8 and then to the corresponding wide string.
+ *file_path = UTF8ToWide(narrow);
+ } else {
+ // Our wide string contains only 8-bit characters and it's not UTF-8, so
+ // we assume it's in the native codepage.
+ *file_path = base::SysNativeMBToWide(narrow);
+ }
+
+ // Fail if 8-bit -> wide conversion failed and gave us an empty string back
+ // (we already filtered out empty strings above).
+ return !file_path->empty();
+}
+
+} // namespace net
+
|