Chromium Code Reviews| Index: remoting/base/capabilities.cc | 
| diff --git a/remoting/base/capabilities.cc b/remoting/base/capabilities.cc | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..1984815ecce36042297ad6effac66cf6ac8ab712 | 
| --- /dev/null | 
| +++ b/remoting/base/capabilities.cc | 
| @@ -0,0 +1,44 @@ | 
| +// Copyright 2013 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 "remoting/base/capabilities.h" | 
| + | 
| +#include <algorithm> | 
| +#include <vector> | 
| + | 
| +#include "base/string_util.h" | 
| + | 
| +namespace remoting { | 
| + | 
| +bool HasCapability(const std::string& capabilities, const std::string& key) { | 
| + std::vector<std::string> caps; | 
| + Tokenize(capabilities, " ", &caps); | 
| + return std::find(caps.begin(), caps.end(), key) != caps.end(); | 
| +} | 
| + | 
| +std::string IntersectCapabilities(const std::string& client_capabilities, | 
| + const std::string& host_capabilities) { | 
| + std::vector<std::string> client_caps; | 
| + Tokenize(client_capabilities, " ", &client_caps); | 
| + std::sort(client_caps.begin(), client_caps.end()); | 
| + | 
| + std::vector<std::string> host_caps; | 
| + Tokenize(host_capabilities, " ", &host_caps); | 
| + std::sort(host_caps.begin(), host_caps.end()); | 
| + | 
| + std::vector<std::string> result(std::min(client_caps.size(), | 
| + host_caps.size())); | 
| + std::vector<std::string>::iterator end = | 
| + std::set_intersection(client_caps.begin(), | 
| + client_caps.end(), | 
| + host_caps.begin(), | 
| + host_caps.end(), | 
| + result.begin()); | 
| + if (end != result.end()) | 
| + result.erase(end); | 
| 
 
Sergey Ulanov
2013/04/18 00:34:53
shouldn't this be result.erase(end, result.end)?
e
 
alexeypa (please no reviews)
2013/04/18 18:56:36
Yes, it should.
 
 | 
| + | 
| + return JoinString(result, " "); | 
| +} | 
| + | 
| +} // namespace remoting |