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