1{-# INCLUDE "cbits.h" #-}
2{-# LANGUAGE ForeignFunctionInterface, CPP #-}
16import Foreign.C.String
22import Prelude hiding (null)
24#if defined(__GLASGOW_HASKELL__)
25import GHC.Base (unsafeChr)
28newtype UUID = U C_UUID
33 (U a) == (U b) = c_compare a b == 0
35instance Ord UUID where
36 compare (U p1) (U p2) =
37 case c_compare p1 p2 of
42instance Show UUID where
51generateRandom :: IO UUID
57generateTime :: IO UUID
64null (U p) = c_null p /= 0
66fromString :: String -> Maybe UUID
67fromString s = unsafePerformIO $ do
69 chars <- mallocBytes 37
71 res <- c_read p (castPtr chars)
73 0 -> return . Just $ U p
76pack :: Int -> String -> Ptr Word8 -> IO ()
77pack 37 _ p = pokeByteOff p 37 (0 :: Word8)
79 pokeByteOff p n (c2w c)
81pack n [] p = pokeByteOff p n (0 :: Word8)
83unpack :: Ptr Word8 -> Int -> IO String
84unpack p 37 = return []
93toString :: UUID -> String
94toString (U p) = unsafePerformIO $ do
95 chars <- mallocBytes 37
97 unpack (castPtr chars) 0
99toStringLower :: UUID -> String
100toStringLower (U p) = unsafePerformIO $ do
101 chars <- mallocBytes 37
103 unpack (castPtr chars) 0
105toStringUpper :: UUID -> String
106toStringUpper (U p) = unsafePerformIO $ do
107 chars <- mallocBytes 37
109 unpack (castPtr chars) 0
111-- | Conversion between 'Word8' and 'Char'. Should compile to a no-op.
112-- Shamelessly stolen from the 'bytestring' package.
114#if !defined(__GLASGOW_HASKELL__)
115w2c = chr . fromIntegral
117w2c = unsafeChr . fromIntegral
121-- | Unsafe conversion between 'Char' and 'Word8'. This is a no-op and
122-- silently truncates to 8 bits Chars > '\255'. It is provided as
123-- convenience for ByteString construction.
124-- Shamelessly stolen from the 'bytestring' package.
126c2w = fromIntegral . ord
130foreign import ccall unsafe "c_compare"
131 c_compare :: C_UUID -> C_UUID -> CInt
133-- making random UUIDs
134foreign import ccall unsafe "c_generate"
135 c_generate :: C_UUID -> IO ()
137foreign import ccall unsafe "c_generate_time"
138 c_generate_time :: C_UUID -> IO ()
140foreign import ccall unsafe "c_generate_random"
141 c_generate_random :: C_UUID -> IO ()
144foreign import ccall unsafe "c_null"
145 c_null :: C_UUID -> CInt
149foreign import ccall unsafe "c_read"
150 c_read :: C_UUID -> CString ->IO CInt
154foreign import ccall unsafe "c_show"
155 c_show :: C_UUID -> CString -> IO ()
157foreign import ccall unsafe "c_show_lower"
158 c_show_lower :: C_UUID -> CString -> IO ()
160foreign import ccall unsafe "c_show_upper"
161 c_show_upper :: C_UUID -> CString -> IO ()
166foreign import ccall unsafe "c_type"
167 c_type :: C_UUID -> CInt
169foreign import ccall unsafe "c_variant"
170 c_variant :: C_UUID -> CInt
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