{-# LANGUAGE MagicHash, NoImplicitPrelude, BangPatterns #-}
module GHC.CString (
unpackCString#, unpackAppendCString#, unpackFoldrCString#,
unpackCStringUtf8#, unpackNBytes#
) where
import GHC.Types
import GHC.Prim
unpackCString# :: Addr# -> [Char]
{-# NOINLINE CONLIKE unpackCString# #-}
unpackCString# :: Addr# -> [Char]
unpackCString# Addr#
addr
= Int# -> [Char]
unpack Int#
0#
where
unpack :: Int# -> [Char]
unpack Int#
nh
| Int# -> Bool
isTrue# (Char#
ch Char# -> Char# -> Int#
`eqChar#` Char#
'\0'#) = []
| Bool
True = Char# -> Char
C# Char#
ch Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
: Int# -> [Char]
unpack (Int#
nh Int# -> Int# -> Int#
+# Int#
1#)
where
!ch :: Char#
ch = Addr# -> Int# -> Char#
indexCharOffAddr# Addr#
addr Int#
nh
unpackAppendCString# :: Addr# -> [Char] -> [Char]
{-# NOINLINE unpackAppendCString# #-}
unpackAppendCString# :: Addr# -> [Char] -> [Char]
unpackAppendCString# Addr#
addr [Char]
rest
= Int# -> [Char]
unpack Int#
0#
where
unpack :: Int# -> [Char]
unpack Int#
nh
| Int# -> Bool
isTrue# (Char#
ch Char# -> Char# -> Int#
`eqChar#` Char#
'\0'#) = [Char]
rest
| Bool
True = Char# -> Char
C# Char#
ch Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
: Int# -> [Char]
unpack (Int#
nh Int# -> Int# -> Int#
+# Int#
1#)
where
!ch :: Char#
ch = Addr# -> Int# -> Char#
indexCharOffAddr# Addr#
addr Int#
nh
unpackFoldrCString# :: Addr# -> (Char -> a -> a) -> a -> a
{-# NOINLINE unpackFoldrCString# #-}
unpackFoldrCString# :: Addr# -> (Char -> a -> a) -> a -> a
unpackFoldrCString# Addr#
addr Char -> a -> a
f a
z
= Int# -> a
unpack Int#
0#
where
unpack :: Int# -> a
unpack Int#
nh
| Int# -> Bool
isTrue# (Char#
ch Char# -> Char# -> Int#
`eqChar#` Char#
'\0'#) = a
z
| Bool
True = Char# -> Char
C# Char#
ch Char -> a -> a
`f` Int# -> a
unpack (Int#
nh Int# -> Int# -> Int#
+# Int#
1#)
where
!ch :: Char#
ch = Addr# -> Int# -> Char#
indexCharOffAddr# Addr#
addr Int#
nh
unpackCStringUtf8# :: Addr# -> [Char]
{-# NOINLINE CONLIKE unpackCStringUtf8# #-}
unpackCStringUtf8# :: Addr# -> [Char]
unpackCStringUtf8# Addr#
addr
= Int# -> [Char]
unpack Int#
0#
where
unpack :: Int# -> [Char]
unpack Int#
nh
| Int# -> Bool
isTrue# (Char#
ch Char# -> Char# -> Int#
`eqChar#` Char#
'\0'# ) = []
| Int# -> Bool
isTrue# (Char#
ch Char# -> Char# -> Int#
`leChar#` Char#
'\x7F'#) = Char# -> Char
C# Char#
ch Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
: Int# -> [Char]
unpack (Int#
nh Int# -> Int# -> Int#
+# Int#
1#)
| Int# -> Bool
isTrue# (Char#
ch Char# -> Char# -> Int#
`leChar#` Char#
'\xDF'#) =
let !c :: Char
c = Char# -> Char
C# (Int# -> Char#
chr# (((Char# -> Int#
ord# Char#
ch Int# -> Int# -> Int#
-# Int#
0xC0#) Int# -> Int# -> Int#
`uncheckedIShiftL#` Int#
6#) Int# -> Int# -> Int#
+#
(Char# -> Int#
ord# (Addr# -> Int# -> Char#
indexCharOffAddr# Addr#
addr (Int#
nh Int# -> Int# -> Int#
+# Int#
1#)) Int# -> Int# -> Int#
-# Int#
0x80#)))
in Char
c Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
: Int# -> [Char]
unpack (Int#
nh Int# -> Int# -> Int#
+# Int#
2#)
| Int# -> Bool
isTrue# (Char#
ch Char# -> Char# -> Int#
`leChar#` Char#
'\xEF'#) =
let !c :: Char
c = Char# -> Char
C# (Int# -> Char#
chr# (((Char# -> Int#
ord# Char#
ch Int# -> Int# -> Int#
-# Int#
0xE0#) Int# -> Int# -> Int#
`uncheckedIShiftL#` Int#
12#) Int# -> Int# -> Int#
+#
((Char# -> Int#
ord# (Addr# -> Int# -> Char#
indexCharOffAddr# Addr#
addr (Int#
nh Int# -> Int# -> Int#
+# Int#
1#)) Int# -> Int# -> Int#
-# Int#
0x80#) Int# -> Int# -> Int#
`uncheckedIShiftL#` Int#
6#) Int# -> Int# -> Int#
+#
(Char# -> Int#
ord# (Addr# -> Int# -> Char#
indexCharOffAddr# Addr#
addr (Int#
nh Int# -> Int# -> Int#
+# Int#
2#)) Int# -> Int# -> Int#
-# Int#
0x80#)))
in Char
c Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
: Int# -> [Char]
unpack (Int#
nh Int# -> Int# -> Int#
+# Int#
3#)
| Bool
True =
let !c :: Char
c = Char# -> Char
C# (Int# -> Char#
chr# (((Char# -> Int#
ord# Char#
ch Int# -> Int# -> Int#
-# Int#
0xF0#) Int# -> Int# -> Int#
`uncheckedIShiftL#` Int#
18#) Int# -> Int# -> Int#
+#
((Char# -> Int#
ord# (Addr# -> Int# -> Char#
indexCharOffAddr# Addr#
addr (Int#
nh Int# -> Int# -> Int#
+# Int#
1#)) Int# -> Int# -> Int#
-# Int#
0x80#) Int# -> Int# -> Int#
`uncheckedIShiftL#` Int#
12#) Int# -> Int# -> Int#
+#
((Char# -> Int#
ord# (Addr# -> Int# -> Char#
indexCharOffAddr# Addr#
addr (Int#
nh Int# -> Int# -> Int#
+# Int#
2#)) Int# -> Int# -> Int#
-# Int#
0x80#) Int# -> Int# -> Int#
`uncheckedIShiftL#` Int#
6#) Int# -> Int# -> Int#
+#
(Char# -> Int#
ord# (Addr# -> Int# -> Char#
indexCharOffAddr# Addr#
addr (Int#
nh Int# -> Int# -> Int#
+# Int#
3#)) Int# -> Int# -> Int#
-# Int#
0x80#)))
in Char
c Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
: Int# -> [Char]
unpack (Int#
nh Int# -> Int# -> Int#
+# Int#
4#)
where
!ch :: Char#
ch = Addr# -> Int# -> Char#
indexCharOffAddr# Addr#
addr Int#
nh
unpackNBytes# :: Addr# -> Int# -> [Char]
{-# NOINLINE unpackNBytes# #-}
unpackNBytes# :: Addr# -> Int# -> [Char]
unpackNBytes# Addr#
_addr Int#
0# = []
unpackNBytes# Addr#
addr Int#
len# = [Char] -> Int# -> [Char]
unpack [] (Int#
len# Int# -> Int# -> Int#
-# Int#
1#)
where
unpack :: [Char] -> Int# -> [Char]
unpack [Char]
acc Int#
i#
| Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
<# Int#
0#) = [Char]
acc
| Bool
True =
case Addr# -> Int# -> Char#
indexCharOffAddr# Addr#
addr Int#
i# of
Char#
ch -> [Char] -> Int# -> [Char]
unpack (Char# -> Char
C# Char#
ch Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
: [Char]
acc) (Int#
i# Int# -> Int# -> Int#
-# Int#
1#)