File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 33## 0.6.0 (July 2024)
44
55- Updated to [ Unicode 15.1.0] ( https://www.unicode.org/versions/Unicode15.1.0/ ) .
6+ - Added ` showCodePoint ` to ` Unicode.Char ` .
67- Added ` intToDigiT ` to ` Unicode.Char.Numeric ` .
78
89## 0.5.0 (July 2024)
Original file line number Diff line number Diff line change @@ -35,7 +35,10 @@ module Unicode.Char
3535 , module Unicode.Char.Normalization
3636 , module Unicode.Char.Identifiers
3737
38- -- * Re-export from @base@
38+ -- * Utils
39+ , showCodePoint
40+
41+ -- * Re-export from @base@
3942 , ord
4043 , chr
4144 )
@@ -50,3 +53,26 @@ import Unicode.Char.Identifiers
5053import Unicode.Char.Numeric
5154import Unicode.Char.Normalization
5255import Unicode.Internal.Char.Version (unicodeVersion )
56+
57+ -- [NOTE] Code inspired from 'showIntAtBase'
58+ -- | Show the code point of a character using the Unicode Standard convention:
59+ -- hexadecimal codepoint padded with zeros if inferior to 4 characters.
60+ --
61+ -- >>> showCodePoint '\xf' ""
62+ -- "000F"
63+ -- >>> showCodePoint '\x1ffff' ""
64+ -- "1FFFF"
65+ --
66+ -- @since 0.6.0
67+ showCodePoint :: Char -> ShowS
68+ showCodePoint c = pad . showIt (quotRem cp 16 )
69+ where
70+ cp = ord c
71+ pad | cp <= 0x00f = \ s -> ' 0' : ' 0' : ' 0' : s
72+ | cp <= 0x0ff = \ s -> ' 0' : ' 0' : s
73+ | cp <= 0xfff = (' 0' : )
74+ | otherwise = id
75+ showIt (n, d) r = case intToDigiT d of
76+ ! c' -> case n of
77+ 0 -> c' : r
78+ _ -> showIt (quotRem n 16 ) (c' : r)
You can’t perform that action at this time.
0 commit comments