diff options
author | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-04 01:21:22 +0000 |
---|---|---|
committer | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-04 01:21:22 +0000 |
commit | 6a4c749008dad827b0699e7de9eb458a0ed6d39f (patch) | |
tree | 38165061573b715fe3a737b9720e2be5f5dfbb62 /net/tools/flip_server/url_utilities.h | |
parent | 93ef176c40555a6f3a3895f745a977efe1b5037b (diff) | |
download | chromium_src-6a4c749008dad827b0699e7de9eb458a0ed6d39f.zip chromium_src-6a4c749008dad827b0699e7de9eb458a0ed6d39f.tar.gz chromium_src-6a4c749008dad827b0699e7de9eb458a0ed6d39f.tar.bz2 |
Landing the open source version of the FLIP server.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/463009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33766 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/tools/flip_server/url_utilities.h')
-rw-r--r-- | net/tools/flip_server/url_utilities.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/net/tools/flip_server/url_utilities.h b/net/tools/flip_server/url_utilities.h new file mode 100644 index 0000000..488753c --- /dev/null +++ b/net/tools/flip_server/url_utilities.h @@ -0,0 +1,69 @@ +// Copyright (c) 2009 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. + +#ifndef NET_TOOLS_FLIP_SERVER_URL_UTILITIES_H__ +#define NET_TOOLS_FLIP_SERVER_URL_UTILITIES_H__ + +#include <string> + +namespace net { + +struct UrlUtilities { + // Get the host from an url + static string GetUrlHost(const string& url) { + size_t b = url.find("//"); + if (b == string::npos) + b = 0; + else + b += 2; + size_t next_slash = url.find_first_of('/', b); + size_t next_colon = url.find_first_of(':', b); + if (next_slash != string::npos + && next_colon != string::npos + && next_colon < next_slash) { + return string(url, b, next_colon - b); + } + if (next_slash == string::npos) { + if (next_colon != string::npos) { + return string(url, next_colon - b); + } else { + next_slash = url.size(); + } + } + return string(url, b, next_slash - b); + } + + // Get the host + path portion of an url + // e.g http://www.foo.com/path + // returns www.foo.com/path + static string GetUrlHostPath(const string& url) { + size_t b = url.find("//"); + if (b == string::npos) + b = 0; + else + b += 2; + return string(url, b); + } + + // Get the path portion of an url + // e.g http://www.foo.com/path + // returns /path + static string GetUrlPath(const string& url) { + size_t b = url.find("//"); + if (b == string::npos) + b = 0; + else + b += 2; + b = url.find("/", b+1); + if (b == string::npos) + return "/"; + + return string(url, b); + } +}; + +} // namespace net + +#endif // NET_TOOLS_FLIP_SERVER_URL_UTILITIES_H__ + |