Example on how to use the PosixRegex class.
#include "config.h"
#include <iostream>
#include <fstream>
int main(int argc, char *argv[])
{
int retValue(0);
if (argc != 3)
{
std::cerr << "Simple grep-like test program: compares line per line, prints matching lines." << std::endl;
std::cerr << "Usage0: " << argv[0] << " <regex> <file>" << std::endl;
std::cerr << "Usage1: " << argv[0] << " RANDOM <max>" << std::endl;
exit(1);
}
try
{
std::string regex((std::string) argv[1]);
if (regex == "RANDOM")
{
long count(0);
long matches(0);
std::cout << "Regex: " << regex << std::endl;
while (count < max)
{
{
std::cout << text << std::endl;
++matches;
}
++count;
}
std::cout << matches << " matches in " << count << " random comparisons." << std::endl;
}
else
{
std::string fileName((std::string) argv[2]);
std::ifstream f(fileName.c_str(), std::ios::in);
char line[160];
while (!f.eof())
{
f.getline(line, 160);
std::cout << line << std::endl;
}
}
}
{
std::cerr << "Posix Err Code: " << e.getCode() << "." << std::endl;
std::cerr << "Posix Err Text: " << e.what() << "." << std::endl;
}
catch (...)
{
std::cerr << "Unknown exception" << std::endl;
}
return(retValue);
}
Posixregex, descriptors and sockets.
Text, descriptors and sockets.
Mutex Lock class; an object of this class will guard a scope.
Definition Misc.hpp:182
Wrapper class for POSIX.2 regex functions.
Definition PosixRegex.hpp:33
std::string genAlphaNumericKey(int len)
For compatibility only.
Definition Text.cpp:108