wcwidth-0.0.2: Native wcwidth.

Safe Haskell | None
Language | Haskell98

Data.Char.WCWidth

Description

A binding for the native `wcwidth`. It's important that you `setLocale` before using it, like this:

     #!/usr/bin/env runhaskell

     import Text.Printf

     import System.Locale.SetLocale
     import Data.Char.WCWidth

     main                     =  do
       setLocale LC_ALL (Just "")
       sequence_ [ display c | c <- chars ]
      where
       chars                  =  [minBound..'A']
       display c = printf "%04x  %2d  %s\n" (fromEnum c) (wcwidth c) (show c)

The program file `WCWidthTableaux.hs` contains a more extensive example of using `wcwidth`.

Note that this binding to the native implementation gets certain characters wrong in obvious ways as well as ways that are problematic for indentation based languages. The ASCII tab should be assigned a width of 8, not -1; and one is likely to find -1 assigned to numerous obscure characters (for example, symbols from the Book of Changes).

Synopsis

- wcwidth :: Char -> Int
- widths :: [(Char, Int)]
- ranges :: [((Char, Char), Int)]

# Documentation

wcwidth :: Char -> Int Source #

Binding to the native `wcwidth`.

widths :: [(Char, Int)] Source #

Widths of all characters.

ranges :: [((Char, Char), Int)] Source #

Characters broken into contiguous ranges with the same width.