#include <fstream>
#include <regex>
#include <string>
#include <vector>
Go to the source code of this file.
|
std::vector< std::string > | findFromFile (const std::string &filePath, const std::string &pattern, std::string &lastWord) |
|
std::vector< std::string > | findFromFile (const std::string &filePath, const std::string &pattern) |
|
◆ findFromFile() [1/2]
std::vector< std::string > findFromFile |
( |
const std::string & | filePath, |
|
|
const std::string & | pattern ) |
|
inline |
Searches line patterns from a file
- Parameters
-
[in] | filePath | Path to the file |
[in] | pattern | Regex search pattern |
- Returns
- std::vector<std::string> Matched lines
Definition at line 49 of file FileHelpers.hpp.
50{
51 std::string lastWord;
53}
std::vector< std::string > findFromFile(const std::string &filePath, const std::string &pattern, std::string &lastWord)
◆ findFromFile() [2/2]
std::vector< std::string > findFromFile |
( |
const std::string & | filePath, |
|
|
const std::string & | pattern, |
|
|
std::string & | lastWord ) |
|
inline |
Searches line patterns from a file
- Parameters
-
[in] | filePath | Path to the file |
[in] | pattern | Regex search pattern |
[out] | lastWord | Last word (space delimiter) of the first found line |
- Returns
- std::vector<std::string> Matched lines
Definition at line 15 of file FileHelpers.hpp.
17{
18 const std::regex regExp(pattern);
19 std::ifstream inFile(filePath);
20 std::vector<std::string> matchedLines;
21
22 std::string readLine;
23 while (getline(inFile, readLine))
24 {
25 if (std::regex_search(readLine, regExp))
26 {
27 matchedLines.push_back(readLine);
28 }
29 }
30
31 if (!matchedLines.empty())
32 {
33 auto pos = matchedLines.front().find_last_of(' ');
34 if (pos != std::string::npos && pos != matchedLines.front().size())
35 {
36 lastWord = matchedLines.front().substr(pos + 1);
37 }
38 }
39
40 return matchedLines;
41}