Add allNames function

This commit is contained in:
Paul Brinkmeier 2023-03-24 13:06:17 +01:00
parent 976fbada7e
commit 3d104ef50c

View File

@ -102,7 +102,7 @@ instance MimeRender PlainText Utf8Model where
Right c -> Right c ->
[ Text.pack [c] [ Text.pack [c]
, Text.pack $ printf "U+%04X" c , Text.pack $ printf "U+%04X" c
, Text.pack $ intercalate ", " $ maybeToList (UnicodeNames.name c) ++ map (++ "*") (UnicodeNames.nameAliases c) , Text.pack $ intercalate ", " $ allNames c
, Text.pack $ fromMaybe "" $ blockName c , Text.pack $ fromMaybe "" $ blockName c
] ]
) )
@ -121,7 +121,7 @@ instance MimeRender HTML Utf8Model where
Right c -> do Right c -> do
H.td $ H.input ! A.class_ "charbox" ! A.value (H.toValue [c]) H.td $ H.input ! A.class_ "charbox" ! A.value (H.toValue [c])
H.td $ H.code $ printfHtml "U+%04X" c H.td $ H.code $ printfHtml "U+%04X" c
H.td $ H.code $ H.toHtml $ intercalate ", " $ maybeToList (UnicodeNames.name c) ++ map (++ "*") (UnicodeNames.nameAliases c) H.td $ H.code $ H.toHtml $ intercalate ", " $ allNames c
H.td $ H.code $ H.toHtml $ fromMaybe "" $ blockName c H.td $ H.code $ H.toHtml $ fromMaybe "" $ blockName c
-- /codepoints/<codepoints> -- /codepoints/<codepoints>
@ -159,7 +159,7 @@ instance MimeRender PlainText CodepointsModel where
Right c -> Right c ->
[ Text.pack [c] [ Text.pack [c]
, Text.pack $ printf "U+%04X" c , Text.pack $ printf "U+%04X" c
, Text.pack $ intercalate ", " $ maybeToList (UnicodeNames.name c) ++ map (++ "*") (UnicodeNames.nameAliases c) , Text.pack $ intercalate ", " $ allNames c
, Text.pack $ fromMaybe "" $ blockName c , Text.pack $ fromMaybe "" $ blockName c
] ]
) )
@ -177,7 +177,7 @@ instance MimeRender HTML CodepointsModel where
Right c -> do Right c -> do
H.td $ H.input ! A.class_ "charbox" ! A.value (H.toValue [c]) H.td $ H.input ! A.class_ "charbox" ! A.value (H.toValue [c])
H.td $ H.code $ printfHtml "U+%04X" c H.td $ H.code $ printfHtml "U+%04X" c
H.td $ H.code $ H.toHtml $ intercalate ", " $ maybeToList (UnicodeNames.name c) ++ map (++ "*") (UnicodeNames.nameAliases c) H.td $ H.code $ H.toHtml $ intercalate ", " $ allNames c
H.td $ H.code $ H.toHtml $ fromMaybe "" $ blockName c H.td $ H.code $ H.toHtml $ fromMaybe "" $ blockName c
-- /text/<text> -- /text/<text>
@ -192,7 +192,7 @@ instance MimeRender HTML TextModel where
H.tr $ do H.tr $ do
H.td $ H.input ! A.class_ "charbox" ! A.value (H.toValue [c]) H.td $ H.input ! A.class_ "charbox" ! A.value (H.toValue [c])
H.td $ H.code $ printfHtml "U+%04X" c H.td $ H.code $ printfHtml "U+%04X" c
H.td $ H.code $ H.toHtml $ intercalate ", " $ maybeToList (UnicodeNames.name c) ++ map (++ "*") (UnicodeNames.nameAliases c) H.td $ H.code $ H.toHtml $ intercalate ", " $ allNames c
H.td $ H.code $ H.toHtml $ fromMaybe "" $ blockName c H.td $ H.code $ H.toHtml $ fromMaybe "" $ blockName c
instance MimeRender PlainText TextModel where instance MimeRender PlainText TextModel where
@ -200,7 +200,7 @@ instance MimeRender PlainText TextModel where
[ map (Table.cl) [ map (Table.cl)
[ Text.pack [c] [ Text.pack [c]
, Text.pack $ printf "U+%04X" c , Text.pack $ printf "U+%04X" c
, Text.pack $ intercalate ", " $ maybeToList (UnicodeNames.name c) ++ map (++ "*") (UnicodeNames.nameAliases c) , Text.pack $ intercalate ", " $ allNames c
, Text.pack $ fromMaybe "" $ blockName c , Text.pack $ fromMaybe "" $ blockName c
] ]
| c <- Text.unpack model.text | c <- Text.unpack model.text
@ -218,6 +218,12 @@ showByteHex = printf " %02X"
showByteBin :: Word8 -> String showByteBin :: Word8 -> String
showByteBin = printf "%08b" showByteBin = printf "%08b"
-- | Retrieve name and aliases (suffixed with @*@) of a 'Char'.
allNames :: Char -> [String]
allNames c =
maybeToList (UnicodeNames.name c)
++ map (++ "*") (UnicodeNames.nameAliases c)
blockName :: Char -> Maybe String blockName :: Char -> Maybe String
blockName c = UnicodeBlocks.blockName . UnicodeBlocks.blockDefinition <$> UnicodeBlocks.block c blockName c = UnicodeBlocks.blockName . UnicodeBlocks.blockDefinition <$> UnicodeBlocks.block c