License | MIT |
---|---|
Stability | Experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
This module exposes higher-level binding to OpenCC than Text.OpenCC.Raw. OpenCC resources are managed automatically, and large string objects are passed without being copied.
There are three sets of higher-level bindings.
- IO handles. You work in
IO
monad and work withOpenCC
handles directly. - One-shot.
convert1
directly converts aString
. - Monadic. You work in
OpenCCM
monad where you can useconvert
.
Caveat: the one-shot interface is unsafe, but as long as OpenCC is not shared or you don't care about errors, you will be fine.
defaultTradToSimp
and defaultSimpToTrad
are suggested by OpenCC.
Synopsis
- convert1 :: String -> Text -> Maybe Text
- type OpenCC = ForeignPtr ()
- open :: String -> MaybeT IO OpenCC
- lastError :: IO Text
- convertIO :: OpenCC -> Text -> IO Text
- data OpenCCM a
- withOpenCC :: String -> OpenCCM a -> MaybeT IO a
- unsafeWithOpenCC :: String -> OpenCCM a -> Maybe a
- convert :: Text -> OpenCCM Text
- defaultSimpToTrad :: String
- defaultTradToSimp :: String
Documentation
convert1 :: String -> Text -> Maybe Text Source #
Do a one-shot conversion. Note that this might affect the outcome
of lastError
, and thus unsafe (despite the pureness suggested by
the signature).
convert1 defaultSimpToTrad "头发发财"
type OpenCC = ForeignPtr () Source #
OpenCC handle plus the finalizer. The OpenCC instance will be finalized when the object is garbage collected.
convertIO :: OpenCC -> Text -> IO Text Source #
Use an OpenCC handle to do the conversion. The result is a UTF-8 encoded text.
The OpenCC environment. In this environment, any conversion
happens within a single OpenCC
instance created by withOpenCC
.
unsafeWithOpenCC :: String -> OpenCCM a -> Maybe a Source #
Same as withOpenCC
but the result is not IO
. This is unsafe,
and the same safety conditions as convert1
apply here.
defaultSimpToTrad :: String Source #
Filename of default Simplified to Traditional configuration
defaultTradToSimp :: String Source #
Filename of default Traditional to Simplified configuration