on master help sign in
Improve comments.
f584cbcBryan O'Sullivan
Data/Text.hs+31−29
@@ -113,6 +113,7 @@ module Data.Text
113 , tails
113 , tails
114
114
115 -- ** Breaking into many substrings
115 -- ** Breaking into many substrings
116+ -- $split
116 , split
117 , split
117 , splitTimes
118 , splitTimes
118 , splitChar
119 , splitChar
@@ -405,12 +406,12 @@ replace s d = intercalate d . split s
405
406
406-- $case
407-- $case
407--
408--
408−-- With Unicode text, it is incorrect to use combinators like @map
409+-- When case converting Unicode text, it is incorrect to use
409−-- toUpper@ to case convert each character of a string individually.
410+-- combinators like @map toUpper@ to case convert each character of a
410−-- Instead, use the whole-string case conversion functions from this
411+-- string individually. Instead, use the whole-string case conversion
411−-- module. For correctness in different writing systems, these
412+-- functions from this module. For correctness in different writing
412−-- functions may map one input character to two or three output
413+-- systems, these functions may map one input character to two or
413−-- characters.
414+-- three output characters.
414
415
415-- | /O(n)/ Convert a string to folded case. This function is mainly
416-- | /O(n)/ Convert a string to folded case. This function is mainly
416-- useful for performing caseless (or case insensitive) string
417-- useful for performing caseless (or case insensitive) string
@@ -422,27 +423,28 @@ replace s d = intercalate d . split s
422--
423--
423-- The result string may be longer than the input string, and may
424-- The result string may be longer than the input string, and may
424-- differ from applying 'toLower' to the input string. For instance,
425-- differ from applying 'toLower' to the input string. For instance,
425−-- the Armenian small ligature men now (U+FB13) is case folded to the
426+-- the Armenian small ligature \"ﬓ\" (men now, U+FB13) is case
427+-- folded to the sequence \"մ\" (men, U+0574) followed by
426−-- bigram men now (U+0574 U+0576), while the micro sign (U+00B5) is
428+-- \"ն\" (now, U+0576), while the Greek \"µ\" (micro sign,
427−-- case folded to the Greek small letter letter mu (U+03BC) instead of
429+-- U+00B5) is case folded to \"μ\" (small letter mu, U+03BC)
428−-- itself.
430+-- instead of itself.
429toCaseFold :: Text -> Text
431toCaseFold :: Text -> Text
430toCaseFold t = unstream (S.toCaseFold (stream t))
432toCaseFold t = unstream (S.toCaseFold (stream t))
431{-# INLINE [0] toCaseFold #-}
433{-# INLINE [0] toCaseFold #-}
432
434
433-- | /O(n)/ Convert a string to lower case, using simple case
435-- | /O(n)/ Convert a string to lower case, using simple case
434-- conversion. The result string may be longer than the input string.
436-- conversion. The result string may be longer than the input string.
435−-- For instance, the Latin capital letter I with dot above (U+0130)
437+-- For instance, \"İ\" (Latin capital letter I with dot above,
436−-- maps to the bigram Latin small letter i (U+0069) followed by
438+-- U+0130) maps to the sequence \"i\" (Latin small letter i, U+0069) followed
437−-- combining dot above (U+0307).
439+-- by \" ̇\" (combining dot above, U+0307).
438toLower :: Text -> Text
440toLower :: Text -> Text
439toLower t = unstream (S.toLower (stream t))
441toLower t = unstream (S.toLower (stream t))
440{-# INLINE toLower #-}
442{-# INLINE toLower #-}
441
443
442-- | /O(n)/ Convert a string to upper case, using simple case
444-- | /O(n)/ Convert a string to upper case, using simple case
443-- conversion. The result string may be longer than the input string.
445-- conversion. The result string may be longer than the input string.
444−-- For instance, the German eszett (U+00DF) maps to the two-letter
446+-- For instance, the German \"ß\" (eszett, U+00DF) maps to the
445−-- sequence SS.
447+-- two-letter sequence \"SS\".
446toUpper :: Text -> Text
448toUpper :: Text -> Text
447toUpper t = unstream (S.toUpper (stream t))
449toUpper t = unstream (S.toUpper (stream t))
448{-# INLINE toUpper #-}
450{-# INLINE toUpper #-}
@@ -824,17 +826,19 @@ tails t | null t = [empty]
824-- and
826-- and
825--
827--
826-- > intercalate (singleton c) . splitChar c == id
828-- > intercalate (singleton c) . splitChar c == id
827−-- > splitChar == splitWith . (==)
829+-- > splitChar == splitWith . (==)
828−--
829−-- As with all splitting functions in this library, this function does
830−-- not copy the substrings, it just constructs new 'Text's that are
831−-- slices of the original.
832splitChar :: Char -> Text -> [Text]
830splitChar :: Char -> Text -> [Text]
833splitChar c = splitWith (==c)
831splitChar c = splitWith (==c)
834{-# INLINE splitChar #-}
832{-# INLINE splitChar #-}
835
833
834+-- $split
835+--
836+-- Splitting functions in this library do not perform character-wise
837+-- copies to create substrings; they just construct new 'Text's that
838+-- are slices of the original.
839+
836−-- | /O(m)*O(n)/ Break a 'Text' into pieces separated by the 'Text'
840+-- | /O(m)*O(n)/ Break a 'Text' into pieces separated by the first
837−-- argument, consuming the delimiter. I.e.
841+-- 'Text' argument, consuming the delimiter. Examples:
838--
842--
839-- > split "\r\n" "a\r\nb\r\nd\r\ne" == ["a","b","d","e"]
843-- > split "\r\n" "a\r\nb\r\nd\r\ne" == ["a","b","d","e"]
840-- > split "aaa" "aaaXaaaXaaaXaaa" == ["","X","X","X",""]
844-- > split "aaa" "aaaXaaaXaaaXaaa" == ["","X","X","X",""]
@@ -842,17 +846,15 @@ splitChar c = splitWith (==c)
842--
846--
843-- and
847-- and
844--
848--
845−-- > intercalate s . split s == id
849+-- > intercalate s . split s == id
846−--
847−-- As with all splitting functions in this library, this function does
848−-- not copy the substrings, it just constructs new 'Text's that are
849−-- slices of the original.
850−split :: Text -> Text -> [Text]
850+split :: Text -- ^ Text to split on
851+ -> Text -- ^ Input text
852+ -> [Text]
851split pat src0
853split pat src0
852 | l == 0 = [src0]
854 | l == 0 = [src0]
853 | otherwise = go src0
855 | otherwise = go src0
854 where
856 where
855− l = length pat
857+ l = length pat
856 go src = search 0 src
858 go src = search 0 src
857 where
859 where
858 search !n !s
860 search !n !s