• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 #define LOG_TAG "PrintTools"
18 
19 #include <input/PrintTools.h>
20 #include <sstream>
21 
22 namespace android {
23 
toString(bool value)24 const char* toString(bool value) {
25     return value ? "true" : "false";
26 }
27 
addLinePrefix(std::string str,const std::string & prefix)28 std::string addLinePrefix(std::string str, const std::string& prefix) {
29     std::stringstream ss;
30     bool newLineStarted = true;
31     for (const auto& ch : str) {
32         if (newLineStarted) {
33             ss << prefix;
34             newLineStarted = false;
35         }
36         if (ch == '\n') {
37             newLineStarted = true;
38         }
39         ss << ch;
40     }
41     return ss.str();
42 }
43 
44 } // namespace android
45