Commits

Bryan O'Sullivan committed 0e82161

Fix behaviour of toTitle

It was not previously lowercasing letters following the first in a word.

Comments (0)

Files changed (3)

 -- | /O(n)/ Convert a string to title case, using simple case
 -- conversion. Subject to fusion.
 --
--- Unlike the other case conversion functions, this function does not
--- convert every letter of its input. Instead, the first letter is
--- converted to title case, as is every subsequent letter that
--- immediately follows a non-letter.
+-- The first letter of the input is converted to title case, as is
+-- every subsequent letter that immediately follows a non-letter.
+-- Every letter that immediately follows another letter is converted
+-- to lower case.
 --
 -- The result string may be longer than the input string. For example,
 -- the Latin small ligature fl (U+FB02) is converted to the

Data/Text/Fusion/Common.hs

 -- | /O(n)/ Convert a string to title case, using simple case
 -- conversion.
 --
--- Unlike the other case conversion functions, this function does not
--- convert every letter of its input. Instead, the first letter is
--- converted to title case, as is every subsequent letter that
--- immediately follows a non-letter.
+-- The first letter of the input is converted to title case, as is
+-- every subsequent letter that immediately follows a non-letter.
+-- Every letter that immediately follows another letter is converted
+-- to lower case.
 --
 -- The result string may be longer than the input string. For example,
 -- the Latin small ligature fl (U+FB02) is converted to the
   where
     next (CC (letter :*: s) '\0' _) =
       case next0 s of
-        Done    -> Done
-        Skip s' -> Skip (CC (letter :*: s') '\0' '\0')
+        Done           -> Done
+        Skip s'        -> Skip (CC (letter :*: s') '\0' '\0')
         Yield c s'
-          | not letter && letter' -> titleMapping c (letter' :*: s')
-          | otherwise -> Yield c (CC (letter' :*: s') '\0' '\0')
+          | letter'    -> if letter
+                          then lowerMapping c (letter' :*: s')
+                          else titleMapping c (letter' :*: s')
+          | otherwise  -> Yield c (CC (letter' :*: s') '\0' '\0')
           where letter' = isLetter c
-    next (CC s a b)  =  Yield a (CC s b '\0')
+    next (CC s a b)     = Yield a (CC s b '\0')
 {-# INLINE [0] toTitle #-}
 
 justifyLeftI :: Integral a => a -> Char -> Stream Char -> Stream Char

Data/Text/Lazy.hs

 -- | /O(n)/ Convert a string to title case, using simple case
 -- conversion.  Subject to fusion.
 --
--- Unlike the other case conversion functions, this function does not
--- convert every letter of its input. Instead, the first letter is
--- converted to title case, as is every subsequent letter that
--- immediately follows a non-letter.
+-- The first letter of the input is converted to title case, as is
+-- every subsequent letter that immediately follows a non-letter.
+-- Every letter that immediately follows another letter is converted
+-- to lower case.
 --
 -- The result string may be longer than the input string. For example,
 -- the Latin small ligature fl (U+FB02) is converted to the