PIRegularExpression::from static constructor
This commit is contained in:
@@ -286,3 +286,37 @@ int PIRegularExpression::Matcher::matchedStart(const PIString & gname) const {
|
||||
int PIRegularExpression::Matcher::matchedSize(const PIString & gname) const {
|
||||
return matchedSize(parent->PRIVATEWB->named_group_index.value(gname));
|
||||
}
|
||||
|
||||
|
||||
PIRegularExpression PIRegularExpression::fromGlob(const PIString & pattern, Options opt) {
|
||||
PIRegularExpression ret;
|
||||
ret.convertFrom(pattern, PCRE2_CONVERT_GLOB, opt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIRegularExpression PIRegularExpression::fromPOSIX(const PIString & pattern, Options opt) {
|
||||
PIRegularExpression ret;
|
||||
ret.convertFrom(pattern, PCRE2_CONVERT_POSIX_BASIC, opt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIRegularExpression::convertFrom(const PIString & pattern, uint type, Options opt) {
|
||||
if (pattern.isEmpty()) return;
|
||||
PIChar * cptr = &((PIString &)pattern)[0];
|
||||
PCRE2_UCHAR * out = nullptr;
|
||||
PCRE2_SIZE out_size = 0;
|
||||
int rc = pcre2_pattern_convert((PCRE2_SPTR)cptr,
|
||||
pattern.size_s(),
|
||||
type | PCRE2_CONVERT_UTF | PCRE2_CONVERT_NO_UTF_CHECK,
|
||||
&out,
|
||||
&out_size,
|
||||
nullptr);
|
||||
if (rc != 0) {
|
||||
piCout << "PIRegularExpression::convertFrom error" << rc;
|
||||
} else {
|
||||
setPattern(PIString((PIChar *)out, out_size), opt);
|
||||
}
|
||||
pcre2_converted_pattern_free(out);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user