module Data.Char
  (chr
  ,ord
  ,isAscii
  ,isLatin1
  ,toUpper
  ,toLower
  ,isAsciiLower
  ,isAsciiUpper
  ,isDigit
  ,isOctDigit
  ,isHexDigit
  ,isSpace
  ) where

import Fay.FFI

chr :: Int -> Char
chr :: Int -> Char
chr = [Char] -> Int -> Char
forall s a. IsString s => s -> a
ffi [Char]
"String.fromCharCode(%1)"

ord :: Char -> Int
ord :: Char -> Int
ord = [Char] -> Char -> Int
forall s a. IsString s => s -> a
ffi [Char]
"%1.charCodeAt(0)"

isAscii :: Char -> Bool
isAscii :: Char -> Bool
isAscii Char
c = Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
< Char
'\x80'

isLatin1 :: Char -> Bool
isLatin1 :: Char -> Bool
isLatin1 Char
c = Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'\xff'

toUpper :: Char -> Char
toUpper :: Char -> Char
toUpper = [Char] -> Char -> Char
forall s a. IsString s => s -> a
ffi [Char]
"%1.toUpperCase()"

toLower :: Char -> Char
toLower :: Char -> Char
toLower = [Char] -> Char -> Char
forall s a. IsString s => s -> a
ffi [Char]
"%1.toLowerCase()"

isAsciiLower :: Char -> Bool
isAsciiLower :: Char -> Bool
isAsciiLower Char
c = Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'a' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'z'

isAsciiUpper :: Char -> Bool
isAsciiUpper :: Char -> Bool
isAsciiUpper Char
c = Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'A' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'Z'

isDigit :: Char -> Bool
isDigit :: Char -> Bool
isDigit Char
c = Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'0' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'9'

isOctDigit :: Char -> Bool
isOctDigit :: Char -> Bool
isOctDigit Char
c =  Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'0' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'7'

isHexDigit :: Char -> Bool
isHexDigit :: Char -> Bool
isHexDigit Char
c  = Char -> Bool
isDigit Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'A' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'F' Bool -> Bool -> Bool
||
                             Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'a' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'f'

isSpace :: Char -> Bool
isSpace :: Char -> Bool
isSpace = [Char] -> Char -> Bool
forall s a. IsString s => s -> a
ffi [Char]
"%1.replace(/\\s/g,'') != %1"