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
Safe Haskell | Trustworthy
Language | Haskell2010

Codec.Binary.UTF8.Generic

Description

Synopsis

- class (Num s, Ord s) => UTF8Bytes b s | b -> s where
  - bsplit :: s -> b -> (b, b)
  - bdrop :: s -> b -> b
  - buncons :: b -> Maybe (Word8, b)
  - elemIndex :: Word8 -> b -> Maybe s
  - empty :: b
  - null :: b -> Bool
  - pack :: [Word8] -> b
  - tail :: b -> b
- decode :: UTF8Bytes b s => b -> Maybe (Char, s)
- replacement_char :: Char
- uncons :: UTF8Bytes b s => b -> Maybe (Char, b)
- splitAt :: UTF8Bytes b s => s -> b -> (b, b)
- take :: UTF8Bytes b s => s -> b -> b
- drop :: UTF8Bytes b s => s -> b -> b
- span :: UTF8Bytes b s => (Char -> Bool) -> b -> (b, b)
- break :: UTF8Bytes b s => (Char -> Bool) -> b -> (b, b)
- fromString :: UTF8Bytes b s => String -> b
- toString :: UTF8Bytes b s => b -> String
- foldl :: UTF8Bytes b s => (a -> Char -> a) -> a -> b -> a
- foldr :: UTF8Bytes b s => (Char -> a -> a) -> a -> b -> a
- length :: UTF8Bytes b s => b -> s
- lines :: UTF8Bytes b s => b -> [b]
- lines' :: UTF8Bytes b s => b -> [b]

# Documentation

class (Num s, Ord s) => UTF8Bytes b s | b -> s where Source #

Methods

bsplit :: s -> b -> (b, b) Source #

bdrop :: s -> b -> b Source #

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

elemIndex :: Word8 -> b -> Maybe s Source #

empty :: b Source #

null :: b -> Bool Source #

pack :: [Word8] -> b Source #

tail :: b -> b Source #

#### Instances

Instances details

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 #

UTF8Bytes ByteString Int64 Source # |

Instance details

Defined in Codec.Binary.UTF8.Generic

Methods

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

bdrop :: Int64 -> ByteString -> ByteString Source #

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

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

empty :: ByteString Source #

null :: ByteString -> Bool Source #

pack :: [Word8] -> ByteString Source #

tail :: ByteString -> ByteString Source #

UTF8Bytes [Word8] Int Source # |
Instance details Defined in Codec.Binary.UTF8.Generic Methods bsplit :: Int -> [Word8] -> ([Word8], [Word8]) Source # bdrop :: Int -> [Word8] -> [Word8] Source # buncons :: [Word8] -> Maybe (Word8, [Word8]) Source # elemIndex :: Word8 -> [Word8] -> Maybe Int Source # empty :: [Word8] Source # null :: [Word8] -> Bool Source # pack :: [Word8] -> [Word8] Source # tail :: [Word8] -> [Word8] Source #

decode :: UTF8Bytes b s => b -> Maybe (Char, s) 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 :: UTF8Bytes b s => b -> Maybe (Char, b) Source #

Get the first character of a byte string, if any. Malformed characters are replaced by `'\0xFFFD'`.

splitAt :: UTF8Bytes b s => s -> b -> (b, b) Source #

Split after a given number of characters. Negative values are treated as if they are 0.

take :: UTF8Bytes b s => s -> b -> b 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 :: UTF8Bytes b s => s -> b -> b 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 :: UTF8Bytes b s => (Char -> Bool) -> b -> (b, b) 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 :: UTF8Bytes b s => (Char -> Bool) -> b -> (b, b) 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 :: UTF8Bytes b s => String -> b Source #

Converts a Haskell string into a UTF8 encoded bytestring.

toString :: UTF8Bytes b s => b -> String Source #

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

foldl :: UTF8Bytes b s => (a -> Char -> a) -> a -> b -> a Source #

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

foldr :: UTF8Bytes b s => (Char -> a -> a) -> a -> b -> a Source #

Traverse a bytestring (right biased).

length :: UTF8Bytes b s => b -> s Source #

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

lines :: UTF8Bytes b s => b -> [b] 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' :: UTF8Bytes b s => b -> [b] 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`.