{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP, NoImplicitPrelude #-}
{-# OPTIONS_HADDOCK hide #-}
module GHC.Unicode (
isAscii, isLatin1, isControl,
isAsciiUpper, isAsciiLower,
isPrint, isSpace, isUpper,
isLower, isAlpha, isDigit,
isOctDigit, isHexDigit, isAlphaNum,
toUpper, toLower, toTitle,
wgencat
) where
import GHC.Base
import GHC.Char
import GHC.Real (fromIntegral)
import Foreign.C.Types (CInt(..))
#include "HsBaseConfig.h"
isAscii :: Char -> Bool
isAscii c = c < '\x80'
isLatin1 :: Char -> Bool
isLatin1 c = c <= '\xff'
isAsciiLower :: Char -> Bool
isAsciiLower c = c >= 'a' && c <= 'z'
isAsciiUpper :: Char -> Bool
isAsciiUpper c = c >= 'A' && c <= 'Z'
isControl :: Char -> Bool
isPrint :: Char -> Bool
isSpace :: Char -> Bool
isSpace c = c == ' ' ||
c == '\t' ||
c == '\n' ||
c == '\r' ||
c == '\f' ||
c == '\v' ||
c == '\xa0' ||
iswspace (fromIntegral (ord c)) /= 0
isUpper :: Char -> Bool
isLower :: Char -> Bool
isAlpha :: Char -> Bool
isAlphaNum :: Char -> Bool
isDigit :: Char -> Bool
isDigit c = c >= '0' && c <= '9'
isOctDigit :: Char -> Bool
isOctDigit c = c >= '0' && c <= '7'
isHexDigit :: Char -> Bool
isHexDigit c = isDigit c || c >= 'A' && c <= 'F' ||
c >= 'a' && c <= 'f'
toUpper :: Char -> Char
toLower :: Char -> Char
toTitle :: Char -> Char
isAlpha c = iswalpha (fromIntegral (ord c)) /= 0
isAlphaNum c = iswalnum (fromIntegral (ord c)) /= 0
isControl c = iswcntrl (fromIntegral (ord c)) /= 0
isPrint c = iswprint (fromIntegral (ord c)) /= 0
isUpper c = iswupper (fromIntegral (ord c)) /= 0
isLower c = iswlower (fromIntegral (ord c)) /= 0
toLower c = chr (fromIntegral (towlower (fromIntegral (ord c))))
toUpper c = chr (fromIntegral (towupper (fromIntegral (ord c))))
toTitle c = chr (fromIntegral (towtitle (fromIntegral (ord c))))
foreign import ccall unsafe "u_iswalpha"
iswalpha :: CInt -> CInt
foreign import ccall unsafe "u_iswalnum"
iswalnum :: CInt -> CInt
foreign import ccall unsafe "u_iswcntrl"
iswcntrl :: CInt -> CInt
foreign import ccall unsafe "u_iswspace"
iswspace :: CInt -> CInt
foreign import ccall unsafe "u_iswprint"
iswprint :: CInt -> CInt
foreign import ccall unsafe "u_iswlower"
iswlower :: CInt -> CInt
foreign import ccall unsafe "u_iswupper"
iswupper :: CInt -> CInt
foreign import ccall unsafe "u_towlower"
towlower :: CInt -> CInt
foreign import ccall unsafe "u_towupper"
towupper :: CInt -> CInt
foreign import ccall unsafe "u_towtitle"
towtitle :: CInt -> CInt
foreign import ccall unsafe "u_gencat"
wgencat :: CInt -> CInt