├── .gitignore ├── Foundation └── Compat │ ├── ByteString.hs │ └── Text.hs ├── LICENSE ├── README.md ├── Setup.hs ├── foundation-edge.cabal └── stack.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.hi 3 | *.tix 4 | *.mix 5 | .stack-work 6 | exts 7 | dist 8 | -------------------------------------------------------------------------------- /Foundation/Compat/ByteString.hs: -------------------------------------------------------------------------------- 1 | -- | 2 | -- Module : Foundation.Compat.ByteString 3 | -- License : BSD-style 4 | -- Maintainer : Foundation 5 | -- Stability : experimental 6 | -- Portability : portable 7 | -- 8 | -- Module to convert bytestring's ByteString type 9 | {-# LANGUAGE ViewPatterns #-} 10 | module Foundation.Compat.ByteString 11 | ( fromByteString 12 | , toByteString 13 | ) where 14 | 15 | import Data.ByteString (ByteString) 16 | import Data.ByteString.Internal (toForeignPtr, unsafeCreate, memcpy) 17 | import Foundation 18 | import Foundation.Array 19 | import Foundation.Array.Internal (withPtr, fromForeignPtr) 20 | 21 | -- | Convert a ByteString to a UArray Word8, 22 | -- without re-allocating or copying anything 23 | fromByteString :: ByteString -> UArray Word8 24 | fromByteString = fromForeignPtr . toForeignPtr 25 | 26 | -- | Convert a UArray Word8 to ByteString 27 | -- 28 | -- all the bytes are copied to a brand new memory chunk 29 | toByteString :: UArray Word8 -> ByteString 30 | toByteString v = unsafeCreate len $ \dst -> withPtr v $ \src -> memcpy dst src len 31 | where 32 | !len = length v 33 | -------------------------------------------------------------------------------- /Foundation/Compat/Text.hs: -------------------------------------------------------------------------------- 1 | -- | 2 | -- Module : Foundation.Compat.Text 3 | -- License : BSD-style 4 | -- Maintainer : Foundation 5 | -- Stability : experimental 6 | -- Portability : portable 7 | -- 8 | -- Module to convert text's Text type 9 | module Foundation.Compat.Text 10 | ( toText 11 | , fromText 12 | ) where 13 | 14 | import Data.Text (Text) 15 | import qualified Data.Text as T 16 | import Foundation 17 | 18 | -- | Convert a String to a Text. 19 | -- This currently allocates a new Text and copies the String content. 20 | toText :: String -> Text 21 | toText = T.pack . toList 22 | 23 | -- | Convert a Text to String 24 | -- This currently allocates a new String and copies the Text content. 25 | fromText :: Text -> String 26 | fromText = fromList . T.unpack 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015-2016 Vincent Hanquez 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of the author nor the names of his contributors 14 | may be used to endorse or promote products derived from this software 15 | without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS AS IS'' AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Foundation-edge 2 | =============== 3 | 4 | This package is useful to convert to and from, types and data structure commonly found in 5 | the haskell ecosystem. 6 | 7 | For now, edge support the following packages: 8 | 9 | * bytestring (initial) 10 | * text (initial) 11 | 12 | And planning to add support to: 13 | 14 | * vector 15 | 16 | If you think edge would benefits from other packages, open an issue (or even better a PR) with 17 | suggestion of what to add. 18 | -------------------------------------------------------------------------------- /Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /foundation-edge.cabal: -------------------------------------------------------------------------------- 1 | Name: foundation-edge 2 | Version: 0.0.2 3 | Synopsis: foundation's edge with the conventional set of packages 4 | Description: 5 | A set of functions to allow interaction with more conventional 6 | and well established packages like bytestring, text, vector 7 | . 8 | Current support: 9 | . 10 | * bytestring 11 | License: BSD3 12 | License-file: LICENSE 13 | Copyright: Vincent Hanquez 14 | Author: Vincent Hanquez 15 | Maintainer: vincent@snarc.org 16 | Category: foundation 17 | Stability: experimental 18 | Build-Type: Simple 19 | Homepage: https://github.com/haskell-foundation/foundation-edge 20 | Bug-Reports: https://github.com/haskell-foundation/foundation-edge/issues 21 | Cabal-Version: >=1.10 22 | tested-with: GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.1 23 | extra-source-files: README.md 24 | 25 | source-repository head 26 | type: git 27 | location: https://github.com/vincenthz/hs-foundation 28 | 29 | Library 30 | Exposed-modules: Foundation.Compat.ByteString 31 | , Foundation.Compat.Text 32 | Default-Extensions: NoImplicitPrelude 33 | TypeFamilies 34 | BangPatterns 35 | DeriveDataTypeable 36 | Build-depends: foundation >= 0.0.7 37 | , bytestring 38 | , text 39 | ghc-options: -Wall 40 | default-language: Haskell2010 41 | -------------------------------------------------------------------------------- /stack.yaml: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by stack init 2 | # For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration/ 3 | 4 | # Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) 5 | resolver: lts-8.12 6 | 7 | # Local packages, usually specified by relative directory name 8 | packages: 9 | - '.' 10 | # Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) 11 | extra-deps: [] 12 | 13 | # Override default flag values for local packages and extra-deps 14 | flags: {} 15 | 16 | # Extra package databases containing global packages 17 | extra-package-dbs: [] 18 | 19 | # Control whether we use the GHC we find on the path 20 | # system-ghc: true 21 | 22 | # Require a specific version of stack, using version ranges 23 | # require-stack-version: -any # Default 24 | # require-stack-version: >= 1.0.0 25 | 26 | # Override the architecture used by stack, especially useful on Windows 27 | # arch: i386 28 | # arch: x86_64 29 | 30 | # Extra directories used by stack for building 31 | # extra-include-dirs: [/path/to/dir] 32 | # extra-lib-dirs: [/path/to/dir] 33 | 34 | # Allow a newer minor version of GHC than the snapshot specifies 35 | # compiler-check: newer-minor 36 | --------------------------------------------------------------------------------