module Data.Text.Punycode (encode, decode, internationalize) where import qualified Data.ByteString as BS import qualified Data.ByteString.UTF8 as UTF8BS import Data.Char (isAscii) import Data.Text.Punycode.Encode (encode) import Data.Text.Punycode.Decode (decode) -- | Convenience function for internationalized domain names. If there is -- at least one non-ascii character, this function will encode the input -- and prepend \"xn--\" to the output string. Otherwise, it will return the -- string untouched. Note that this function does not run nameprep (e.g. it -- operates on pre-prepped strings) internationalize :: String -> BS.ByteString internationalize x | all isAscii x = UTF8BS.fromString x | otherwise = UTF8BS.fromString "xn--" `BS.append` encode x