-
Notifications
You must be signed in to change notification settings - Fork 7
/
pcre_wrapper.go
36 lines (27 loc) · 784 Bytes
/
pcre_wrapper.go
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
31
32
33
34
35
36
// Copyright 2018 Couchbase, Inc. All rights reserved.
// +build pcre
package gojsonsm
import (
"errors"
"github.com/glenn-brown/golang-pkg-pcre/src/pkg/pcre"
)
type PcreWrapper struct {
pcreRegex *pcre.Regexp
}
func MakePcreWrapper(expression string) (PcreWrapperInterface, error) {
pcreWrapper := &PcreWrapper{}
pcreRegex, err := pcre.Compile(expression, 0)
if err != nil {
return pcreWrapper, errors.New("failed to compile PcreExpr: " + err.Message)
}
pcreWrapper.pcreRegex = &pcreRegex
return pcreWrapper, nil
}
func (wrapper *PcreWrapper) Match(b []byte) bool {
matcher := pcre.Matcher{}
matcher.Reset(*wrapper.pcreRegex, b, 0)
return matcher.Matches()
}
func MakePcreExpression(expression string) (Expression, error) {
return PcreExpr{expression}, nil
}