utf8-string-1.0.2: Support for reading and writing UTF8 Strings

Copyright | (c) Iavor S. Diatchki 2009
License | BSD3-style (see LICENSE)
Maintainer | emertens@galois.com
Stability | experimental
Portability | portable 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.
Safe Haskell | Trustworthy
Language | Haskell2010

Data.ByteString.UTF8

Description

Synopsis

- 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)
- fromChar :: Char -> 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 Source #

A space-efficient representation of a `Word8` vector, supporting many efficient operations.

A `ByteString` contains 8-bit bytes, or by using the operations from Data.ByteString.Char8 it can be interpreted as containing 8-bit characters.

#### Instances

Instances details

NFData ByteString |
Instance details Defined in Data.ByteString.Internal.Type Methods rnf :: ByteString -> () Source #
Monoid ByteString |
Instance details Defined in Data.ByteString.Internal.Type Methods mempty :: ByteString Source # mappend :: ByteString -> ByteString -> ByteString Source # mconcat :: [ByteString] -> ByteString Source #
Semigroup ByteString |
Instance details Defined in Data.ByteString.Internal.Type Methods (<>) :: ByteString -> ByteString -> ByteString Source # sconcat :: NonEmpty ByteString -> ByteString Source # stimes :: Integral b => b -> ByteString -> ByteString Source #
Data ByteString |

Instance details

Defined in Data.ByteString.Internal.Type

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ByteString -> c ByteString Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ByteString Source #

toConstr :: ByteString -> Constr Source #

dataTypeOf :: ByteString -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ByteString) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ByteString) Source #

gmapT :: (forall b. Data b => b -> b) -> ByteString -> ByteString Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ByteString -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ByteString -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> ByteString -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> ByteString -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> ByteString -> m ByteString Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteString -> m ByteString Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteString -> m ByteString Source #

IsString ByteString | Beware: `fromString` truncates multi-byte characters to octets. e.g. "枯朶に烏のとまりけり秋の暮" becomes �6k�nh~�Q��n�
Instance details Defined in Data.ByteString.Internal.Type Methods fromString :: String -> ByteString Source #
IsList ByteString | Since: bytestring-0.10.12.0

Instance details

Defined in Data.ByteString.Internal.Type

Associated Types

type Item ByteString |
Instance details Defined in Data.ByteString.Internal.Type type Item ByteString = Word8

Methods

fromList :: [Item ByteString] -> ByteString Source #

fromListN :: Int -> [Item ByteString] -> ByteString Source #

toList :: ByteString -> [Item ByteString] Source #

Read ByteString |
Instance details Defined in Data.ByteString.Internal.Type Methods readsPrec :: Int -> ReadS ByteString Source # readList :: ReadS [ByteString] Source # readPrec :: ReadPrec ByteString Source # readListPrec :: ReadPrec [ByteString] Source #
Show ByteString |
Instance details Defined in Data.ByteString.Internal.Type Methods showsPrec :: Int -> ByteString -> ShowS Source # show :: ByteString -> String Source # showList :: [ByteString] -> ShowS Source #
Eq ByteString |
Instance details Defined in Data.ByteString.Internal.Type Methods (==) :: ByteString -> ByteString -> Bool Source # (/=) :: ByteString -> ByteString -> Bool Source #
Ord ByteString |

Instance details

Defined in Data.ByteString.Internal.Type

Methods

compare :: ByteString -> ByteString -> Ordering Source #

(<) :: ByteString -> ByteString -> Bool Source #

(<=) :: ByteString -> ByteString -> Bool Source #

(>) :: ByteString -> ByteString -> Bool Source #

(>=) :: ByteString -> ByteString -> Bool Source #

max :: ByteString -> ByteString -> ByteString Source #

min :: ByteString -> ByteString -> ByteString Source #

Lift ByteString | Since: bytestring-0.11.2.0
Instance details Defined in Data.ByteString.Internal.Type Methods lift :: Quote m => ByteString -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => ByteString -> Code m ByteString Source #
UTF8Bytes ByteString Int Source # |

Instance details

Defined in Codec.Binary.UTF8.Generic

Methods

bsplit :: Int -> ByteString -> (ByteString, ByteString) Source #

bdrop :: Int -> ByteString -> ByteString Source #

buncons :: ByteString -> Maybe (Word8, ByteString) Source #

elemIndex :: Word8 -> ByteString -> Maybe Int Source #

empty :: ByteString Source #

null :: ByteString -> Bool Source #

pack :: [Word8] -> ByteString Source #

tail :: ByteString -> ByteString Source #

type Item ByteString |
Instance details Defined in Data.ByteString.Internal.Type type Item ByteString = Word8

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 :: Char Source #

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 -> ByteString Source #

`take n s` returns the first `n` characters of `s`. If `s` has less than `n` characters, then we return the whole of `s`.

drop :: Int -> ByteString -> ByteString Source #

`drop n s` returns the `s` without its first `n` characters. If `s` has less than `n` characters, then we return 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.

fromChar :: Char -> ByteString Source #

Converts a Haskell char into a UTF8 encoded bytestring.

fromString :: String -> ByteString Source #

Converts a Haskell string into a UTF8 encoded bytestring.

toString :: ByteString -> String Source #

Convert a UTF8 encoded bytestring into a Haskell string. Invalid characters are replaced with `'\0xFFFD'`.

foldl :: (a -> Char -> a) -> a -> ByteString -> a Source #

Traverse a bytestring (left biased). This function is strict in the accumulator.

foldr :: (Char -> a -> a) -> a -> ByteString -> a Source #

Traverse a bytestring (right biased).

length :: ByteString -> Int Source #

Counts the number of characters encoded in the bytestring. Note that this includes replacement characters.

lines :: ByteString -> [ByteString] Source #

Split a string into a list of lines. Lines are terminated by `'\n'` or the end of the string. Empty lines 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 terminated by `'\n'` or the end of the string. Empty lines may not be terminated by the end of the string. This function preserves the terminators. See also `lines`.