• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include "linkerconfig/stringutil.h"
17 
18 #include <set>
19 #include <sstream>
20 #include <vector>
21 
22 #include <android-base/strings.h>
23 
24 namespace android {
25 namespace linkerconfig {
26 namespace modules {
TrimPrefix(const std::string & s,const std::string & prefix)27 std::string TrimPrefix(const std::string& s, const std::string& prefix) {
28   if (android::base::StartsWith(s, prefix)) {
29     return s.substr(prefix.size());
30   }
31   return s;
32 }
33 
34 // merge a list of libs into a single value (concat with ":")
MergeLibs(const std::vector<std::string> & libs)35 std::string MergeLibs(const std::vector<std::string>& libs) {
36   std::set<std::string> seen;
37   std::ostringstream oss;
38   for (const auto& part : libs) {
39     std::istringstream iss(part);
40     std::string lib;
41     while (std::getline(iss, lib, ':')) {
42       if (!lib.empty() && seen.insert(lib).second) {  // for a new lib
43         if (oss.tellp() > 0) {
44           oss << ':';
45         }
46         oss << lib;
47       }
48     }
49   }
50   return oss.str();
51 }
52 }  // namespace modules
53 }  // namespace linkerconfig
54 }  // namespace android