on master help sign in
Merge pull request #168 from alskipp/toTitle
214598aBryan O'Sullivan
Data/Text/Internal/Fusion/Common.hs+10−9
@@ -107,7 +107,7 @@ import Prelude (Bool(..), Char, Eq(..), Int, Integral, Maybe(..),
107import qualified Data.List as L
107import qualified Data.List as L
108import qualified Prelude as P
108import qualified Prelude as P
109import Data.Bits (shiftL)
109import Data.Bits (shiftL)
110−import Data.Char (isLetter)
110+import Data.Char (isLetter, isSpace)
111import Data.Int (Int64)
111import Data.Int (Int64)
112import Data.Text.Internal.Fusion.Types
112import Data.Text.Internal.Fusion.Types
113import Data.Text.Internal.Fusion.CaseMapping (foldMapping, lowerMapping, titleMapping,
113import Data.Text.Internal.Fusion.CaseMapping (foldMapping, lowerMapping, titleMapping,
@@ -462,15 +462,16 @@ toTitle (Stream next0 s0 len) = Stream next (CC (False :*: s0) '\0' '\0') len
462 where
462 where
463 next (CC (letter :*: s) '\0' _) =
463 next (CC (letter :*: s) '\0' _) =
464 case next0 s of
464 case next0 s of
465− Done -> Done
465+ Done -> Done
466− Skip s' -> Skip (CC (letter :*: s') '\0' '\0')
466+ Skip s' -> Skip (CC (letter :*: s') '\0' '\0')
467 Yield c s'
467 Yield c s'
468− | letter' -> if letter
468+ | nonSpace -> if letter
469− then lowerMapping c (letter' :*: s')
469+ then lowerMapping c (nonSpace :*: s')
470− else titleMapping c (letter' :*: s')
470+ else titleMapping c (letter' :*: s')
471− | otherwise -> Yield c (CC (letter' :*: s') '\0' '\0')
471+ | otherwise -> Yield c (CC (letter' :*: s') '\0' '\0')
472+ where nonSpace = P.not (isSpace c)
472− where letter' = isLetter c
473+ letter' = isLetter c
473− next (CC s a b) = Yield a (CC s b '\0')
474+ next (CC s a b) = Yield a (CC s b '\0')
474{-# INLINE [0] toTitle #-}
475{-# INLINE [0] toTitle #-}
475
476
476data Justify i s = Just1 !i !s
477data Justify i s = Just1 !i !s
tests/Tests/Properties.hs+4−1
@@ -326,6 +326,8 @@ t_toUpper_upper t = p (T.toUpper t) >= p t
326 where p = T.length . T.filter isUpper
326 where p = T.length . T.filter isUpper
327tl_toUpper_upper t = p (TL.toUpper t) >= p t
327tl_toUpper_upper t = p (TL.toUpper t) >= p t
328 where p = TL.length . TL.filter isUpper
328 where p = TL.length . TL.filter isUpper
329+t_toTitle_title t = all (<= 1) (caps t)
330+ where caps = fmap (T.length . T.filter isUpper) . T.words . T.toTitle
329
331
330justifyLeft k c xs = xs ++ L.replicate (k - length xs) c
332justifyLeft k c xs = xs ++ L.replicate (k - length xs) c
331justifyRight m n xs = L.replicate (m - length xs) n ++ xs
333justifyRight m n xs = L.replicate (m - length xs) n ++ xs
@@ -1030,7 +1032,8 @@ tests =
1030 testProperty "tl_toLower_lower" tl_toLower_lower,
1032 testProperty "tl_toLower_lower" tl_toLower_lower,
1031 testProperty "t_toUpper_length" t_toUpper_length,
1033 testProperty "t_toUpper_length" t_toUpper_length,
1032 testProperty "t_toUpper_upper" t_toUpper_upper,
1034 testProperty "t_toUpper_upper" t_toUpper_upper,
1033− testProperty "tl_toUpper_upper" tl_toUpper_upper
1035+ testProperty "tl_toUpper_upper" tl_toUpper_upper,
1036+ testProperty "t_toTitle_title" t_toTitle_title
1034 ],
1037 ],
1035
1038
1036 testGroup "justification" [
1039 testGroup "justification" [