Add hasOffset to PcreError
This commit is contained in:
parent
584b071162
commit
0a475038e1
6
error.go
6
error.go
@ -49,6 +49,7 @@ func ptrToError(tls *libc.TLS, pe uintptr) *PcreError {
|
|||||||
|
|
||||||
err := codeToError(tls, eo.errCode)
|
err := codeToError(tls, eo.errCode)
|
||||||
err.offset = eo.errOffset
|
err.offset = eo.errOffset
|
||||||
|
err.hasOffset = true
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -62,12 +63,13 @@ func codeToError(tls *libc.TLS, code int32) *PcreError {
|
|||||||
// and store it in errBuf.
|
// and store it in errBuf.
|
||||||
msgLen := lib.Xpcre2_get_error_message_8(tls, code, cErrBuf, 256)
|
msgLen := lib.Xpcre2_get_error_message_8(tls, code, cErrBuf, 256)
|
||||||
|
|
||||||
return &PcreError{0, string(errBuf[:msgLen])}
|
return &PcreError{false, 0, string(errBuf[:msgLen])}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PcreError represents errors returned
|
// PcreError represents errors returned
|
||||||
// by underlying pcre2 functions.
|
// by underlying pcre2 functions.
|
||||||
type PcreError struct {
|
type PcreError struct {
|
||||||
|
hasOffset bool
|
||||||
offset lib.Tsize_t
|
offset lib.Tsize_t
|
||||||
errStr string
|
errStr string
|
||||||
}
|
}
|
||||||
@ -75,7 +77,7 @@ type PcreError struct {
|
|||||||
// Error returns the string within the error,
|
// Error returns the string within the error,
|
||||||
// prepending the offset if it exists.
|
// prepending the offset if it exists.
|
||||||
func (pe *PcreError) Error() string {
|
func (pe *PcreError) Error() string {
|
||||||
if pe.offset == 0 {
|
if !pe.hasOffset {
|
||||||
return pe.errStr
|
return pe.errStr
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("offset %d: %s", pe.offset, pe.errStr)
|
return fmt.Sprintf("offset %d: %s", pe.offset, pe.errStr)
|
||||||
|
Loading…
Reference in New Issue
Block a user