packages feed

Z-Data 0.8.1.0 → 0.8.2.0

raw patch · 11 files changed

+65/−21 lines, 11 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Z.Data.Text: displayWidthChar :: Char -> Int
+ Z.Data.Text.Base: displayWidthChar :: Char -> Int
+ Z.Foreign.CPtr: withCPtrs :: forall a b. [CPtr a] -> (Ptr (Ptr a) -> Int -> IO b) -> IO b
+ Z.Foreign.CPtr: withCPtrsUnsafe :: forall a b. [CPtr a] -> (BA# (Ptr a) -> Int -> IO b) -> IO b

Files

ChangeLog.md view
@@ -1,5 +1,10 @@ # Revision history for Z-Data +## 0.8.2.0  -- 2021-05-10++* Add `withCPtrs`, `withCPtrsUnsafe` to `Z.Foreign.CPtr`.+* Add `displayWidthChar` to `Z.Data.Text`.+ ## 0.8.1.0  -- 2021-04-23  * Change `ParseChunks` and `parseChunks` to based on `parseChunk`.
README.md view
@@ -2,7 +2,7 @@  [![Hackage](https://img.shields.io/hackage/v/Z-Data.svg?style=flat)](https://hackage.haskell.org/package/Z-Data) [![Linux Build Status](https://github.com/ZHaskell/z-data/workflows/ubuntu-ci/badge.svg)](https://github.com/ZHaskell/z-data/actions)-[![MacOS Build Status](https://github.com/haskell-Z/z-data/workflows/osx-ci/badge.svg)](https://github.com/ZHaskell/z-data/actions)+[![macOS Build Status](https://github.com/ZHaskell/z-data/workflows/osx-ci/badge.svg)](https://github.com/ZHaskell/z-data/actions) [![Windows Build Status](https://github.com/ZHaskell/z-data/workflows/win-ci/badge.svg)](https://github.com/ZHaskell/z-data/actions) [![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.svg)](https://gitter.im/Z-Haskell/community) 
Z-Data.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4 name:               Z-Data-version:            0.8.1.0+version:            0.8.2.0 synopsis:           Array, vector and text description:        This package provides array, slice and text operations license:            BSD-3-Clause@@ -10,8 +10,8 @@ copyright:          (c) Z.Haskell Contributors category:           Data build-type:         Custom-homepage:           https://github.com/haskell-Z/z-data-bug-reports:        https://github.com/haskell-Z/z-data/issues+homepage:           https://github.com/ZHaskell/z-data+bug-reports:        https://github.com/ZHaskell/z-data/issues extra-source-files:   AUTHORS   cbits/bytes.c
Z/Data/JSON.hs view
@@ -124,7 +124,7 @@ -- --     * Records are encoded as JSON object like above. @data T = A | B {k1 :: .., k2 :: ..}@ are encoded as --         @{\"B\":{\"k1\":...,\"k2\":...}}@ in @B .. ..@ case, or @\"A\"@ in @A@ case.---     * Plain product are similar to above, wrappered by an outer single-key object layer marking which constructor.+--     * Products inside a sum type are similar to above, wrapped by an outer single-key object layer marking which constructor used during data construction. -- -- These rules apply to user defined ADTs, but some built-in instances have different behaviours, namely: --@@ -184,9 +184,9 @@ -- -- The 'Value' type is different from aeson's one in that we use @Vector (Text, Value)@ to represent JSON objects, thus -- we can choose different strategies on key duplication, the lookup map type, etc. so instead of a single 'withObject',--- we provide 'withHashMap', 'withHashMapR', 'withFlatMap' and 'withFlatMapR' which use different lookup map type, and different key order piority. Most of time 'FlatMap' is faster than 'HashMap' since we only use the lookup map once, the cost of constructing a 'HashMap' is higher. If you want to directly working on key-values, 'withKeyValues' provide key-values vector access.+-- we provide 'withHashMap', 'withHashMapR', 'withFlatMap' and 'withFlatMapR' which use different lookup map type, and different key order priority. Most of the time 'FlatMap' is faster than 'HashMap' since we only use the lookup map once, the cost of constructing a 'HashMap' is higher. If you want to directly work on key-values, 'withKeyValues' provide key-values vector access. ----- There're some useful tools to help write encoding code in "Z.Data.JSON.Builder" module, such as JSON string escaping tool, etc.+-- There're some useful tools to help write encoding code in "Z.Data.JSON.Builder" module, such as a JSON string escaping tool, etc. -- -- If you don't particularly care for fast encoding, you can also use 'toValue' together with value builder, the overhead is usually very small. 
Z/Data/JSON/Value.hs view
@@ -12,8 +12,7 @@   * The numeric representation use 'Scientific', which impose a limit on number's exponent part(limited to 'Int').   * Unescaped control characters(<=0x1F) are NOT accepted, (different from aeson).   * Only @0x20, 0x09, 0x0A, 0x0D@ are valid JSON whitespaces, 'skipSpaces' from this module is different from 'P.skipSpaces'.-  * A JSON document shouldn't have trailing characters except whitespaces describe above, see 'parseValue''-    and 'parseValueChunks''.+  * A JSON document shouldn't have trailing characters except whitespaces describe above, see 'parseValue''.   * Objects are represented as key-value vectors, key order and duplicated keys are preserved for further processing.  Note that rfc8258 doesn't enforce unique key in objects, it's up to users to decided how to deal with key duplication, e.g. prefer first or last key, see 'Z.Data.JSON.Base.withFlatMap' or 'Std.Data.JSON.Base.withFlatMapR' for example.
Z/Data/Parser/Base.hs view
@@ -217,10 +217,10 @@ -- parseChunks :: Monad m => (V.Bytes -> Result e a) -> ParseChunks m e a {-# INLINABLE parseChunks #-}-parseChunks pc m0 inp = go m0 (pc inp)+parseChunks pc m inp = go (pc inp)   where-    go m r = case r of-        Partial f -> go m . f =<< m+    go r = case r of+        Partial f -> go . f =<< m         Success a rest    -> pure (rest, Right a)         Failure errs rest -> pure (rest, Left errs) 
Z/Data/Text.hs view
@@ -9,7 +9,7 @@  A 'Text' wrap a 'Bytes' which will be interpreted using UTF-8 encoding. User should always use 'validate' \/ 'validateMaybe' to construt a 'Text' (instead of using construtor directly or coercing), otherwise illegal UTF-8 encoded codepoints will cause undefined behaviours. -This library also provide simple unicode processing based on <https://github.com/haskell-Z/utf8rewind/ utf8rewind>,+This library also provide simple unicode processing based on <https://github.com/ZHaskell/utf8rewind/ utf8rewind>, see 'normalize', 'caseFold' (current using unicode 13 databases).  -}@@ -43,7 +43,7 @@     -- ** Special folds   , count, all, any     -- ** Text display width-  , displayWidth+  , displayWidth, displayWidthChar   -- * Slice manipulation   , cons, snoc   , uncons, unsnoc
Z/Data/Text/Base.hs view
@@ -38,7 +38,7 @@     -- ** Special folds   , count, all, any     -- ** Text display width-  , displayWidth+  , displayWidth, displayWidthChar     -- ** normalization   , NormalizationResult(..), NormalizeMode(..)   , isNormalized, isNormalizedTo, normalize, normalizeTo@@ -1107,6 +1107,13 @@         | i >= end = acc         | otherwise =             let (# c, n #) = decodeChar ba i-            in go (i+n) (acc + mk_wcwidth (fromIntegral (fromEnum c)))+            in go (i+n) (acc + displayWidthChar c)++-- | Get the display width of a 'Char'.+--+-- You shouldn't pass texts with control characters(<0x20, \\DEL), which are counted with -1 width.+displayWidthChar :: Char -> Int+{-# INLINE displayWidthChar #-}+displayWidthChar c =  mk_wcwidth (fromIntegral (fromEnum c))  foreign import ccall unsafe "hs_wcwidth.c mk_wcwidth" mk_wcwidth :: Int32 -> Int
Z/Foreign/CPtr.hs view
@@ -12,19 +12,22 @@  module Z.Foreign.CPtr (   -- * CPtr type-    CPtr, newCPtr', newCPtrUnsafe, newCPtr, withCPtr+    CPtr, newCPtr', newCPtrUnsafe, newCPtr, withCPtr, withCPtrsUnsafe, withCPtrs   -- * Ptr type   , Ptr   , nullPtr   , FunPtr   ) where +import Control.Monad import Control.Monad.Primitive-import Control.Exception        (mask_)+import Control.Exception                    (mask_) import Data.Primitive.PrimArray-import Z.Data.Text              as T+import qualified Z.Data.Text                as T import GHC.Ptr import GHC.Exts+import Z.Data.Array+import Z.Foreign  -- | Lightweight foreign pointers. newtype CPtr a = CPtr (PrimArray (Ptr a))@@ -38,7 +41,7 @@     CPtr a `compare` CPtr b = indexPrimArray a 0 `compare` indexPrimArray b 0  instance Show (CPtr a) where-    show = toString+    show = T.toString  instance T.Print (CPtr a) where     {-# INLINE toUTF8BuilderP #-}@@ -102,3 +105,26 @@     r <- f (indexPrimArray pa 0)     primitive_ (touch# ba#)     return r++-- | Pass a list of 'CPtr Foo' as @foo**@. USE THIS FUNCTION WITH UNSAFE FFI ONLY!+withCPtrsUnsafe :: forall a b. [CPtr a] -> (BA# (Ptr a) -> Int -> IO b) -> IO b+withCPtrsUnsafe cptrs f = do+    mpa <- newPrimArray @IO @(Ptr a) len+    foldM_ (\ !i (CPtr pa) ->+        writePrimArray mpa i (indexPrimArray pa 0) >> return (i+1)) 0 cptrs+    (PrimArray ba#) <- unsafeFreezePrimArray mpa+    r <- f ba# len+    primitive_ (touch# cptrs)+    return r+  where len = length cptrs++-- | Pass a list of 'CPtr Foo' as @foo**@.+withCPtrs :: forall a b. [CPtr a] -> (Ptr (Ptr a) -> Int -> IO b) -> IO b+withCPtrs cptrs f = do+    mpa <- newPinnedPrimArray @IO @(Ptr a) len+    foldM_ (\ !i (CPtr pa) ->+        writePrimArray mpa i (indexPrimArray pa 0) >> return (i+1)) 0 cptrs+    r <- withMutablePrimArrayContents mpa $ \ p -> f p len+    primitive_ (touch# cptrs)+    return r+  where len = length cptrs
test/Z/ForeignSpec.hs view
@@ -11,7 +11,6 @@ import           Z.Foreign import qualified Z.Data.Vector.Base         as V import qualified Z.Data.Array               as A-import           Z.Foreign import           Test.QuickCheck import           Test.QuickCheck.Function import           Test.QuickCheck.Property
test/cbits/ffi.c view
@@ -21,3 +21,11 @@   }   return res; }++HsWord sum_pointer(void** addr, HsInt len){+    HsWord sum = 0;+    for(HsInt ix = 0;ix < len;ix++) {+        sum += (size_t)addr[ix];+    }+    return sum;+}