1 /*
2  * Copyright (C) 2017 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 
17 #include "utils.h"
18 
19 namespace android {
20 namespace lshal {
21 
toHexString(uint64_t t)22 std::string toHexString(uint64_t t) {
23     std::ostringstream os;
24     os << std::hex << std::setfill('0') << std::setw(16) << t;
25     return os.str();
26 }
27 
split(const std::string & s,char c)28 std::vector<std::string> split(const std::string &s, char c) {
29     std::vector<std::string> components{};
30     size_t startPos = 0;
31     size_t matchPos;
32     while ((matchPos = s.find(c, startPos)) != std::string::npos) {
33         components.push_back(s.substr(startPos, matchPos - startPos));
34         startPos = matchPos + 1;
35     }
36 
37     if (startPos <= s.length()) {
38         components.push_back(s.substr(startPos));
39     }
40     return components;
41 }
42 
replaceAll(std::string * s,char from,char to)43 void replaceAll(std::string *s, char from, char to) {
44     for (size_t i = 0; i < s->size(); ++i) {
45         if (s->at(i) == from) {
46             s->at(i) = to;
47         }
48     }
49 }
50 
51 }  // namespace lshal
52 }  // namespace android
53 
54