on master help sign in
Fix behaviour of toTitle
9af7c1dBryan O'Sullivan
Data/Text.hs+4−4
@@ -688,10 +688,10 @@ toUpper t = unstream (S.toUpper (stream t))
688-- | /O(n)/ Convert a string to title case, using simple case
688-- | /O(n)/ Convert a string to title case, using simple case
689-- conversion. Subject to fusion.
689-- conversion. Subject to fusion.
690--
690--
691−-- Unlike the other case conversion functions, this function does not
692−-- convert every letter of its input. Instead, the first letter is
693−-- converted to title case, as is every subsequent letter that
691+-- The first letter of the input is converted to title case, as is
694−-- immediately follows a non-letter.
692+-- every subsequent letter that immediately follows a non-letter.
693+-- Every letter that immediately follows another letter is converted
694+-- to lower case.
695--
695--
696-- The result string may be longer than the input string. For example,
696-- The result string may be longer than the input string. For example,
697-- the Latin small ligature fl (U+FB02) is converted to the
697-- the Latin small ligature fl (U+FB02) is converted to the
Data/Text/Fusion/Common.hs+11−9
@@ -438,10 +438,10 @@ toLower = caseConvert lowerMapping
438-- | /O(n)/ Convert a string to title case, using simple case
438-- | /O(n)/ Convert a string to title case, using simple case
439-- conversion.
439-- conversion.
440--
440--
441−-- Unlike the other case conversion functions, this function does not
442−-- convert every letter of its input. Instead, the first letter is
443−-- converted to title case, as is every subsequent letter that
441+-- The first letter of the input is converted to title case, as is
444−-- immediately follows a non-letter.
442+-- every subsequent letter that immediately follows a non-letter.
443+-- Every letter that immediately follows another letter is converted
444+-- to lower case.
445--
445--
446-- The result string may be longer than the input string. For example,
446-- The result string may be longer than the input string. For example,
447-- the Latin small ligature fl (U+FB02) is converted to the
447-- the Latin small ligature fl (U+FB02) is converted to the
@@ -458,13 +458,15 @@ toTitle (Stream next0 s0 len) = Stream next (CC (False :*: s0) '\0' '\0') len
458 where
458 where
459 next (CC (letter :*: s) '\0' _) =
459 next (CC (letter :*: s) '\0' _) =
460 case next0 s of
460 case next0 s of
461− Done -> Done
461+ Done -> Done
462− Skip s' -> Skip (CC (letter :*: s') '\0' '\0')
462+ Skip s' -> Skip (CC (letter :*: s') '\0' '\0')
463 Yield c s'
463 Yield c s'
464+ | letter' -> if letter
465+ then lowerMapping c (letter' :*: s')
464− | not letter && letter' -> titleMapping c (letter' :*: s')
466+ else titleMapping c (letter' :*: s')
465− | otherwise -> Yield c (CC (letter' :*: s') '\0' '\0')
467+ | otherwise -> Yield c (CC (letter' :*: s') '\0' '\0')
466 where letter' = isLetter c
468 where letter' = isLetter c
467− next (CC s a b) = Yield a (CC s b '\0')
469+ next (CC s a b) = Yield a (CC s b '\0')
468{-# INLINE [0] toTitle #-}
470{-# INLINE [0] toTitle #-}
469
471
470justifyLeftI :: Integral a => a -> Char -> Stream Char -> Stream Char
472justifyLeftI :: Integral a => a -> Char -> Stream Char -> Stream Char
Data/Text/Lazy.hs+4−4
@@ -707,10 +707,10 @@ toUpper t = unstream (S.toUpper (stream t))
707-- | /O(n)/ Convert a string to title case, using simple case
707-- | /O(n)/ Convert a string to title case, using simple case
708-- conversion. Subject to fusion.
708-- conversion. Subject to fusion.
709--
709--
710−-- Unlike the other case conversion functions, this function does not
711−-- convert every letter of its input. Instead, the first letter is
712−-- converted to title case, as is every subsequent letter that
710+-- The first letter of the input is converted to title case, as is
713−-- immediately follows a non-letter.
711+-- every subsequent letter that immediately follows a non-letter.
712+-- Every letter that immediately follows another letter is converted
713+-- to lower case.
714--
714--
715-- The result string may be longer than the input string. For example,
715-- The result string may be longer than the input string. For example,
716-- the Latin small ligature fl (U+FB02) is converted to the
716-- the Latin small ligature fl (U+FB02) is converted to the