on master help sign in
Rename textP to text
7217d93Bryan O'Sullivan
Data/Text.hs+20−20
@@ -213,7 +213,7 @@ import qualified Data.Text.Internal.Fusion as S
213import qualified Data.Text.Internal.Fusion.Common as S
213import qualified Data.Text.Internal.Fusion.Common as S
214import Data.Text.Internal.Fusion (stream, reverseStream, unstream)
214import Data.Text.Internal.Fusion (stream, reverseStream, unstream)
215import Data.Text.Internal.Private (span_)
215import Data.Text.Internal.Private (span_)
216−import Data.Text.Internal (Text(..), empty, firstf, safe, textP)
216+import Data.Text.Internal (Text(..), empty, firstf, safe, text)
217import qualified Prelude as P
217import qualified Prelude as P
218import Data.Text.Unsafe (Iter(..), iter, iter_, lengthWord16, reverseIter,
218import Data.Text.Unsafe (Iter(..), iter, iter_, lengthWord16, reverseIter,
219 reverseIter_, unsafeHead, unsafeTail)
219 reverseIter_, unsafeHead, unsafeTail)
@@ -452,7 +452,7 @@ head t = S.head (stream t)
452uncons :: Text -> Maybe (Char, Text)
452uncons :: Text -> Maybe (Char, Text)
453uncons t@(Text arr off len)
453uncons t@(Text arr off len)
454 | len <= 0 = Nothing
454 | len <= 0 = Nothing
455− | otherwise = Just (c, textP arr (off+d) (len-d))
455+ | otherwise = Just (c, text arr (off+d) (len-d))
456 where Iter c d = iter t 0
456 where Iter c d = iter t 0
457{-# INLINE [1] uncons #-}
457{-# INLINE [1] uncons #-}
458
458
@@ -483,7 +483,7 @@ last (Text arr off len)
483tail :: Text -> Text
483tail :: Text -> Text
484tail t@(Text arr off len)
484tail t@(Text arr off len)
485 | len <= 0 = emptyError "tail"
485 | len <= 0 = emptyError "tail"
486− | otherwise = textP arr (off+d) (len-d)
486+ | otherwise = text arr (off+d) (len-d)
487 where d = iter_ t 0
487 where d = iter_ t 0
488{-# INLINE [1] tail #-}
488{-# INLINE [1] tail #-}
489
489
@@ -498,8 +498,8 @@ tail t@(Text arr off len)
498-- be non-empty. Subject to fusion.
498-- be non-empty. Subject to fusion.
499init :: Text -> Text
499init :: Text -> Text
500init (Text arr off len) | len <= 0 = emptyError "init"
500init (Text arr off len) | len <= 0 = emptyError "init"
501− | n >= 0xDC00 && n <= 0xDFFF = textP arr off (len-2)
501+ | n >= 0xDC00 && n <= 0xDFFF = text arr off (len-2)
502− | otherwise = textP arr off (len-1)
502+ | otherwise = text arr off (len-1)
503 where
503 where
504 n = A.unsafeIndex arr (off+len-1)
504 n = A.unsafeIndex arr (off+len-1)
505{-# INLINE [1] init #-}
505{-# INLINE [1] init #-}
@@ -1004,7 +1004,7 @@ take :: Int -> Text -> Text
1004take n t@(Text arr off len)
1004take n t@(Text arr off len)
1005 | n <= 0 = empty
1005 | n <= 0 = empty
1006 | n >= len = t
1006 | n >= len = t
1007− | otherwise = textP arr off (iterN n t)
1007+ | otherwise = text arr off (iterN n t)
1008{-# INLINE [1] take #-}
1008{-# INLINE [1] take #-}
1009
1009
1010iterN :: Int -> Text -> Int
1010iterN :: Int -> Text -> Int
@@ -1031,7 +1031,7 @@ takeEnd :: Int -> Text -> Text
1031takeEnd n t@(Text arr off len)
1031takeEnd n t@(Text arr off len)
1032 | n <= 0 = empty
1032 | n <= 0 = empty
1033 | n >= len = t
1033 | n >= len = t
1034− | otherwise = textP arr (off+i) (len-i)
1034+ | otherwise = text arr (off+i) (len-i)
1035 where i = iterNEnd n t
1035 where i = iterNEnd n t
1036
1036
1037iterNEnd :: Int -> Text -> Int
1037iterNEnd :: Int -> Text -> Int
@@ -1049,7 +1049,7 @@ drop :: Int -> Text -> Text
1049drop n t@(Text arr off len)
1049drop n t@(Text arr off len)
1050 | n <= 0 = t
1050 | n <= 0 = t
1051 | n >= len = empty
1051 | n >= len = empty
1052− | otherwise = textP arr (off+i) (len-i)
1052+ | otherwise = text arr (off+i) (len-i)
1053 where i = iterN n t
1053 where i = iterN n t
1054{-# INLINE [1] drop #-}
1054{-# INLINE [1] drop #-}
1055
1055
@@ -1070,7 +1070,7 @@ dropEnd :: Int -> Text -> Text
1070dropEnd n t@(Text arr off len)
1070dropEnd n t@(Text arr off len)
1071 | n <= 0 = t
1071 | n <= 0 = t
1072 | n >= len = empty
1072 | n >= len = empty
1073− | otherwise = textP arr off (iterNEnd n t)
1073+ | otherwise = text arr off (iterNEnd n t)
1074
1074
1075-- | /O(n)/ 'takeWhile', applied to a predicate @p@ and a 'Text',
1075-- | /O(n)/ 'takeWhile', applied to a predicate @p@ and a 'Text',
1076-- returns the longest prefix (possibly empty) of elements that
1076-- returns the longest prefix (possibly empty) of elements that
@@ -1079,7 +1079,7 @@ takeWhile :: (Char -> Bool) -> Text -> Text
1079takeWhile p t@(Text arr off len) = loop 0
1079takeWhile p t@(Text arr off len) = loop 0
1080 where loop !i | i >= len = t
1080 where loop !i | i >= len = t
1081 | p c = loop (i+d)
1081 | p c = loop (i+d)
1082− | otherwise = textP arr off i
1082+ | otherwise = text arr off i
1083 where Iter c d = iter t i
1083 where Iter c d = iter t i
1084{-# INLINE [1] takeWhile #-}
1084{-# INLINE [1] takeWhile #-}
1085
1085
@@ -1165,7 +1165,7 @@ splitAt n t@(Text arr off len)
1165 | n <= 0 = (empty, t)
1165 | n <= 0 = (empty, t)
1166 | n >= len = (t, empty)
1166 | n >= len = (t, empty)
1167 | otherwise = let k = iterN n t
1167 | otherwise = let k = iterN n t
1168− in (textP arr off k, textP arr (off+k) (len-k))
1168+ in (text arr off k, text arr (off+k) (len-k))
1169
1169
1170-- | /O(n)/ 'span', applied to a predicate @p@ and text @t@, returns
1170-- | /O(n)/ 'span', applied to a predicate @p@ and text @t@, returns
1171-- a pair whose first element is the longest prefix (possibly empty)
1171-- a pair whose first element is the longest prefix (possibly empty)
@@ -1188,7 +1188,7 @@ groupBy p = loop
1188 where
1188 where
1189 loop t@(Text arr off len)
1189 loop t@(Text arr off len)
1190 | null t = []
1190 | null t = []
1191− | otherwise = textP arr off n : loop (textP arr (off+n) (len-n))
1191+ | otherwise = text arr off n : loop (text arr (off+n) (len-n))
1192 where Iter c d = iter t 0
1192 where Iter c d = iter t 0
1193 n = d + findAIndexOrEnd (not . p c) (Text arr (off+d) (len-d))
1193 n = d + findAIndexOrEnd (not . p c) (Text arr (off+d) (len-d))
1194
1194
@@ -1247,8 +1247,8 @@ splitOn pat@(Text _ _ l) src@(Text arr off len)
1247 | isSingleton pat = split (== unsafeHead pat) src
1247 | isSingleton pat = split (== unsafeHead pat) src
1248 | otherwise = go 0 (indices pat src)
1248 | otherwise = go 0 (indices pat src)
1249 where
1249 where
1250− go !s (x:xs) = textP arr (s+off) (x-s) : go (x+l) xs
1250+ go !s (x:xs) = text arr (s+off) (x-s) : go (x+l) xs
1251− go s _ = [textP arr (s+off) (len-s)]
1251+ go s _ = [text arr (s+off) (len-s)]
1252{-# INLINE [1] splitOn #-}
1252{-# INLINE [1] splitOn #-}
1253
1253
1254{-# RULES
1254{-# RULES
@@ -1340,7 +1340,7 @@ breakOn pat src@(Text arr off len)
1340 | null pat = emptyError "breakOn"
1340 | null pat = emptyError "breakOn"
1341 | otherwise = case indices pat src of
1341 | otherwise = case indices pat src of
1342 [] -> (src, empty)
1342 [] -> (src, empty)
1343− (x:_) -> (textP arr off x, textP arr (off+x) (len-x))
1343+ (x:_) -> (text arr off x, text arr (off+x) (len-x))
1344{-# INLINE breakOn #-}
1344{-# INLINE breakOn #-}
1345
1345
1346-- | /O(n+m)/ Similar to 'breakOn', but searches from the end of the
1346-- | /O(n+m)/ Similar to 'breakOn', but searches from the end of the
@@ -1382,7 +1382,7 @@ breakOnAll pat src@(Text arr off slen)
1382 | otherwise = L.map step (indices pat src)
1382 | otherwise = L.map step (indices pat src)
1383 where
1383 where
1384 step x = (chunk 0 x, chunk x (slen-x))
1384 step x = (chunk 0 x, chunk x (slen-x))
1385− chunk !n !l = textP arr (n+off) l
1385+ chunk !n !l = text arr (n+off) l
1386{-# INLINE breakOnAll #-}
1386{-# INLINE breakOnAll #-}
1387
1387
1388-------------------------------------------------------------------------------
1388-------------------------------------------------------------------------------
@@ -1582,7 +1582,7 @@ isInfixOf needle haystack
1582-- > fnordLength _ = -1
1582-- > fnordLength _ = -1
1583stripPrefix :: Text -> Text -> Maybe Text
1583stripPrefix :: Text -> Text -> Maybe Text
1584stripPrefix p@(Text _arr _off plen) t@(Text arr off len)
1584stripPrefix p@(Text _arr _off plen) t@(Text arr off len)
1585− | p `isPrefixOf` t = Just $! textP arr (off+plen) (len-plen)
1585+ | p `isPrefixOf` t = Just $! text arr (off+plen) (len-plen)
1586 | otherwise = Nothing
1586 | otherwise = Nothing
1587
1587
1588-- | /O(n)/ Find the longest non-empty common prefix of two strings
1588-- | /O(n)/ Find the longest non-empty common prefix of two strings
@@ -1602,8 +1602,8 @@ commonPrefixes t0@(Text arr0 off0 len0) t1@(Text arr1 off1 len1) = go 0 0
1602 where
1602 where
1603 go !i !j | i < len0 && j < len1 && a == b = go (i+d0) (j+d1)
1603 go !i !j | i < len0 && j < len1 && a == b = go (i+d0) (j+d1)
1604 | i > 0 = Just (Text arr0 off0 i,
1604 | i > 0 = Just (Text arr0 off0 i,
1605− textP arr0 (off0+i) (len0-i),
1605+ text arr0 (off0+i) (len0-i),
1606− textP arr1 (off1+j) (len1-j))
1606+ text arr1 (off1+j) (len1-j))
1607 | otherwise = Nothing
1607 | otherwise = Nothing
1608 where Iter a d0 = iter t0 i
1608 where Iter a d0 = iter t0 i
1609 Iter b d1 = iter t1 j
1609 Iter b d1 = iter t1 j
@@ -1628,7 +1628,7 @@ commonPrefixes t0@(Text arr0 off0 len0) t1@(Text arr1 off1 len1) = go 0 0
1628-- > quuxLength _ = -1
1628-- > quuxLength _ = -1
1629stripSuffix :: Text -> Text -> Maybe Text
1629stripSuffix :: Text -> Text -> Maybe Text
1630stripSuffix p@(Text _arr _off plen) t@(Text arr off len)
1630stripSuffix p@(Text _arr _off plen) t@(Text arr off len)
1631− | p `isSuffixOf` t = Just $! textP arr off (len-plen)
1631+ | p `isSuffixOf` t = Just $! text arr off (len-plen)
1632 | otherwise = Nothing
1632 | otherwise = Nothing
1633
1633
1634-- | Add a list of non-negative numbers. Errors out on overflow.
1634-- | Add a list of non-negative numbers. Errors out on overflow.
Data/Text/Encoding.hs+3−3
@@ -86,7 +86,7 @@ import Data.ByteString as B
86import Data.ByteString.Internal as B hiding (c2w)
86import Data.ByteString.Internal as B hiding (c2w)
87import Data.Text ()
87import Data.Text ()
88import Data.Text.Encoding.Error (OnDecodeError, UnicodeException, strictDecode)
88import Data.Text.Encoding.Error (OnDecodeError, UnicodeException, strictDecode)
89−import Data.Text.Internal (Text(..), safe, textP)
89+import Data.Text.Internal (Text(..), safe, text)
90import Data.Text.Internal.Private (runText)
90import Data.Text.Internal.Private (runText)
91import Data.Text.Internal.Unsafe.Char (unsafeWrite)
91import Data.Text.Internal.Unsafe.Char (unsafeWrite)
92import Data.Text.Internal.Unsafe.Shift (shiftR)
92import Data.Text.Internal.Unsafe.Shift (shiftR)
@@ -130,7 +130,7 @@ decodeASCII = decodeUtf8
130-- 'decodeLatin1' is semantically equivalent to
130-- 'decodeLatin1' is semantically equivalent to
131-- @Data.Text.pack . Data.ByteString.Char8.unpack@
131-- @Data.Text.pack . Data.ByteString.Char8.unpack@
132decodeLatin1 :: ByteString -> Text
132decodeLatin1 :: ByteString -> Text
133−decodeLatin1 (PS fp off len) = textP a 0 len
133+decodeLatin1 (PS fp off len) = text a 0 len
134 where
134 where
135 a = A.run (A.new len >>= unsafeIOToST . go)
135 a = A.run (A.new len >>= unsafeIOToST . go)
136 go dest = withForeignPtr fp $ \ptr -> do
136 go dest = withForeignPtr fp $ \ptr -> do
@@ -285,7 +285,7 @@ streamDecodeUtf8With onErr = decodeChunk B.empty 0 0
285 codepoint <- peek codepointPtr
285 codepoint <- peek codepointPtr
286 chunkText <- unsafeSTToIO $ do
286 chunkText <- unsafeSTToIO $ do
287 arr <- A.unsafeFreeze dest
287 arr <- A.unsafeFreeze dest
288− return $! textP arr 0 (fromIntegral n)
288+ return $! text arr 0 (fromIntegral n)
289 lastPtr <- peek curPtrPtr
289 lastPtr <- peek curPtrPtr
290 let left = lastPtr `minusPtr` curPtr
290 let left = lastPtr `minusPtr` curPtr
291 undecoded = case state of
291 undecoded = case state of
Data/Text/Internal.hs+10−6
@@ -54,8 +54,8 @@ data Text = Text
54 deriving (Typeable)
54 deriving (Typeable)
55
55
56-- | Smart constructor.
56-- | Smart constructor.
57−text :: A.Array -> Int -> Int -> Text
57+text_ :: A.Array -> Int -> Int -> Text
58−text arr off len =
58+text_ arr off len =
59#if defined(ASSERTS)
59#if defined(ASSERTS)
60 let c = A.unsafeIndex arr off
60 let c = A.unsafeIndex arr off
61 alen = A.length arr
61 alen = A.length arr
@@ -65,7 +65,7 @@ text arr off len =
65 assert (len == 0 || c < 0xDC00 || c > 0xDFFF) $
65 assert (len == 0 || c < 0xDC00 || c > 0xDFFF) $
66#endif
66#endif
67 Text arr off len
67 Text arr off len
68−{-# INLINE text #-}
68+{-# INLINE text_ #-}
69
69
70-- | /O(1)/ The empty 'Text'.
70-- | /O(1)/ The empty 'Text'.
71empty :: Text
71empty :: Text
@@ -74,10 +74,14 @@ empty = Text A.empty 0 0
74
74
75-- | Construct a 'Text' without invisibly pinning its byte array in
75-- | Construct a 'Text' without invisibly pinning its byte array in
76-- memory if its length has dwindled to zero.
76-- memory if its length has dwindled to zero.
77−textP :: A.Array -> Int -> Int -> Text
77+text :: A.Array -> Int -> Int -> Text
78−textP arr off len | len == 0 = empty
78+text arr off len | len == 0 = empty
79 | otherwise = text arr off len
79 | otherwise = text arr off len
80−{-# INLINE textP #-}
80+{-# INLINE text #-}
81+
82+textP :: A.Array -> Int -> Int -> Text
83+{-# DEPRECATED textP "Use text instead" #-}
84+textP = text
81
85
82-- | A useful 'show'-like function for debugging purposes.
86-- | A useful 'show'-like function for debugging purposes.
83showText :: Text -> String
87showText :: Text -> String
Data/Text/Internal/Fusion.hs+2−2
@@ -132,7 +132,7 @@ length = S.lengthI
132reverse :: Stream Char -> Text
132reverse :: Stream Char -> Text
133reverse (Stream next s len0)
133reverse (Stream next s len0)
134 | isEmpty len0 = I.empty
134 | isEmpty len0 = I.empty
135− | otherwise = I.textP arr off' len'
135+ | otherwise = I.text arr off' len'
136 where
136 where
137 len0' = upperBound 4 (larger len0 4)
137 len0' = upperBound 4 (larger len0 4)
138 (arr, (off', len')) = A.run2 (A.new len0' >>= loop s (len0'-1) len0')
138 (arr, (off', len')) = A.run2 (A.new len0' >>= loop s (len0'-1) len0')
@@ -210,7 +210,7 @@ countChar = S.countCharI
210-- function to each element of a 'Text', passing an accumulating
210-- function to each element of a 'Text', passing an accumulating
211-- parameter from left to right, and returns a final 'Text'.
211-- parameter from left to right, and returns a final 'Text'.
212mapAccumL :: (a -> Char -> (a,Char)) -> a -> Stream Char -> (a, Text)
212mapAccumL :: (a -> Char -> (a,Char)) -> a -> Stream Char -> (a, Text)
213−mapAccumL f z0 (Stream next0 s0 len) = (nz,I.textP na 0 nl)
213+mapAccumL f z0 (Stream next0 s0 len) = (nz, I.text na 0 nl)
214 where
214 where
215 (na,(nz,nl)) = A.run2 (A.new mlen >>= \arr -> outer arr mlen z0 s0 0)
215 (na,(nz,nl)) = A.run2 (A.new mlen >>= \arr -> outer arr mlen z0 s0 0)
216 where mlen = upperBound 4 len
216 where mlen = upperBound 4 len
Data/Text/Internal/Private.hs+4−4
@@ -16,14 +16,14 @@ module Data.Text.Internal.Private
16 ) where
16 ) where
17
17
18import Control.Monad.ST (ST, runST)
18import Control.Monad.ST (ST, runST)
19−import Data.Text.Internal (Text(..), textP)
19+import Data.Text.Internal (Text(..), text)
20import Data.Text.Unsafe (Iter(..), iter)
20import Data.Text.Unsafe (Iter(..), iter)
21import qualified Data.Text.Array as A
21import qualified Data.Text.Array as A
22
22
23span_ :: (Char -> Bool) -> Text -> (# Text, Text #)
23span_ :: (Char -> Bool) -> Text -> (# Text, Text #)
24span_ p t@(Text arr off len) = (# hd,tl #)
24span_ p t@(Text arr off len) = (# hd,tl #)
25− where hd = textP arr off k
25+ where hd = text arr off k
26− tl = textP arr (off+k) (len-k)
26+ tl = text arr (off+k) (len-k)
27 !k = loop 0
27 !k = loop 0
28 loop !i | i < len && p c = loop (i+d)
28 loop !i | i < len && p c = loop (i+d)
29 | otherwise = i
29 | otherwise = i
@@ -33,5 +33,5 @@ span_ p t@(Text arr off len) = (# hd,tl #)
33runText :: (forall s. (A.MArray s -> Int -> ST s Text) -> ST s Text) -> Text
33runText :: (forall s. (A.MArray s -> Int -> ST s Text) -> ST s Text) -> Text
34runText act = runST (act $ \ !marr !len -> do
34runText act = runST (act $ \ !marr !len -> do
35 arr <- A.unsafeFreeze marr
35 arr <- A.unsafeFreeze marr
36− return $! textP arr 0 len)
36+ return $! text arr 0 len)
37{-# INLINE runText #-}
37{-# INLINE runText #-}
Data/Text/Lazy.hs+4−4
@@ -215,7 +215,7 @@ import qualified Data.Text.Internal.Lazy.Fusion as S
215import Data.Text.Internal.Fusion.Types (PairS(..))
215import Data.Text.Internal.Fusion.Types (PairS(..))
216import Data.Text.Internal.Lazy.Fusion (stream, unstream)
216import Data.Text.Internal.Lazy.Fusion (stream, unstream)
217import Data.Text.Internal.Lazy (Text(..), chunk, empty, foldlChunks, foldrChunks)
217import Data.Text.Internal.Lazy (Text(..), chunk, empty, foldlChunks, foldrChunks)
218−import Data.Text.Internal (firstf, safe, textP)
218+import Data.Text.Internal (firstf, safe, text)
219import qualified Data.Text.Internal.Functions as F
219import qualified Data.Text.Internal.Functions as F
220import Data.Text.Internal.Lazy.Search (indices)
220import Data.Text.Internal.Lazy.Search (indices)
221#if __GLASGOW_HASKELL__ >= 702
221#if __GLASGOW_HASKELL__ >= 702
@@ -1002,7 +1002,7 @@ dropWords i t0
1002 where drop' 0 ts = ts
1002 where drop' 0 ts = ts
1003 drop' _ Empty = Empty
1003 drop' _ Empty = Empty
1004 drop' n (Chunk (T.Text arr off len) ts)
1004 drop' n (Chunk (T.Text arr off len) ts)
1005− | n < len' = chunk (textP arr (off+n') (len-n')) ts
1005+ | n < len' = chunk (text arr (off+n') (len-n')) ts
1006 | otherwise = drop' (n - len') ts
1006 | otherwise = drop' (n - len') ts
1007 where len' = fromIntegral len
1007 where len' = fromIntegral len
1008 n' = fromIntegral n
1008 n' = fromIntegral n
@@ -1113,8 +1113,8 @@ splitAtWord _ Empty = empty :*: empty
1113splitAtWord x (Chunk c@(T.Text arr off len) cs)
1113splitAtWord x (Chunk c@(T.Text arr off len) cs)
1114 | y >= len = let h :*: t = splitAtWord (x-fromIntegral len) cs
1114 | y >= len = let h :*: t = splitAtWord (x-fromIntegral len) cs
1115 in Chunk c h :*: t
1115 in Chunk c h :*: t
1116− | otherwise = chunk (textP arr off y) empty :*:
1116+ | otherwise = chunk (text arr off y) empty :*:
1117− chunk (textP arr (off+y) (len-y)) cs
1117+ chunk (text arr (off+y) (len-y)) cs
1118 where y = fromIntegral x
1118 where y = fromIntegral x
1119
1119
1120-- | /O(n+m)/ Find the first instance of @needle@ (which must be
1120-- | /O(n+m)/ Find the first instance of @needle@ (which must be