@@ -56,12 +56,17 @@ module Data.Text
59− -- * Case conversion
59+ -- ** Case conversion
61 , toCaseFold
61 , toCaseFold
65 -- * Folds
70 -- * Folds
@@ -163,7 +168,7 @@ import Prelude (Char, Bool(..), Functor(..), Int, Maybe(..), String,
163 Eq(..), Ord(..), (++),
168 Eq(..), Ord(..), (++),
164 Read(..), Show(..),
169 Read(..), Show(..),
165 (&&), (||), (+), (-), (.), ($),
170 (&&), (||), (+), (-), (.), ($),
166− not, return, otherwise)
171+ div, not, return, otherwise)
167import Control.Exception (assert)
172import Control.Exception (assert)
168import Data.Char (isSpace)
173import Data.Char (isSpace)
169import Control.Monad.ST (ST)
174import Control.Monad.ST (ST)
@@ -452,6 +457,52 @@ toUpper :: Text -> Text
452toUpper t = unstream (S.toUpper (stream t))
457toUpper t = unstream (S.toUpper (stream t))
453{-# INLINE toUpper #-}
458{-# INLINE toUpper #-}
460+-- | /O(n)/ Left-justify a string to the given length, using the
461+-- specified fill character on the right. This function is subject to
462+-- array fusion. Examples:
464+-- > justifyLeft 7 'x' "foo" == "fooxxxx"
465+-- > justifyLeft 3 'x' "foobar" == "foobar"
466+justifyLeft :: Int -> Char -> Text -> Text
469+ | otherwise = t `append` replicate (k-len) c
470+ where len = length t
471+{-# INLINE [1] justifyLeft #-}
474+"TEXT justifyLeft -> fused" [~1] forall k c t.
475+ justifyLeft k c t = unstream (S.justifyLeft k c (stream t))
476+"TEXT justifyLeft -> unfused" [1] forall k c t.
477+ unstream (S.justifyLeft k c (stream t)) = justifyLeft k c t
480+-- | /O(n)/ Right-justify a string to the given length, using the
481+-- specified fill character on the left. Examples:
483+-- > justifyRight 7 'x' "bar" == "xxxxbar"
484+-- > justifyRight 3 'x' "foobar" == "foobar"
485+justifyRight :: Int -> Char -> Text -> Text
488+ | otherwise = replicate (k-len) c `append` t
489+ where len = length t
490+{-# INLINE justifyRight #-}
492+-- | /O(n)/ Center a string to the given length, using the
493+-- specified fill character on either side. Examples:
495+-- > center 8 'x' "HS" = "xxxHSxxx"
496+center :: Int -> Char -> Text -> Text
499+ | otherwise = replicate l c `append` t `append` replicate r c
500+ where len = length t
504+{-# INLINE center #-}
455-- | /O(n)/ The 'transpose' function transposes the rows and columns
506-- | /O(n)/ The 'transpose' function transposes the rows and columns
456-- of its 'Text' argument. Note that this function uses 'pack',
507-- of its 'Text' argument. Note that this function uses 'pack',
457-- 'unpack', and the list version of transpose, and is thus not very
508-- 'unpack', and the list version of transpose, and is thus not very