@@ -17,12 +17,9 @@ module Distribution.Utils.CharSet (
1717 difference ,
1818 -- * Query
1919 size ,
20- null ,
21- member ,
2220 -- * Conversions
2321 fromList ,
2422 toList ,
25- fromIntervalList ,
2623 toIntervalList ,
2724 -- * Special lists
2825 alpha ,
@@ -32,12 +29,12 @@ module Distribution.Utils.CharSet (
3229 ) where
3330
3431import Data.Char (chr , isAlpha , isAlphaNum , isDigit , isUpper , ord )
35- import Data.List (foldl' , sortBy )
32+ import Data.List (foldl' )
3633import Data.Monoid (Monoid (.. ))
3734import Data.String (IsString (.. ))
3835import Distribution.Compat.Semigroup (Semigroup (.. ))
3936import 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 ,
4138 showString , uncurry , ($) , (.) )
4239
4340#if MIN_VERSION_containers(0,5,0)
@@ -79,40 +76,15 @@ empty = CS IM.empty
7976universe :: CharSet
8077universe = CS $ IM. singleton 0 0x10ffff
8178
82- -- | Check whether 'CharSet' is 'empty'.
83- null :: CharSet -> Bool
84- null (CS cs) = IM. null cs
85-
8679-- | Size of 'CharSet'
8780--
88- -- >>> size $ fromIntervalList [('a','f'), ('0','9')]
89- -- 16
90- --
91- -- >>> length $ toList $ fromIntervalList [('a','f'), ('0','9')]
92- -- 16
93- --
9481size :: CharSet -> Int
9582size (CS m) = foldl' (\ ! acc (lo, hi) -> acc + (hi - lo) + 1 ) 0 (IM. toList m)
9683
9784-- | Singleton character set.
9885singleton :: Char -> CharSet
9986singleton c = CS (IM. singleton (ord c) (ord c))
10087
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-
11688-- | Insert 'Char' into 'CharSet'.
11789{- FOURMOLU_DISABLE -}
11890insert :: Char -> CharSet -> CharSet
@@ -182,24 +154,6 @@ toList = concatMap (uncurry enumFromTo) . toIntervalList
182154toIntervalList :: CharSet -> [(Char , Char )]
183155toIntervalList (CS m) = [ (chr lo, chr hi) | (lo, hi) <- IM. toList m ]
184156
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-
203157-------------------------------------------------------------------------------
204158-- Normalisation
205159-------------------------------------------------------------------------------
0 commit comments