• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 #ifndef OTAPREOPT_FILE_PARSING_H_
18 #define OTAPREOPT_FILE_PARSING_H_
19 
20 #include <fstream>
21 #include <functional>
22 #include <string>
23 
24 namespace android {
25 namespace installd {
26 
ParseFile(const std::string & strFile,std::function<bool (const std::string &)> parse)27 bool ParseFile(const std::string& strFile, std::function<bool (const std::string&)> parse) {
28     std::ifstream input_stream(strFile);
29 
30     if (!input_stream.is_open()) {
31         return false;
32     }
33 
34     while (!input_stream.eof()) {
35         // Read the next line.
36         std::string line;
37         getline(input_stream, line);
38 
39         // Is the line empty? Simplifies the next check.
40         if (line.empty()) {
41             continue;
42         }
43 
44         // Is this a comment (starts with pound)?
45         if (line[0] == '#') {
46             continue;
47         }
48 
49         if (!parse(line)) {
50             return false;
51         }
52     }
53 
54     return true;
55 }
56 
57 }  // namespace installd
58 }  // namespace android
59 
60 #endif  // OTAPREOPT_FILE_PARSING_H_
61