1{-# LANGUAGE DeriveDataTypeable #-}
4-- Module : Data.Text.Internal
5-- Copyright : (c) Tom Harper 2008-2009,
6-- (c) Bryan O'Sullivan 2009,
7-- (c) Duncan Coutts 2009
10-- Maintainer : bos@serpentine.com, rtharper@aftereternity.co.uk,
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
31import Control.Exception (assert)
32import qualified Data.Text.Array as A
33import Data.Typeable (Typeable)
34import Data.Word (Word16)
36-- | A space efficient, packed, unboxed Unicode text type.
38 {-# UNPACK #-} !(A.Array Word16) -- payload
39 {-# UNPACK #-} !Int -- offset
40 {-# UNPACK #-} !Int -- length
43-- | Smart constructor.
44text :: A.Array Word16 -> Int -> Int -> Text
48 assert (alen == 0 || len == 0 || off < alen) .
49 assert (len == 0 || c < 0xDC00 || c > 0xDFFF) $
51 where c = A.unsafeIndex arr off
55-- | /O(1)/ The empty 'Text'.
57empty = Text A.empty 0 0
58{-# INLINE [1] empty #-}
60-- | Construct a 'Text' without invisibly pinning its byte array in
61-- memory if its length has dwindled to zero.
62textP :: A.Array Word16 -> Int -> Int -> Text
63textP arr off len | len == 0 = empty
64 | otherwise = text arr off len
67-- | A useful 'show'-like function for debugging purposes.
68showText :: Text -> String
69showText (Text arr off len) =
70 "Text " ++ (show . take (off+len) . A.toList) arr ++ ' ' :
71 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