From 7819fb45a2096e7943e85136e0e8c3a507451e88 Mon Sep 17 00:00:00 2001 From: Nicholas Scheel Date: Tue, 26 Dec 2017 01:00:53 -0600 Subject: [PATCH] Add conversions between CodePoint and Char --- src/Data/String/CodePoints.purs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Data/String/CodePoints.purs b/src/Data/String/CodePoints.purs index 7fe51f3..0cac8c8 100644 --- a/src/Data/String/CodePoints.purs +++ b/src/Data/String/CodePoints.purs @@ -60,6 +60,13 @@ codePointFromInt n = Nothing codePointToInt :: CodePoint -> Int codePointToInt (CodePoint n) = n +codePointToChar :: CodePoint -> Maybe Char +codePointToChar (CodePoint n) | 0 <= n && n <= 0xFFFF = Just (Char.fromCharCode n) +codePointToChar n = Nothing + +codePointFromChar :: Char -> CodePoint +codePointFromChar = CodePoint <<< Char.toCharCode + unsurrogate :: Int -> Int -> CodePoint unsurrogate lead trail = CodePoint ((lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000)