packages feed

string-transform (empty) → 0.0.0

raw patch · 5 files changed

+234/−0 lines, 5 filesdep +basedep +bytestringdep +string-transform

Dependencies added: base, bytestring, string-transform, tasty, tasty-hunit, tasty-smallcheck, text, utf8-string

Files

+ LICENSE view
@@ -0,0 +1,7 @@+Copyright 2017 ncaq++Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ README.md view
@@ -0,0 +1,27 @@+# string-transform++[![Build Status](https://travis-ci.org/ncaq/string-transform.svg?branch=master)](https://travis-ci.org/ncaq/string-transform)++It is++* `Prelude.String`+* `Data.ByteString.ByteString`+* `Data.ByteString.Lazy.ByteString`+* `Data.Text.Text`+* `Data.Text.Lazy.Text`++transform wrapper.++It is **simple** and **easy**.++# provide function++* `toString`+* `toByteStringStrict`+* `toByteStringLazy`+* `toTextStrict`+* `toTextLazy`++# note++It wrapper expect that `ByteString` encode is utf-8.
+ src/Data/String/Transform.hs view
@@ -0,0 +1,103 @@+{-# LANGUAGE FlexibleInstances    #-}+{-# LANGUAGE Safe                 #-}+{-# LANGUAGE TypeSynonymInstances #-}+module Data.String.Transform where++import qualified Data.ByteString           as B+import qualified Data.ByteString.Lazy      as BL+import qualified Data.ByteString.Lazy.UTF8 as BLU+import qualified Data.ByteString.UTF8      as BU+import qualified Data.Text                 as T+import qualified Data.Text.Encoding        as T+import qualified Data.Text.Lazy            as TL+import qualified Data.Text.Lazy.Encoding   as TL++class ToString a where+    toString :: a -> String++instance ToString String where+    toString = id++instance ToString B.ByteString where+    toString = BU.toString++instance ToString BL.ByteString where+    toString = BLU.toString++instance ToString T.Text where+    toString = T.unpack++instance ToString TL.Text where+    toString = TL.unpack++class ToByteStringStrict a where+    toByteStringStrict :: a -> B.ByteString++instance ToByteStringStrict String where+    toByteStringStrict = BU.fromString++instance ToByteStringStrict B.ByteString where+    toByteStringStrict = id++instance ToByteStringStrict BL.ByteString where+    toByteStringStrict = BL.toStrict++instance ToByteStringStrict T.Text where+    toByteStringStrict = T.encodeUtf8++instance ToByteStringStrict TL.Text where+    toByteStringStrict = T.encodeUtf8 . TL.toStrict++class ToByteStringLazy a where+    toByteStringLazy :: a -> BL.ByteString++instance ToByteStringLazy String where+    toByteStringLazy = BLU.fromString++instance ToByteStringLazy B.ByteString where+    toByteStringLazy = BL.fromStrict++instance ToByteStringLazy BL.ByteString where+    toByteStringLazy = id++instance ToByteStringLazy T.Text where+    toByteStringLazy = BL.fromStrict . T.encodeUtf8++instance ToByteStringLazy TL.Text where+    toByteStringLazy = TL.encodeUtf8++class ToTextStrict a where+    toTextStrict :: a -> T.Text++instance ToTextStrict String where+    toTextStrict = T.pack++instance ToTextStrict B.ByteString where+    toTextStrict = T.decodeUtf8++instance ToTextStrict BL.ByteString where+    toTextStrict = T.decodeUtf8 . BL.toStrict++instance ToTextStrict T.Text where+    toTextStrict = id++instance ToTextStrict TL.Text where+    toTextStrict = TL.toStrict++class ToTextLazy a where+    toTextLazy :: a -> TL.Text++instance ToTextLazy String where+    toTextLazy = TL.pack++instance ToTextLazy B.ByteString where+    toTextLazy = TL.decodeUtf8 . BL.fromStrict++instance ToTextLazy BL.ByteString where+    toTextLazy = TL.decodeUtf8++instance ToTextLazy T.Text where+    toTextLazy = TL.fromStrict++instance ToTextLazy TL.Text where+    toTextLazy = id
+ string-transform.cabal view
@@ -0,0 +1,54 @@+-- This file has been generated from package.yaml by hpack version 0.17.1.+--+-- see: https://github.com/sol/hpack++name:           string-transform+version:        0.0.0+synopsis:       simple and easy haskell string transform+category:       Text+homepage:       https://github.com/ncaq/string-transform.git#readme+bug-reports:    https://github.com/ncaq/string-transform.git/issues+author:         ncaq+maintainer:     ncaq@ncaq.net+copyright:      © ncaq+license:        MIT+license-file:   LICENSE+build-type:     Simple+cabal-version:  >= 1.10++extra-source-files:+    README.md++source-repository head+  type: git+  location: https://github.com/ncaq/string-transform.git++library+  hs-source-dirs:+      src+  ghc-options: -Wall+  build-depends:+      base >= 4.7 && < 5+    , bytestring+    , text+    , utf8-string+  exposed-modules:+      Data.String.Transform+  default-language: Haskell2010++test-suite tasty+  type: exitcode-stdio-1.0+  main-is: Main.hs+  hs-source-dirs:+      test+  ghc-options: -Wall+  build-depends:+      base >= 4.7 && < 5+    , bytestring+    , text+    , utf8-string+    , string-transform+    , tasty+    , tasty-hunit+    , tasty-smallcheck+  default-language: Haskell2010
+ test/Main.hs view
@@ -0,0 +1,43 @@+module Main (main) where++import           Data.String.Transform+import           Test.Tasty+import           Test.Tasty.HUnit+import           Test.Tasty.SmallCheck++main :: IO ()+main = defaultMain $ testGroup "all-tests" tests++tests :: [TestTree]+tests =+    [ testGroup "SmallCheck" smallCheckTest+    , testGroup "Unit tests" hunitTest+    ]++smallCheckTest :: [TestTree]+smallCheckTest =+    [ testProperty "toByteStringStrict" prop_toByteStringStrict_toString+    , testProperty "toByteStringLazy" prop_toByteStringLazy_toString+    , testProperty "toTextStrict" prop_toTextStrict_toString+    , testProperty "toTextLazy" prop_toTextLazy_toString+    ]++hunitTest :: [TestTree]+hunitTest =+    [ testCase "toByteStringStrict 日本語" case_japanese_toByteStrictStrict_toString+    ]++prop_toByteStringStrict_toString :: String -> Bool+prop_toByteStringStrict_toString string = string == toString (toByteStringStrict string)++prop_toByteStringLazy_toString :: String -> Bool+prop_toByteStringLazy_toString string = string == toString (toByteStringLazy string)++prop_toTextStrict_toString :: String -> Bool+prop_toTextStrict_toString string = string == toString (toTextStrict string)++prop_toTextLazy_toString :: String -> Bool+prop_toTextLazy_toString string = string == toString (toTextLazy string)++case_japanese_toByteStrictStrict_toString :: Assertion+case_japanese_toByteStrictStrict_toString = toString (toByteStringStrict "日本語") @?= "日本語"