The following links I have used to helped get closer to a solution, however I am still experiencing read, memory, or looping errors. I am looping through a logfile and extracting the json. Before the start of the json objects there is a date and time along with message and object ID - Which corresponds to the json. So both are needed. Time is also a factor as the log file grows. I need help figuring out where I am going so wrong.
https://riptutorial.com/cplusplus/example/19029/string-streams
https://www.codeproject.com/Questions/1221494/Simple-multiline-regex-in-Cplusplus
http://www.cplusplus.com/reference/iterator/next/
I can use regex on a string no problem, and as a multiline. Reading from a file using stringstream I have while(input >> sstr.rdbuf());
where my stream is now buffered to my understanding.
when I cout << sstr.str()
it is only read 1 time
std::ifstream input("log.txt");
std::stringstream sstr;
std::smatch m;
std::regex reg("(\\{|\\[)(\\n\\s+.*)+\\n*(\\}||\\])");
while (input >> sstr.rdbuf());
std::string strang = sstr.str();
while (std::regex_search(strang, m, reg)) {
std::cout << "Results : \n" << m.str() << '\n';
for (i = 0; i < strang.length(); i++) {
std::cout << m.str(i);
i++;
}
}
This seems to loop the file forever if the file is small. For larger files 30MB+ there is no output.
I am looking at vectors and hashmaps, but I am not certain how to apply regex to hashmap- seems odd. Ontop of that I have learned that vectors only store upto about 30 variables anyway, so this type of workload is too much.
Thanks!
Another Variation
void PrintMatches(std::string str, std::regex reg) {
std::smatch matches;
std::cout << matches.size() << std::endl;
}
int main() {
std::ifstream input("log.txt");
std::stringstream sstr;
std::smatch m;
std::regex reg("(\\{|\\[)(\\n\\s+.*)+\\n*(\\}||\\])");
while (input >> sstr.rdbuf());
std::string str = sstr.str();
std::cout << str;
//PrintMatches(str, reg);
return 0;
}