1.7 KiB
1.7 KiB
Strings
import qualified Data.Text as T
import qualified Data.Text.Lazy as L
Text
The Text type represents Unicode character strings, in a time and space-efficient manner. This package provides text processing capabilities that are optimized for performance critical use, both in terms of large data quantities and high speed.
LText
Bytestring
LBytestring
Encoding
encodeUtf8
encodeUtf8 :: Text -> ByteString
> encodeUtf8 "ポケット"
"\227\131\157\227\130\177\227\131\131\227\131\136"
decodeUtf8
decodeUtf8 :: ByteString -> Text
> putStrLn $ decodeUtf8 "\227\131\157\227\130\177\227\131\131\227\131\136"
ポケット
decodeUtf8'
decodeUtf8' :: ByteString -> Either UnicodeException Text
decodeUtf8With
decodeUtf8With :: OnDecodeError -> ByteString -> Text
UnicodeException
data UnicodeException
= DecodeError [Char] (Maybe Word8)
| EncodeError [Char] (Maybe Char)
Strictness
fromStrict
fromStrict :: Text -> LText
toStrict
toStrict :: LText -> Text
Conversion
class StringConv a b where
strConv :: Leniency -> a -> b
data Leniency = Lenient | Strict
toS
toS :: StringConv a b => a -> b
toSL
toSL :: StringConv a b => a -> b
Example:
a :: LByteString
a = "Einstein"
b :: Text
b = "Feynmann"
c :: ByteString
c = "Schrödinger"
example1 :: ByteString
example1 = toS b
example2 :: Bool
example2 = (a == toS b) && (toS b == c)