packages feed

validity-text 0.3.1.1 → 0.3.1.2

raw patch · 4 files changed

+63/−40 lines, 4 filesdep ~validitysetup-changed

Dependency ranges changed: validity

Files

LICENSE view
@@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016-2020 Tom Sydney Kerckhove+Copyright (c) 2016-2021 Tom Sydney Kerckhove  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
− Setup.hs
@@ -1,3 +0,0 @@-import Distribution.Simple--main = defaultMain
src/Data/Validity/Text.hs view
@@ -1,14 +1,13 @@-{-# OPTIONS_GHC -fno-warn-orphans #-} {-# LANGUAGE CPP #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}  module Data.Validity.Text where  import Control.Exception (evaluate, try)--import Data.Validity-+import Data.ByteString (ByteString) import qualified Data.ByteString.Builder as SBB import qualified Data.ByteString.Lazy as LB+import Data.Text (Text) import qualified Data.Text as ST import qualified Data.Text.Array as A import qualified Data.Text.Encoding as E@@ -16,36 +15,65 @@ import qualified Data.Text.Internal as ST import qualified Data.Text.Internal.Lazy as LT import qualified Data.Text.Unsafe as U+import Data.Validity+import Data.Word  -- | A text is valid if the internal structure is consistent. instance Validity ST.Text where-    validate t@(ST.Text arr off len) =-        mconcat-            [ check (len >= 0) "The length is positive."-            , check (off >= 0) "The offset is positive."-            , check-                  (let c = A.unsafeIndex arr off-                    in len == 0 || c < 0xDC00 || c > 0xDFFF)-                  "The offset character is valid UTF16."-                 -- It contains a valid UTF16-            , check-                  ((== (Right t :: Either E.UnicodeException ST.Text)) $-                   U.unsafeDupablePerformIO .-                   try .-                   evaluate .-                   E.decodeUtf16LEWith E.strictDecode .-                   LB.toStrict .-                   SBB.toLazyByteString . mconcat . map SBB.word16LE $-                   A.toList arr off len)-                  "The bytes can correctly be decoded as UTF16."-            ]+  validate t@(ST.Text arr off len) =+    mconcat+      [ declare "The length is positive." (len >= 0),+        declare "The offset is positive." (off >= 0),+        declare "The offset char is valid" $+          let c = A.unsafeIndex arr off+           in len == 0 || offsetCharCheck c,+        declare "The array contains bytes in the right encoding" $+          (== (Right t :: Either E.UnicodeException ST.Text))+            . U.unsafeDupablePerformIO+            . try+            . evaluate+            . validityDecoding+            . LB.toStrict+            . SBB.toLazyByteString+            . mconcat+            . map validityWording+            $ A.toList arr off len+      ]+    where +#if MIN_VERSION_text(2,0,0)+      offsetCharCheck :: Word8 -> Bool+      offsetCharCheck c =  c < 0x80 || c >= 0xC0 -- Valid UTF8+#else+      offsetCharCheck :: Word16 -> Bool+      offsetCharCheck c = c < 0xDC00 || c > 0xDFFF -- Valid UTF16+#endif++#if MIN_VERSION_text(2,0,0)+      validityDecoding :: ByteString -> Text+      validityDecoding = E.decodeUtf8With E.strictDecode+#else+      validityDecoding :: ByteString -> Text+      validityDecoding = E.decodeUtf16LEWith E.strictDecode+#endif++#if MIN_VERSION_text(2,0,0)+      validityWording :: Word8 -> SBB.Builder+      validityWording = SBB.word8+#else+      validityWording :: Word16 -> SBB.Builder+      validityWording = SBB.word16LE+#endif+ -- | A lazy text value is valid if all the internal chunks are valid and nonempty instance Validity LT.Text where-    validate LT.Empty = valid-    validate (LT.Chunk st lt) =-        mconcat-            [ delve "The strict chunk" st-            , declare "The strict chunk is not empty" $ not $ ST.null st-            , delve "The lazy chunk" lt-            ]+  validate LT.Empty = valid+  validate (LT.Chunk st lt) =+    mconcat+      [ delve "The strict chunk" st,+        declare "The strict chunk is not empty" $ not $ ST.null st,+        delve "The lazy chunk" lt+      ]++validateTextSingleLine :: ST.Text -> Validation+validateTextSingleLine = validateStringSingleLine . ST.unpack
validity-text.cabal view
@@ -1,20 +1,18 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.33.0.+-- This file has been generated from package.yaml by hpack version 0.34.4. -- -- see: https://github.com/sol/hpack------ hash: 54d7dc6c0d4ec3a9ed491d16e3e7eb5e0450e3638055729e40f68444332d8cf7  name:           validity-text-version:        0.3.1.1+version:        0.3.1.2 synopsis:       Validity instances for text category:       Web homepage:       https://github.com/NorfairKing/validity#readme bug-reports:    https://github.com/NorfairKing/validity/issues author:         Tom Sydney Kerckhove maintainer:     syd@cs-syd.eu-copyright:      Copyright: (c) 2016-2020 Tom Sydney Kerckhove+copyright:      Copyright: (c) 2016-2021 Tom Sydney Kerckhove license:        MIT license-file:   LICENSE build-type:     Simple