This module provides fast, validated encoding and decoding functions
between ByteString
s and String
s. It does not exactly match the
output of the Codec.Binary.UTF8.String output for invalid encodings
as the number of replacement characters is sometimes longer.
- data ByteString
- decode :: ByteString -> Maybe (Char, Int)
- replacement_char :: Char
- uncons :: ByteString -> Maybe (Char, ByteString)
- splitAt :: Int -> ByteString -> (ByteString, ByteString)
- take :: Int -> ByteString -> ByteString
- drop :: Int -> ByteString -> ByteString
- span :: (Char -> Bool) -> ByteString -> (ByteString, ByteString)
- break :: (Char -> Bool) -> ByteString -> (ByteString, ByteString)
- fromString :: String -> ByteString
- toString :: ByteString -> String
- foldl :: (a -> Char -> a) -> a -> ByteString -> a
- foldr :: (Char -> a -> a) -> a -> ByteString -> a
- length :: ByteString -> Int
- lines :: ByteString -> [ByteString]
- lines' :: ByteString -> [ByteString]
Documentation
data ByteString
A space-efficient representation of a Word8 vector, supporting many
efficient operations. A ByteString
contains 8-bit characters only.
Instances of Eq, Ord, Read, Show, Data, Typeable
decode :: ByteString -> Maybe (Char, Int)Source
Try to extract a character from a byte string.
Returns Nothing
if there are no more bytes in the byte string.
Otherwise, it returns a decoded character and the number of
bytes used in its representation.
Errors are replaced by character '\0xFFFD'.
replacement_char :: CharSource
This character is used to mark errors in a UTF8 encoded string.
uncons :: ByteString -> Maybe (Char, ByteString)Source
Get the first character of a byte string, if any. Malformed characters are replaced by '\0xFFFD'.
splitAt :: Int -> ByteString -> (ByteString, ByteString)Source
Split after a given number of characters. Negative values are treated as if they are 0.
take :: Int -> ByteString -> ByteStringSource
take n s
returns the first n
characters of s
.
If s
has less then n
characters, then we return the whole of s
.
drop :: Int -> ByteString -> ByteStringSource
drop n s
returns the s
without its first n
characters.
If s
has less then n
characters, then we return the an empty string.
span :: (Char -> Bool) -> ByteString -> (ByteString, ByteString)Source
Split a string into two parts: the first is the longest prefix that contains only characters that satisfy the predicate; the second part is the rest of the string. Invalid characters are passed as '\0xFFFD' to the predicate.
break :: (Char -> Bool) -> ByteString -> (ByteString, ByteString)Source
Split a string into two parts: the first is the longest prefix that contains only characters that do not satisfy the predicate; the second part is the rest of the string. Invalid characters are passed as '\0xFFFD' to the predicate.
fromString :: String -> ByteStringSource
Converts a Haskell string into a UTF8 encoded bytestring.
toString :: ByteString -> StringSource
Convert a UTF8 encoded bytestring into a Haskell string. Invalid characters are replaced with '\xFFFD'.
foldl :: (a -> Char -> a) -> a -> ByteString -> aSource
Traverse a bytestring (left biased). This fuction is strict in the acumulator.
foldr :: (Char -> a -> a) -> a -> ByteString -> aSource
Traverse a bytestring (right biased).
length :: ByteString -> IntSource
Counts the number of characters encoded in the bytestring. Note that this includes replacment characters.
lines :: ByteString -> [ByteString]Source
Split a string into a list of lines. Lines are termianted by '\n' or the end of the string. Empty line may not be terminated by the end of the string. See also 'lines\''.
lines' :: ByteString -> [ByteString]Source
Split a string into a list of lines.
Lines are termianted by '\n' or the end of the string.
Empty line may not be terminated by the end of the string.
This function preserves the terminators.
See also lines
.