charToJChar :: Char -> Maybe JChar
charToJChar chr
    | chrVal <= maxJChar && not isSurrogate = Just $ fromIntegral chrVal
    | otherwise = Nothing
    where maxJChar = fromIntegral (maxBound :: JChar)
          chrVal = ord chr
          -- check if Char is reserved UTF-16 value - not a valid JChar
          isSurrogate = 0xD800 <= chrVal && chrVal <= 0xDFFF
charToJChar :: Char -> Maybe JChar
charToJChar chr
    | chrVal <= maxJChar && not isSurrogate = Just $ fromIntegral chrVal
    | otherwise = Nothing
    where maxJChar = fromIntegral (maxBound :: JChar)
          chrVal = ord chr
          -- check if Char is reserved UTF-16 value - not a valid JChar
          isSurrogate = 0xD800 <= chrVal && chrVal <= 0xDFFF
charToJChar chr
    | chrVal <= maxJChar && not isSurrogate = Just $ fromIntegral chrVal
    | otherwise = Nothing
    where maxJChar = fromIntegral (maxBound :: JChar)
          chrVal = ord chr
          -- check if Char is reserved UTF-16 value - not a valid JChar
          isSurrogate = 0xD800 <= chrVal && chrVal <= 0xDFFF