Home | History | Annotate | Download | only in base
      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.
      4 
      5 #include "remoting/base/capabilities.h"
      6 
      7 #include <algorithm>
      8 #include <vector>
      9 
     10 #include "base/stl_util.h"
     11 #include "base/strings/string_util.h"
     12 
     13 namespace remoting {
     14 
     15 bool HasCapability(const std::string& capabilities, const std::string& key) {
     16   std::vector<std::string> caps;
     17   Tokenize(capabilities, " ", &caps);
     18   return std::find(caps.begin(), caps.end(), key) != caps.end();
     19 }
     20 
     21 std::string IntersectCapabilities(const std::string& client_capabilities,
     22                                   const std::string& host_capabilities) {
     23   std::vector<std::string> client_caps;
     24   Tokenize(client_capabilities, " ", &client_caps);
     25   std::sort(client_caps.begin(), client_caps.end());
     26 
     27   std::vector<std::string> host_caps;
     28   Tokenize(host_capabilities, " ", &host_caps);
     29   std::sort(host_caps.begin(), host_caps.end());
     30 
     31   std::vector<std::string> result =
     32       base::STLSetIntersection<std::vector<std::string> >(
     33           client_caps, host_caps);
     34 
     35   return JoinString(result, " ");
     36 }
     37 
     38 }  // namespace remoting
     39