module Codec.Binary.UTF8.Width ( wcwidth
, wcswidth
)
where
import Foreign.C.Types
import Foreign.C.String
import Foreign.Storable
import Foreign.Ptr
import System.IO.Unsafe
wcwidth :: Char -> Int
wcwidth c = unsafePerformIO (withCWString [c] $! \ws -> do
wc <- peek ws
let !w = fromIntegral $! wcwidth' wc
return w
)
foreign import ccall unsafe "vty_mk_wcwidth" wcwidth' :: CWchar -> CInt
wcswidth :: String -> Int
wcswidth str = unsafePerformIO (withCWStringLen str $! \(ws, ws_len) -> do
let !w = fromIntegral $! wcswidth' ws (fromIntegral ws_len)
return w
)
foreign import ccall unsafe "vty_mk_wcswidth" wcswidth' :: Ptr CWchar -> CSize -> CInt