packages feed

string-variants 0.1.0.1 → 0.1.0.2

raw patch · 5 files changed

+13/−4 lines, 5 files

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # Changelog +## [0.1.0.2] - 2022-10-18++- Fix `mkNonEmptyTextWithTruncate` to perform truncation after character stripping.+ ## [0.1.0.1] - 2022-09-29  - Fix building on GHC 8.10.7, and add it to CI.
src/Data/StringVariants/NonEmptyText.hs view
@@ -12,6 +12,7 @@      -- * Construction     mkNonEmptyText,+    mkNonEmptyTextWithTruncate,     unsafeMkNonEmptyText,     nonEmptyTextToText,     compileNonEmptyText,
src/Data/StringVariants/NonEmptyText/Internal.hs view
@@ -81,6 +81,13 @@   where     stripped = T.filter (/= '\NUL') $ T.strip t +mkNonEmptyTextWithTruncate :: forall n. KnownNat n => Text -> Maybe (NonEmptyText n)+mkNonEmptyTextWithTruncate t+  | textIsWhitespace stripped = Nothing+  | otherwise = Just (NonEmptyText $ T.stripEnd $ T.take (fromIntegral $ natVal (Proxy @n)) stripped)+  where+    stripped = T.filter (/= '\NUL') $ T.stripStart t+ -- | Make a NonEmptyText when you can manually verify the length unsafeMkNonEmptyText :: forall n. KnownNat n => Text -> NonEmptyText n unsafeMkNonEmptyText = NonEmptyText
src/Data/StringVariants/NullableNonEmptyText.hs view
@@ -63,9 +63,6 @@   | textIsTooLong t (fromIntegral $ natVal (Proxy @n)) = Nothing -- we can't store text that is too long   | otherwise = Just $ NullableNonEmptyText $ mkNonEmptyText t -mkNonEmptyTextWithTruncate :: forall n. KnownNat n => Text -> Maybe (NonEmptyText n)-mkNonEmptyTextWithTruncate = mkNonEmptyText . T.take (fromInteger (natVal (Proxy @n)))- nullNonEmptyText :: NullableNonEmptyText n nullNonEmptyText = NullableNonEmptyText Nothing 
string-variants.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           string-variants-version:        0.1.0.1+version:        0.1.0.2 synopsis:       Constrained text newtypes description:    See README at <https://github.com/MercuryTechnologies/string-variants#readme>. category:       Data