@@ -1,4 +1,4 @@
1−{-# LANGUAGE BangPatterns #-}
1+{-# LANGUAGE BangPatterns, Rank2Types #-}
3-- Module : Data.Text.Fusion.Common
3-- Module : Data.Text.Fusion.Common
4-- Copyright : (c) Bryan O'Sullivan 2009
4-- Copyright : (c) Bryan O'Sullivan 2009
@@ -37,6 +37,7 @@ module Data.Text.Fusion.Common
38 -- ** Case conversion
38 -- ** Case conversion
41 -- * Folds
42 -- * Folds
@@ -99,7 +100,7 @@ import Prelude (Bool(..), Char, Either(..), Eq(..), Int, Integral, Maybe(..),
99import qualified Data.List as L
100import qualified Data.List as L
100import qualified Prelude as P
101import qualified Prelude as P
101import Data.Text.Fusion.Internal
102import Data.Text.Fusion.Internal
102−import Data.Text.Fusion.CaseMapping (upperMapping)
103+import Data.Text.Fusion.CaseMapping (lowerMapping, upperMapping)
104singleton :: Char -> Stream Char
105singleton :: Char -> Stream Char
105singleton c = Stream next False 1 -- HINT maybe too low
106singleton c = Stream next False 1 -- HINT maybe too low
@@ -299,22 +300,34 @@ intersperse c (Stream next0 s0 len) = Stream next (s0 :!: N :!: S1) len -- HINT
299-- ----------------------------------------------------------------------------
300-- ----------------------------------------------------------------------------
300-- ** Case conversions (folds)
301-- ** Case conversions (folds)
302−-- | /O(n)/ Convert a string to upper case, using simple case
303+caseConvert :: (forall s. Char -> s -> Step (PairS (PairS s Char) Char) Char)
303−-- conversion. The result string may be longer than the input string.
304−-- For instance, the German eszett (U+00DF) maps to the two-letter
306−toUpper :: Stream Char -> Stream Char
304+ -> Stream Char -> Stream Char
307−toUpper (Stream next0 s0 len) = Stream next (s0 :!: '\0' :!: '\0') len
305+caseConvert remap (Stream next0 s0 len) = Stream next (s0 :!: '\0' :!: '\0') len
309 {-# INLINE next #-}
307 {-# INLINE next #-}
310 next (s :!: '\0' :!: _) =
308 next (s :!: '\0' :!: _) =
311 case next0 s of
309 case next0 s of
312 Done -> Done
310 Done -> Done
313 Skip s' -> Skip (s' :!: '\0' :!: '\0')
311 Skip s' -> Skip (s' :!: '\0' :!: '\0')
314− Yield c s' -> upperMapping c s'
312+ Yield c s' -> remap c s'
315 next (s :!: a :!: b) = Yield a (s :!: b :!: '\0')
313 next (s :!: a :!: b) = Yield a (s :!: b :!: '\0')
315+-- | /O(n)/ Convert a string to upper case, using simple case
316+-- conversion. The result string may be longer than the input string.
317+-- For instance, the German eszett (U+00DF) maps to the two-letter
319+toUpper :: Stream Char -> Stream Char
320+toUpper = caseConvert upperMapping
316{-# INLINE [0] toUpper #-}
321{-# INLINE [0] toUpper #-}
323+-- | /O(n)/ Convert a string to lower case, using simple case
324+-- conversion. The result string may be longer than the input string.
325+-- For instance, the German eszett (U+00DF) maps to the two-letter
327+toLower :: Stream Char -> Stream Char
328+toLower = caseConvert lowerMapping
329+{-# INLINE [0] toLower #-}
318-- ----------------------------------------------------------------------------
331-- ----------------------------------------------------------------------------
319-- * Reducing Streams (folds)
332-- * Reducing Streams (folds)