packages feed

validity-text 0.1.1.0 → 0.1.2.0

raw patch · 2 files changed

+26/−17 lines, 2 filesdep +bytestring

Dependencies added: bytestring

Files

src/Data/Validity/Text.hs view
@@ -2,25 +2,33 @@  module Data.Validity.Text where +import Control.Exception (evaluate, try)+ import Data.Validity +import qualified Data.ByteString.Builder as SBB+import qualified Data.ByteString.Lazy as LB+import Data.Text () import qualified Data.Text.Array as A+import qualified Data.Text.Encoding as E+import qualified Data.Text.Encoding.Error as E import Data.Text.Internal (Text(..))-import qualified Data.Text.Internal.Encoding.Utf16 as E+import qualified Data.Text.Unsafe as U  -- | A text is valid if the internal structure is consistent. instance Validity Text where-    isValid (Text arr off len) =-        let c = A.unsafeIndex arr off-        in and-               [ len >= 0-               , off >= 0-               , len == 0 || c < 0xDC00 || c > 0xDFFF-               , let ws = A.toList arr off len -- Checking for failures while decoding the UTFX-                 in all E.validate1 ws && all (uncurry E.validate2) (tupsOf ws)-               ]-      where-        tupsOf :: [a] -> [(a, a)]-        tupsOf [] = []-        tupsOf [_] = []-        tupsOf (a:b:rs) = (a, b) : tupsOf rs+    isValid t@(Text arr off len) =+        and+            [ len >= 0+            , off >= 0+            , let c = A.unsafeIndex arr off+              in len == 0 || c < 0xDC00 || c > 0xDFFF+                 -- It contains a valid UTF16+            , (== (Right t :: Either E.UnicodeException Text)) $+              U.unsafeDupablePerformIO .+              try .+              evaluate .+              E.decodeUtf16LEWith E.strictDecode .+              LB.toStrict . SBB.toLazyByteString . mconcat . map SBB.word16LE $+              A.toList arr off len+            ]
validity-text.cabal view
@@ -1,5 +1,5 @@ name: validity-text-version: 0.1.1.0+version: 0.1.2.0 cabal-version: >=1.10 build-type: Simple license: MIT@@ -23,7 +23,8 @@     build-depends:         base <5,         validity -any,-        text -any+        text -any,+        bytestring -any     default-language: Haskell2010     hs-source-dirs: src