File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ License : NCSA
6
6
module Kore.Builtin.Encoding
7
7
( encode8Bit
8
8
, decode8Bit
9
+ , parse8Bit
9
10
, parseBase16
10
11
, toBase16
11
12
) where
@@ -33,6 +34,7 @@ import Data.Word
33
34
)
34
35
import Text.Megaparsec
35
36
( Parsec
37
+ , (<?>)
36
38
)
37
39
import qualified Text.Megaparsec as Parsec
38
40
@@ -62,6 +64,23 @@ encode8Bit =
62
64
, show int
63
65
]
64
66
67
+ {- | Encode text using an 8-bit encoding.
68
+
69
+ Each 'Char' in the text is interpreted as a 'Data.Word.Word8'. It is an error if
70
+ any character falls outside that representable range.
71
+
72
+ -}
73
+ parse8Bit :: Parsec Void Text ByteString
74
+ parse8Bit =
75
+ ByteString. pack <$> many parseByte
76
+ where
77
+ parseByte :: Parsec Void Text Word8
78
+ parseByte =
79
+ fromIntegral . Char. ord <$> Parsec. satisfy is8Bit <?> " 8-bit value"
80
+
81
+ is8Bit :: Char -> Bool
82
+ is8Bit c = c < ' \x100 '
83
+
65
84
decode8Bit :: ByteString -> Text
66
85
decode8Bit =
67
86
ByteString. unpack
You can’t perform that action at this time.
0 commit comments