Skip to content

Commit

Permalink
Implement singleton constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
hvr committed Jan 18, 2018
1 parent fc4b1a3 commit b28ea8d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Data/Text/Short.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ module Data.Text.Short
, stripSuffix

-- * Conversions
-- ** 'Char'
, singleton

-- ** 'String'
, fromString
, toString
Expand Down
14 changes: 14 additions & 0 deletions src/Data/Text/Short/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ module Data.Text.Short.Internal
, stripSuffix

-- * Conversions
-- ** 'Char'
, singleton

-- ** 'String'
, Data.Text.Short.Internal.fromString
, toString
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit b28ea8d

Please sign in to comment.