diff --git a/src/Data/Text/Short.hs b/src/Data/Text/Short.hs index 6bfe3e5..f013760 100644 --- a/src/Data/Text/Short.hs +++ b/src/Data/Text/Short.hs @@ -24,6 +24,9 @@ module Data.Text.Short , stripSuffix -- * Conversions + -- ** 'Char' + , singleton + -- ** 'String' , fromString , toString diff --git a/src/Data/Text/Short/Internal.hs b/src/Data/Text/Short/Internal.hs index b2fd972..a4b66a5 100644 --- a/src/Data/Text/Short/Internal.hs +++ b/src/Data/Text/Short/Internal.hs @@ -32,6 +32,9 @@ module Data.Text.Short.Internal , stripSuffix -- * Conversions + -- ** 'Char' + , singleton + -- ** 'String' , Data.Text.Short.Internal.fromString , toString @@ -209,6 +212,17 @@ toText = T.decodeUtf8 . toByteString ---- +-- | \(\mathcal{O}(1)\) Construct 'ShortText' from single codepoint. +-- +-- Note: This function is total because it replaces the (invalid) code-points U+D800 through U+DFFF with the replacement character U+FFFD. +-- +-- @since TBD +singleton :: Char -> ShortText +singleton c0 = fromText (T.singleton c) + where + c | 0xd800 <= ord c0, ord c0 < 0xe000 = '\xFFFD' + | otherwise = c0 + -- | \(\mathcal{O}(n)\) Construct/pack from 'String' -- -- Note: This function is total because it replaces the (invalid) code-points U+D800 through U+DFFF with the replacement character U+FFFD.