@@ -17,12 +17,9 @@ module Distribution.Utils.CharSet (
17
17
difference ,
18
18
-- * Query
19
19
size ,
20
- null ,
21
- member ,
22
20
-- * Conversions
23
21
fromList ,
24
22
toList ,
25
- fromIntervalList ,
26
23
toIntervalList ,
27
24
-- * Special lists
28
25
alpha ,
@@ -32,12 +29,12 @@ module Distribution.Utils.CharSet (
32
29
) where
33
30
34
31
import Data.Char (chr , isAlpha , isAlphaNum , isDigit , isUpper , ord )
35
- import Data.List (foldl' , sortBy )
32
+ import Data.List (foldl' )
36
33
import Data.Monoid (Monoid (.. ))
37
34
import Data.String (IsString (.. ))
38
35
import Distribution.Compat.Semigroup (Semigroup (.. ))
39
36
import Prelude
40
- (Bool ( .. ), Bounded (.. ), Char , Enum (.. ), Eq (.. ), Int , Maybe ( .. ), Num (.. ), Ord (.. ), Show (.. ), String , (&&) , concatMap , flip , fst , not , otherwise , showParen ,
37
+ (Bounded (.. ), Char , Enum (.. ), Eq (.. ), Int , Num (.. ), Ord (.. ), Show (.. ), String , (&&) , concatMap , flip , not , otherwise , showParen ,
41
38
showString , uncurry , ($) , (.) )
42
39
43
40
#if MIN_VERSION_containers(0,5,0)
@@ -79,40 +76,15 @@ empty = CS IM.empty
79
76
universe :: CharSet
80
77
universe = CS $ IM. singleton 0 0x10ffff
81
78
82
- -- | Check whether 'CharSet' is 'empty'.
83
- null :: CharSet -> Bool
84
- null (CS cs) = IM. null cs
85
-
86
79
-- | Size of 'CharSet'
87
80
--
88
- -- >>> size $ fromIntervalList [('a','f'), ('0','9')]
89
- -- 16
90
- --
91
- -- >>> length $ toList $ fromIntervalList [('a','f'), ('0','9')]
92
- -- 16
93
- --
94
81
size :: CharSet -> Int
95
82
size (CS m) = foldl' (\ ! acc (lo, hi) -> acc + (hi - lo) + 1 ) 0 (IM. toList m)
96
83
97
84
-- | Singleton character set.
98
85
singleton :: Char -> CharSet
99
86
singleton c = CS (IM. singleton (ord c) (ord c))
100
87
101
- -- | Test whether character is in the set.
102
- member :: Char -> CharSet -> Bool
103
- #if MIN_VERSION_containers(0,5,0)
104
- member c (CS m) = case IM. lookupLE i m of
105
- Nothing -> False
106
- Just (_, hi) -> i <= hi
107
- where
108
- #else
109
- member c (CS m) = go (IM. toList m)
110
- where
111
- go [] = False
112
- go ((x,y): zs) = (x <= i && i <= y) || go zs
113
- #endif
114
- i = ord c
115
-
116
88
-- | Insert 'Char' into 'CharSet'.
117
89
{- FOURMOLU_DISABLE -}
118
90
insert :: Char -> CharSet -> CharSet
@@ -182,24 +154,6 @@ toList = concatMap (uncurry enumFromTo) . toIntervalList
182
154
toIntervalList :: CharSet -> [(Char , Char )]
183
155
toIntervalList (CS m) = [ (chr lo, chr hi) | (lo, hi) <- IM. toList m ]
184
156
185
- -- | Convert from interval pairs.
186
- --
187
- -- >>> fromIntervalList []
188
- -- ""
189
- --
190
- -- >>> fromIntervalList [('a','f'), ('0','9')]
191
- -- "0123456789abcdef"
192
- --
193
- -- >>> fromIntervalList [('Z','A')]
194
- -- ""
195
- --
196
- fromIntervalList :: [(Char ,Char )] -> CharSet
197
- fromIntervalList xs = normalise' $ sortBy (\ a b -> compare (fst a) (fst b))
198
- [ (ord lo, ord hi)
199
- | (lo, hi) <- xs
200
- , lo <= hi
201
- ]
202
-
203
157
-------------------------------------------------------------------------------
204
158
-- Normalisation
205
159
-------------------------------------------------------------------------------
0 commit comments