Repo-Init
 
Loading...
Searching...
No Matches
FileHelpers.hpp File Reference
#include <atomic>
#include <filesystem>
#include <fstream>
#include <regex>
#include <string>
#include <sys/inotify.h>
#include <thread>
#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.

Classes

class  FileMonitor
 

Typedefs

using FNotifyCallback = std::function<void(const void *)>
 Callback function for file notifications.
 

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)
 

Typedef Documentation

◆ FNotifyCallback

using FNotifyCallback = std::function<void(const void *)>

Callback function for file notifications.

Definition at line 60 of file FileHelpers.hpp.

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 53 of file FileHelpers.hpp.

54{
55 std::string lastWord;
56 return findFromFile(filePath, pattern, lastWord);
57}
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 19 of file FileHelpers.hpp.

21{
22 const std::regex regExp(pattern);
23 std::ifstream inFile(filePath);
24 std::vector<std::string> matchedLines;
25
26 std::string readLine;
27 while (getline(inFile, readLine))
28 {
29 if (std::regex_search(readLine, regExp))
30 {
31 matchedLines.push_back(readLine);
32 }
33 }
34
35 if (!matchedLines.empty())
36 {
37 auto pos = matchedLines.front().find_last_of(' ');
38 if (pos != std::string::npos && pos != matchedLines.front().size())
39 {
40 lastWord = matchedLines.front().substr(pos + 1);
41 }
42 }
43
44 return matchedLines;
45}
Here is the caller graph for this function: