WvStreams
wvregex.cc
1/*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2004 Net Integration Technologies, Inc.
4 *
5 * Implementation of regular expression support though libc
6 */
7#include "wvregex.h"
8
10
11const int WvRegex::default_cflags = WvRegex::EXTENDED;
12const int WvRegex::default_eflags = 0;
13
14void WvRegex::seterr(int errcode)
15{
16 int error_desc_len = ::regerror(errcode, &preg, NULL, 0);
17 if (error_desc_len > 0)
18 {
19 WvString error_desc;
20 error_desc.setsize(error_desc_len);
21 ::regerror(errcode, &preg, error_desc.edit(), error_desc_len);
22 WvErrorBase::seterr_both(errcode, error_desc);
23 }
24 else WvErrorBase::seterr(errcode);
25}
26
27bool WvRegex::set(WvStringParm regex, int cflags)
28{
29 if (have_preg) ::regfree(&preg);
30
31 int errcode = ::regcomp(&preg, regex, cflags);
32 if (errcode)
33 {
34 seterr(errcode);
35 have_preg = false;
36 }
37 else have_preg = true;
38
39 return have_preg;
40}
41
42WvRegex::~WvRegex()
43{
44 if (have_preg) ::regfree(&preg);
45}
46
47bool WvRegex::match(WvStringParm string, int eflags,
48 size_t nmatch, regmatch_t pmatch[]) const
49{
50 if (!have_preg) return false;
51
52 return ::regexec(&preg, string, nmatch, pmatch, eflags) == 0;
53}
virtual void seterr(int _errnum)
Set the errnum variable – we have an error.
Definition wverror.cc:144
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
static WvString __wvre_null_reg
Internal use only.
bool set(WvStringParm regex, int cflags=default_cflags)
Replace the current regex to match with a new one.
Definition wvregex.cc:27
WvString is an implementation of a simple and efficient printable-string class.
char * edit()
make the string editable, and return a non-const (char*)