pcre-heavy 0.2.0 → 0.2.1
raw patch · 3 files changed
+39/−3 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Text.Regex.PCRE.Heavy: split :: Stringable a => Regex -> a -> [a]
+ Text.Regex.PCRE.Heavy: splitO :: Stringable a => Regex -> [PCREExecOption] -> a -> [a]
Files
- README.md +10/−1
- library/Text/Regex/PCRE/Heavy.hs +25/−1
- pcre-heavy.cabal +4/−1
README.md view
@@ -71,9 +71,18 @@ -- I have no idea why you would want to use that, but that's there :-) ``` +### Splitting++`split`, well, splits.++```haskell+>>> split [re|%(begin|next|end)%|] "%begin%hello%next%world%end%"+["","hello","world",""]+```+ ### Options -You can pass `pcre-light` options like this:+You can pass `pcre-light` options by using the `somethingO` variants of functions (and `mkRegexQQ` for compile time options): ```haskell >>> let myRe = mkRegexQQ [multiline, utf8, ungreedy]
library/Text/Regex/PCRE/Heavy.hs view
@@ -17,6 +17,9 @@ , subO , gsub , gsubO+ -- * Splitting+, split+, splitO -- * QuasiQuoter , re , mkRegexQQ@@ -36,7 +39,7 @@ import Text.Regex.PCRE.Light.Base import Control.Applicative ((<$>)) import Data.Maybe (isJust, fromMaybe)-import Data.List (unfoldr)+import Data.List (unfoldr, mapAccumL) import Data.Stringable import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Internal as BS@@ -194,6 +197,27 @@ case rawSub r t acc offset opts of Just (result, newOffset) -> loop newOffset result _ -> acc++-- | Splits the string using the given regex.+--+-- Is lazy.+--+-- >>> split [re|%(begin|next|end)%|] "%begin%hello%next%world%end%"+-- ["","hello","world",""]+--+-- >>> split [re|%(begin|next|end)%|] ""+-- [""]+split :: Stringable a => Regex -> a -> [a]+split r s = splitO r [] s++-- | Exactly like 'split', but passes runtime options to PCRE.+splitO :: Stringable a => Regex -> [PCREExecOption] -> a -> [a]+splitO r opts s = map fromByteString $ map' (substr str) partRanges+ where map' f = foldr ((:) . f) [f (lastL, BS.length str)] -- avoiding the snoc operation+ (lastL, partRanges) = mapAccumL invRange 0 ranges+ invRange acc (xl, xr) = (xr, (acc, xl))+ ranges = map fst $ scanRangesO r opts str+ str = toByteString s instance Lift PCREOption where -- well, the constructor isn't exported, but at least it implements Read/Show :D
pcre-heavy.cabal view
@@ -1,12 +1,15 @@ name: pcre-heavy-version: 0.2.0+version: 0.2.1 synopsis: A regexp library on top of pcre-light you can actually use. description: A regular expressions library that does not suck. - based on <https://hackage.haskell.org/package/pcre-light pcre-light>+ - takes and returns <https://hackage.haskell.org/package/stringable Stringables> everywhere+ - a QuasiQuoter for regexps that does compile time checking+ - SEARCHES FOR MULTIPLE MATCHES! DOES REPLACEMENT! category: Web homepage: https://github.com/myfreeweb/pcre-heavy