summaryrefslogtreecommitdiff
path: root/src/pg_regex.cpp
blob: 0051beb1bec59d65fcf0b18992fab5858807e4ff (plain)
    1 ////////////////////////////////////////////////////////////////////////
    2 // FILE:        pg_regex.cpp
    3 // AUTHOR:      Johannes Winkelmann, jw@tks6.net
    4 // COPYRIGHT:   (c) 2005 by Johannes Winkelmann
    5 // ---------------------------------------------------------------------
    6 //  This program is free software; you can redistribute it and/or modify  
    7 //  it under the terms of the GNU General Public License as published by  
    8 //  the Free Software Foundation; either version 2 of the License, or     
    9 //  (at your option) any later version.                                   
   10 ////////////////////////////////////////////////////////////////////////
   11 
   12 
   13 #include <string>
   14 using namespace std;
   15 
   16 #include "pg_regex.h"
   17 
   18 
   19 RegEx::RegEx(const string& pattern, bool caseSensitive) 
   20 {
   21     int additionalFlags = 0;
   22     if (!caseSensitive) {
   23         additionalFlags |= REG_ICASE;
   24     }
   25 
   26     m_validPattern = 
   27         regcomp(&m_pattern, 
   28                 pattern.c_str(), 
   29                 REG_EXTENDED|REG_NOSUB|additionalFlags) == 0;
   30 }
   31 
   32 RegEx::~RegEx() 
   33 {
   34     regfree(&m_pattern);
   35 }
   36 
   37 bool RegEx::match(const string& input) 
   38 {
   39     if (!m_validPattern) {
   40         return false;
   41     }
   42     bool success = (regexec(&m_pattern, input.c_str(), 0, 0, 0) == 0);
   43     return success;
   44 }
   45 
   46 bool RegEx::match(const string& pattern,
   47                   const string& input,
   48                   bool caseSensitive) 
   49 {
   50     RegEx re(pattern, caseSensitive);
   51     return re.match(input);
   52 }

Generated by cgit