summaryrefslogtreecommitdiff
path: root/src/regmatch.cc
blob: 0942ad97bc6d96bf8d418927ec7b2322dc7fc3ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
 *  @file  regex.cc
 *  @brief Implementation of miscellaneous regexp functions
 *  @author Andreas Aardal Hanssen
 *  @date 2002-2005
 */

#include "regmatch.h"

#include <string>

#include <stdio.h>

#include <regex.h>
#include <sys/types.h>

int Binc::regexMatch(const std::string &data_in, const std::string &p_in)
{
  regex_t r;
  regmatch_t rm[2];

  if (regcomp(&r, p_in.c_str(), REG_EXTENDED | REG_NOSUB) != 0) return 2;

  int n = regexec(&r, data_in.c_str(), data_in.length(), rm, 0);
  regfree(&r);
  if (n == 0)
    return 0;
  else
    return 2;
}