utf8-string 0.3.6 → 0.3.7
raw patch · 6 files changed
+45/−39 lines, 6 filesnew-uploader
Files
- Codec/Binary/UTF8/Generic.hs +8/−8
- Codec/Binary/UTF8/String.hs +9/−3
- Data/ByteString/Lazy/UTF8.hs +8/−8
- Data/ByteString/UTF8.hs +8/−8
- Data/String/UTF8.hs +11/−11
- utf8-string.cabal +1/−1
Codec/Binary/UTF8/Generic.hs view
@@ -178,13 +178,13 @@ Nothing -> (bs, empty) -- | @take n s@ returns the first @n@ characters of @s@.--- If @s@ has less then @n@ characters, then we return the whole of @s@.+-- If @s@ has less than @n@ characters, then we return the whole of @s@. {-# INLINE take #-} take :: UTF8Bytes b s => s -> b -> b take n bs = fst (splitAt n bs) -- | @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.+-- If @s@ has less than @n@ characters, then we return an empty string. {-# INLINE drop #-} drop :: UTF8Bytes b s => s -> b -> b drop n bs = snd (splitAt n bs)@@ -227,7 +227,7 @@ Nothing -> nil -- | Traverse a bytestring (left biased).--- This fuction is strict in the acumulator.+-- This function is strict in the accumulator. {-# SPECIALIZE foldl :: (a -> Char -> a) -> a -> B.ByteString -> a #-} {-# SPECIALIZE foldl :: (a -> Char -> a) -> a -> L.ByteString -> a #-} {-# SPECIALIZE foldl :: (a -> Char -> a) -> a -> [Word8] -> a #-}@@ -238,7 +238,7 @@ Nothing -> acc -- | Counts the number of characters encoded in the bytestring.--- Note that this includes replacment characters.+-- Note that this includes replacement characters. {-# SPECIALIZE length :: B.ByteString -> Int #-} {-# SPECIALIZE length :: L.ByteString -> Int64 #-} {-# SPECIALIZE length :: [Word8] -> Int #-}@@ -249,8 +249,8 @@ Nothing -> n -- | 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.+-- 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\''. {-# SPECIALIZE lines :: B.ByteString -> [B.ByteString] #-} {-# SPECIALIZE lines :: L.ByteString -> [L.ByteString] #-}@@ -263,8 +263,8 @@ Nothing -> [bs] -- | 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.+-- 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'. {-# SPECIALIZE lines' :: B.ByteString -> [B.ByteString] #-}
Codec/Binary/UTF8/String.hs view
@@ -16,6 +16,7 @@ , decode , encodeString , decodeString+ , encodeChar , isUTF8Encoded , utf8Encode@@ -40,9 +41,9 @@ replacement_character :: Char replacement_character = '\xfffd' --- | Encode a Haskell String to a list of Word8 values, in UTF8 format.-encode :: String -> [Word8]-encode = concatMap (map fromIntegral . go . ord)+-- | Encode a single Haskell Char to a list of Word8 values, in UTF8 format.+encodeChar :: Char -> [Word8]+encodeChar = map fromIntegral . go . ord where go oc | oc <= 0x7f = [oc]@@ -60,6 +61,11 @@ , 0x80 + ((oc `shiftR` 6) .&. 0x3f) , 0x80 + oc .&. 0x3f ]+++-- | Encode a Haskell String to a list of Word8 values, in UTF8 format.+encode :: String -> [Word8]+encode = concatMap encodeChar -- -- | Decode a UTF8 string packed into a list of Word8 values, directly to String
Data/ByteString/Lazy/UTF8.hs view
@@ -131,12 +131,12 @@ Nothing -> (bs, B.empty) -- | @take n s@ returns the first @n@ characters of @s@.--- If @s@ has less then @n@ characters, then we return the whole of @s@.+-- If @s@ has less than @n@ characters, then we return the whole of @s@. take :: Int64 -> B.ByteString -> B.ByteString take n bs = fst (splitAt n bs) -- | @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.+-- If @s@ has less than @n@ characters, then we return an empty string. drop :: Int64 -> B.ByteString -> B.ByteString drop n bs = snd (splitAt n bs) @@ -170,7 +170,7 @@ Nothing -> nil -- | Traverse a bytestring (left biased).--- This fuction is strict in the acumulator.+-- This function is strict in the accumulator. foldl :: (a -> Char -> a) -> a -> B.ByteString -> a foldl add acc cs = case uncons cs of Just (a,as) -> let v = add acc a@@ -178,7 +178,7 @@ Nothing -> acc -- | Counts the number of characters encoded in the bytestring.--- Note that this includes replacment characters.+-- Note that this includes replacement characters. length :: B.ByteString -> Int length b = loop 0 b where loop n xs = case decode xs of@@ -186,8 +186,8 @@ Nothing -> n -- | 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.+-- 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 :: B.ByteString -> [B.ByteString] lines bs | B.null bs = []@@ -197,8 +197,8 @@ Nothing -> [bs] -- | 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.+-- 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'. lines' :: B.ByteString -> [B.ByteString]
Data/ByteString/UTF8.hs view
@@ -130,12 +130,12 @@ Nothing -> (bs, B.empty) -- | @take n s@ returns the first @n@ characters of @s@.--- If @s@ has less then @n@ characters, then we return the whole of @s@.+-- If @s@ has less than @n@ characters, then we return the whole of @s@. take :: Int -> B.ByteString -> B.ByteString take n bs = fst (splitAt n bs) -- | @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.+-- If @s@ has less than @n@ characters, then we return an empty string. drop :: Int -> B.ByteString -> B.ByteString drop n bs = snd (splitAt n bs) @@ -169,7 +169,7 @@ Nothing -> nil -- | Traverse a bytestring (left biased).--- This fuction is strict in the acumulator.+-- This function is strict in the accumulator. foldl :: (a -> Char -> a) -> a -> B.ByteString -> a foldl add acc cs = case uncons cs of Just (a,as) -> let v = add acc a@@ -177,7 +177,7 @@ Nothing -> acc -- | Counts the number of characters encoded in the bytestring.--- Note that this includes replacment characters.+-- Note that this includes replacement characters. length :: B.ByteString -> Int length b = loop 0 b where loop n xs = case decode xs of@@ -185,8 +185,8 @@ Nothing -> n -- | 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.+-- 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 :: B.ByteString -> [B.ByteString] lines bs | B.null bs = []@@ -196,8 +196,8 @@ Nothing -> [bs] -- | 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.+-- 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'. lines' :: B.ByteString -> [B.ByteString]
Data/String/UTF8.hs view
@@ -45,8 +45,8 @@ import qualified Codec.Binary.UTF8.Generic as G import Codec.Binary.UTF8.Generic (UTF8Bytes) --- | The type of strngs that are represented using the UTF8 encoding.--- The parameters is the type of the container for the representation.+-- | The type of strings that are represented using the UTF8 encoding.+-- The parameter is the type of the container for the representation. newtype UTF8 string = Str string deriving (Eq,Ord) -- XXX: Is this OK? instance UTF8Bytes string index => Show (UTF8 string) where@@ -100,12 +100,12 @@ -- | @take n s@ returns the first @n@ characters of @s@.--- If @s@ has less then @n@ characters, then we return the whole of @s@.+-- If @s@ has less than @n@ characters, then we return the whole of @s@. take :: UTF8Bytes string index => index -> UTF8 string -> UTF8 string take n (Str bs) = Str (G.take n bs) -- | @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.+-- If @s@ has less than @n@ characters, then we return an empty string. drop :: UTF8Bytes string index => index -> UTF8 string -> UTF8 string drop n (Str bs) = Str (G.drop n bs) @@ -135,7 +135,7 @@ return (c, Str y) -- | Extract the first character for the underlying representation,--- if one is avaialble. It also returns the number of bytes used+-- if one is available. It also returns the number of bytes used -- in the representation of the character. -- See also 'uncons', 'dropBytes'. decode :: UTF8Bytes string index => UTF8 string -> Maybe (Char, index)@@ -146,26 +146,26 @@ foldr cons nil (Str cs) = G.foldr cons nil cs -- | Traverse a bytestring (left biased).--- This fuction is strict in the accumulator.+-- This function is strict in the accumulator. foldl :: UTF8Bytes string index => (a -> Char -> a) -> a -> UTF8 string -> a foldl add acc (Str cs) = G.foldl add acc cs -- | Counts the number of characters encoded in the bytestring.--- Note that this includes replacment characters.+-- Note that this includes replacement characters. -- The function is linear in the number of bytes in the representation. length :: UTF8Bytes string index => UTF8 string -> index length (Str b) = G.length b -- | 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.+-- 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 string index => UTF8 string -> [UTF8 string] lines (Str b) = map Str (G.lines b) -- XXX: unnecessary map -- | 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.+-- 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'. lines' :: UTF8Bytes string index => UTF8 string -> [UTF8 string]
utf8-string.cabal view
@@ -1,5 +1,5 @@ Name: utf8-string-Version: 0.3.6+Version: 0.3.7 Author: Eric Mertens Maintainer: emertens@galois.com License: BSD3