pcre-light 0.4.1.0 → 0.4.1.2
raw patch · 5 files changed
+61/−29 lines, 5 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Text.Regex.PCRE.Light.Base: c_pcre_free :: FinalizerPtr a
Files
- ChangeLog.md +10/−0
- Text/Regex/PCRE/Light.hs +20/−12
- Text/Regex/PCRE/Light/Base.hsc +7/−1
- pcre-light.cabal +17/−16
- tests/Unit.hs +7/−0
+ ChangeLog.md view
@@ -0,0 +1,10 @@+# Changelog for pcre-light++## 0.4.1.2+- Replace finalizerFree with c_pcre_free. ([PR 17](https://gitlab.com/daniel-casanueva/pcre-light/-/merge_requests/17))++## 0.4.1.1+- Bugfix where ByteString.empty was treated differently than the empty ByteString `""`++## 0.4.1.0+- Add `captureCount` and `captureNames` for working with named captures/groups
Text/Regex/PCRE/Light.hs view
@@ -201,15 +201,15 @@ compileM str os = unsafePerformIO $ S.useAsCString str $ \pattern -> do alloca $ \errptr -> do- alloca $ \erroffset -> do- pcre_ptr <- c_pcre_compile pattern (combineOptions os) errptr erroffset nullPtr- if pcre_ptr == nullPtr- then do- err <- peekCString =<< peek errptr- return (Left err)- else do- reg <- newForeignPtr finalizerFree pcre_ptr -- release with free()- return (Right (Regex reg str))+ alloca $ \erroffset -> do+ pcre_ptr <- c_pcre_compile pattern (combineOptions os) errptr erroffset nullPtr+ if pcre_ptr == nullPtr+ then do+ err <- peekCString =<< peek errptr+ return (Left err)+ else do+ reg <- newForeignPtr c_pcre_free pcre_ptr+ return (Right (Regex reg str)) -- Possible improvements: an 'IsString' instance could be defined -- for 'Regex', which would allow the compiler to insert calls to@@ -283,15 +283,23 @@ let (str_fp, off, len) = S.toForeignPtr subject withForeignPtr str_fp $ \cstr -> do- r <- c_pcre_exec+ let exec csub clen = c_pcre_exec pcre_ptr nullPtr- (cstr `plusPtr` off) -- may contain binary zero bytes.- (fromIntegral len)+ csub -- may contain binary zero bytes.+ (fromIntegral clen) 0 (combineExecOptions os) ovec (fromIntegral ovec_size)++ -- An empty ByteString may be represented with a nullPtr. Passing+ -- a nullPtr to pcre_exec will cause it to return an error, even if+ -- the pattern could succesfully match an empty subject. As a+ -- workaround, allocate a small buffer and pass that to pcre_exec.+ r <- if cstr == nullPtr+ then allocaBytes 1 $ \buf -> exec buf 0+ else exec (cstr `plusPtr` off) len if r < 0 -- errors, or error_no_match then return Nothing
Text/Regex/PCRE/Light/Base.hsc view
@@ -1,4 +1,5 @@-{-# LANGUAGE CPP, ForeignFunctionInterface, GeneralizedNewtypeDeriving #-}+{-# LANGUAGE CPP, ForeignFunctionInterface, CApiFFI #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-} -------------------------------------------------------------------- -- | -- Module : Text.Regex.PCRE.Light.Base@@ -25,6 +26,7 @@ , c_pcre_compile , c_pcre_exec , c_pcre_fullinfo+ , c_pcre_free ------------------------------------------------------------------------ @@ -823,4 +825,8 @@ -> PCREInfo -> Ptr a -> IO CInt++-- | Return pcre_free finalizer+foreign import capi "pcre.h value pcre_free"+ c_pcre_free :: FinalizerPtr a
pcre-light.cabal view
@@ -1,26 +1,25 @@ name: pcre-light-version: 0.4.1.0-homepage: https://github.com/Daniel-Diaz/pcre-light+version: 0.4.1.2+homepage: https://gitlab.com/daniel-casanueva/pcre-light synopsis: Portable regex library for Perl 5 compatible regular expressions description:- A small, efficient and portable regex library for Perl 5 compatible regular expressions+ A small, efficient and portable regex library for Perl 5 compatible regular expressions. . The PCRE library is a set of functions that implement regular expression pattern matching using the same syntax and semantics as Perl 5. .- If installation fails reporting that you are missing the prce C library, try installing- the @libpcre3-dev@ package (linux) or @brew install pcre@ (MacOS).+ If installation fails with missing pcre/pkg-config, try installing+ the @libpcre3-dev@ package (linux) or running @brew install pcre pkg-config@ (macOS). .-category: Text-license: BSD3-license-file: LICENSE-copyright: (c) 2007-2010. Don Stewart <dons@galois.com>-author: Don Stewart-maintainer: Daniel Díaz <dhelta.diaz@gmail.com>-cabal-version: >= 1.8.0-build-type: Simple-tested-with: GHC == 7.8.3-extra-source-files: README.md+category: Text+license: BSD3+license-file: LICENSE+copyright: (c) 2007-2010. Don Stewart <dons@galois.com>+author: Don Stewart+maintainer: Daniel Casanueva <daniel.casanueva `at` proton.me>+cabal-version: 1.18+build-type: Simple+extra-doc-files: README.md, ChangeLog.md flag old_base description: Build with an old version of base (< 3)@@ -35,7 +34,8 @@ Text.Regex.PCRE.Light.Char8 Text.Regex.PCRE.Light.Base - extensions: CPP, ForeignFunctionInterface+ default-language: Haskell2010+ default-extensions: CPP, ForeignFunctionInterface if flag(old_base) build-depends: base < 3@@ -49,6 +49,7 @@ test-suite unit type: exitcode-stdio-1.0+ default-language: Haskell2010 hs-source-dirs: tests main-is: Unit.hs if flag(old_base)
tests/Unit.hs view
@@ -4451,6 +4451,13 @@ Nothing, Nothing] + , -- Regression test; ensure "" and empty are treated the same.+ testRegex ".*" []+ [ ""+ , S.empty]+ [Just [""]+ ,Just [""]]+ -- named capture group tests , -- Handles cases with no capture groups testCaptures 0 "no capture groups" []