2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2004 Net Integration Technologies, Inc.
5 * Implementation of regular expression support though libc
9 WvString
WvRegex::__wvre_null_reg
;
11 const int WvRegex::default_cflags
= WvRegex::EXTENDED
;
12 const int WvRegex::default_eflags
= 0;
14 void WvRegex::seterr(int errcode
)
16 int error_desc_len
= ::regerror(errcode
, &preg
, NULL
, 0);
17 if (error_desc_len
> 0)
20 error_desc
.setsize(error_desc_len
);
21 ::regerror(errcode
, &preg
, error_desc
.edit(), error_desc_len
);
22 WvErrorBase::seterr_both(errcode
, error_desc
);
24 else WvErrorBase::seterr(errcode
);
27 bool WvRegex::set(WvStringParm regex
, int cflags
)
29 if (have_preg
) ::regfree(&preg
);
31 int errcode
= ::regcomp(&preg
, regex
, cflags
);
37 else have_preg
= true;
44 if (have_preg
) ::regfree(&preg
);
47 bool WvRegex::match(WvStringParm string
, int eflags
,
48 size_t nmatch
, regmatch_t pmatch
[]) const
50 if (!have_preg
) return false;
52 return ::regexec(&preg
, string
, nmatch
, pmatch
, eflags
) == 0;