Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / remoting / base / capabilities.cc
blob4903aedfe5fab84b1cb3086500d6bf2dc67f738e
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "remoting/base/capabilities.h"
7 #include <algorithm>
8 #include <vector>
10 #include "base/stl_util.h"
11 #include "base/strings/string_split.h"
12 #include "base/strings/string_util.h"
14 namespace remoting {
16 bool HasCapability(const std::string& capabilities, const std::string& key) {
17 std::vector<base::StringPiece> caps = base::SplitStringPiece(
18 capabilities, " ", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
19 return std::find(caps.begin(), caps.end(), base::StringPiece(key)) !=
20 caps.end();
23 std::string IntersectCapabilities(const std::string& client_capabilities,
24 const std::string& host_capabilities) {
25 std::vector<std::string> client_caps = base::SplitString(
26 client_capabilities, " ", base::KEEP_WHITESPACE,
27 base::SPLIT_WANT_NONEMPTY);
28 std::sort(client_caps.begin(), client_caps.end());
30 std::vector<std::string> host_caps = base::SplitString(
31 host_capabilities, " ", base::KEEP_WHITESPACE,
32 base::SPLIT_WANT_NONEMPTY);
33 std::sort(host_caps.begin(), host_caps.end());
35 std::vector<std::string> result =
36 base::STLSetIntersection<std::vector<std::string> >(
37 client_caps, host_caps);
39 return base::JoinString(result, " ");
42 } // namespace remoting