#include <atomic>
#include <filesystem>
#include <fstream>
#include <regex>
#include <string>
#include <sys/inotify.h>
#include <thread>
#include <vector>
Go to the source code of this file.
|
using | FNotifyCallback = std::function<void(const void *)> |
| Callback function for file notifications.
|
|
|
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) |
|
◆ FNotifyCallback
Callback function for file notifications.
Definition at line 60 of file FileHelpers.hpp.
◆ 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 53 of file FileHelpers.hpp.
54{
55 std::string lastWord;
57}
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 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}