Repo-Init
 
Loading...
Searching...
No Matches
FileHelpers.hpp File Reference
#include <fstream>
#include <regex>
#include <string>
#include <vector>
Include dependency graph for FileHelpers.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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)
 

Function Documentation

◆ 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]filePathPath to the file
[in]patternRegex search pattern
Returns
std::vector<std::string> Matched lines

Definition at line 49 of file FileHelpers.hpp.

50{
51 std::string lastWord;
52 return findFromFile(filePath, pattern, lastWord);
53}
std::vector< std::string > findFromFile(const std::string &filePath, const std::string &pattern, std::string &lastWord)
Here is the call graph for this function:

◆ 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]filePathPath to the file
[in]patternRegex search pattern
[out]lastWordLast 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}
Here is the caller graph for this function: