1
- {-|
1
+ {-|
2
2
Module : Text.Regex.TDFA.Text
3
3
Copyright : Chris Kuklewicz 2007-2009, shelarcy 2012
4
4
License : BSD-style (see the file LICENSE)
5
5
6
- Maintainer : shelarcy <shelarcy@gmail.com>
7
- Stability : experimental
8
- Portability : GHC (uses text)
9
-
10
6
This modules provides 'RegexMaker' and 'RegexLike' instances for using
11
7
'Text' with the TDFA backend ("Text.Regex.TDFA.NewDFA.Engine" and
12
- "Text.Regex.TDFA.NewDFA.Tester").
8
+ "Text.Regex.TDFA.NewDFA.Tester").
13
9
14
10
This exports instances of the high level API and the medium level
15
11
API of 'compile','execute', and 'regexec'.
12
+
13
+ @since 1.3.1
16
14
-}
17
15
module Text.Regex.TDFA.Text (
18
16
Regex
@@ -38,32 +36,38 @@ import Text.Regex.TDFA.NewDFA.Uncons(Uncons(uncons))
38
36
import qualified Text.Regex.TDFA.NewDFA.Engine as Engine (execMatch )
39
37
import qualified Text.Regex.TDFA.NewDFA.Tester as Tester (matchTest )
40
38
39
+ -- | @since 1.3.1
41
40
instance Uncons T. Text where
42
41
{- INLINE uncons #-}
43
42
uncons = T. uncons
44
43
44
+ -- | @since 1.3.1
45
45
instance RegexContext Regex T. Text T. Text where
46
46
match = polymatch
47
47
matchM = polymatchM
48
48
49
+ -- | @since 1.3.1
49
50
instance RegexMaker Regex CompOption ExecOption T. Text where
50
51
makeRegexOptsM c e source = makeRegexOptsM c e (T. unpack source)
51
52
53
+ -- | @since 1.3.1
52
54
{-# SPECIALIZE execMatch :: Regex -> Position -> Char -> T.Text -> [MatchArray] #-}
53
55
execMatch :: Uncons text => Regex -> Position -> Char -> text -> [MatchArray ]
54
56
execMatch = Engine. execMatch
55
57
58
+ -- | @since 1.3.1
56
59
{-# SPECIALIZE myMatchTest :: Regex -> T.Text -> Bool #-}
57
60
myMatchTest :: Uncons text => Regex -> text -> Bool
58
61
myMatchTest = Tester. matchTest
59
62
63
+ -- | @since 1.3.1
60
64
instance RegexLike Regex T. Text where
61
65
matchOnce r s = listToMaybe (matchAll r s)
62
66
matchAll r s = execMatch r 0 ' \n ' s
63
67
matchCount r s = length (matchAll r' s)
64
68
where r' = r { regex_execOptions = (regex_execOptions r) {captureGroups = False } }
65
69
matchTest = myMatchTest
66
- matchOnceText regex source =
70
+ matchOnceText regex source =
67
71
fmap (\ ma -> let (o,l) = ma! 0
68
72
in (before o source
69
73
,fmap (\ ol -> (extract ol source,ol)) ma
@@ -73,6 +77,7 @@ instance RegexLike Regex T.Text where
73
77
map (fmap (\ ol -> (extract ol source,ol)))
74
78
(matchAll regex source)
75
79
80
+ -- | @since 1.3.1
76
81
compile :: CompOption -- ^ Flags (summed together)
77
82
-> ExecOption -- ^ Flags (summed together)
78
83
-> T. Text -- ^ The regular expression to compile
@@ -82,11 +87,13 @@ compile compOpt execOpt txt =
82
87
Left err -> Left (" parseRegex for Text.Regex.TDFA.Text failed:" ++ show err)
83
88
Right pattern -> Right (patternToRegex pattern compOpt execOpt)
84
89
90
+ -- | @since 1.3.1
85
91
execute :: Regex -- ^ Compiled regular expression
86
92
-> T. Text -- ^ Text to match against
87
93
-> Either String (Maybe MatchArray )
88
94
execute r txt = Right (matchOnce r txt)
89
95
96
+ -- | @since 1.3.1
90
97
regexec :: Regex -- ^ Compiled regular expression
91
98
-> T. Text -- ^ Text to match against
92
99
-> Either String (Maybe (T. Text , T. Text , T. Text , [T. Text ]))
0 commit comments