#include "common.h" #include "ZRegexScanner.h" ZRegexScanner::ZRegexScanner() : iLastError(0), nMatched(0) { memset(®ex,0,sizeof(regex)); } ZRegexScanner::~ZRegexScanner() { regfree(®ex); } void ZRegexScanner::saveLastError(int v) { iLastError = v; int n = regerror(v,®ex,0,0); regerror(v,®ex,sLastError.getBuffer(n),n); } bool ZRegexScanner::setPattern(const char* s) { int v = regcomp(®ex,s,REG_EXTENDED); if (0 == v) { return true; } saveLastError(v); return false; } void ZRegexScanner::onLine(const char* s) { ++nLines; cbFile += strlen(s); int v = regexec(®ex,s,N_MATCH,match,0); if (REG_NOMATCH == v) { return; } if (0 == v) { ++nMatched; ZString sMatch; int i1 = match[1].rm_so; int i2 = match[1].rm_eo; sMatch.strcpy(s + i1,i2 - i1); //printf("MATCH '%s'\n",sMatch.getBuffer()); return; } saveLastError(v); }