1{-# LANGUAGE CPP, DeriveDataTypeable #-}
4-- Module : Data.Text.Internal
5-- Copyright : (c) 2008, 2009 Tom Harper,
6-- (c) 2009, 2010 Bryan O'Sullivan,
7-- (c) 2009 Duncan Coutts
10-- Maintainer : bos@serpentine.com, rtomharper@googlemail.com,
12-- Stability : experimental
15-- Semi-public internals. Most users should not need to use this
18module Data.Text.Internal
25 -- * Code that must be here for accessibility
32import Control.Exception (assert)
34import qualified Data.Text.Array as A
35import Data.Typeable (Typeable)
37-- | A space efficient, packed, unboxed Unicode text type.
39 {-# UNPACK #-} !A.Array -- payload
40 {-# UNPACK #-} !Int -- offset
41 {-# UNPACK #-} !Int -- length
44-- | Smart constructor.
45text :: A.Array -> Int -> Int -> Text
48 let c = A.unsafeIndex arr off
50 in assert (len >= 0) .
52 assert (alen == 0 || len == 0 || off < alen) .
53 assert (len == 0 || c < 0xDC00 || c > 0xDFFF) $
58-- | /O(1)/ The empty 'Text'.
60empty = Text A.empty 0 0
61{-# INLINE [1] empty #-}
63-- | Construct a 'Text' without invisibly pinning its byte array in
64-- memory if its length has dwindled to zero.
65textP :: A.Array -> Int -> Int -> Text
66textP arr off len | len == 0 = empty
67 | otherwise = text arr off len
70-- | A useful 'show'-like function for debugging purposes.
71showText :: Text -> String
72showText (Text arr off len) =
73 "Text " ++ show (A.toList arr off len) ++ ' ' :
74 show off ++ ' ' : show len
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list