packages feed

utf8-conversions 0.1.0.1 → 0.1.0.2

raw patch · 5 files changed

+113/−7 lines, 5 filesdep +charsetdetectdep +hspecdep ~text-short

Dependencies added: charsetdetect, hspec

Dependency ranges changed: text-short

Files

ChangeLog.md view
@@ -1,7 +1,7 @@ # Changelog for utf8-conversions  #### 0.1.0.1-- Changed the conversion method between A and B+- Changed the conversion method between String and ShortByteString - Added type synonyms for documentation.  
README.md view
@@ -1,7 +1,33 @@ # `utf8-conversions` A string conversion library that assumes utf8 +[![Build Status](https://travis-ci.org/chemirea/utf8-conversions.svg?branch=master)](https://travis-ci.org/chemirea/utf8-conversions)+[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)+ This package provides a Data.Convertible.Utf8 library for easy conversion of many string types in Haskell +## usage++```haskell+import Data.Convertible.Utf8 (convert)++string :: String+string = "Hello world"++bytestring :: ByteString+bytestring = convert string++text :: Text+text = convert bytestring+```++A typeclass that represents something that can be converted.+A `Convertible a b` instance represents an `a` that can be converted to a `b`.++```haskell+class Convertible a b where+  convert :: a -> b+```+ ## Support  - String@@ -30,7 +56,7 @@ Libraries that do not explicitly state UTF8 are insecure  Therefore, this library clearly states that it assumes UTF8 and performs the conversion without using the MAYBE type, which is both safe and easy.-。+  ## Get involved! 
+ test/Data/Convertible/Utf8Spec.hs view
@@ -0,0 +1,75 @@+module Data.Convertible.Utf8Spec where++import           Codec.Text.Detect     (detectEncodingName)+import           Data.Convertible.Utf8+import           Test.Hspec++spec :: Spec+spec =+  describe "convert to LBS" $+    context "from String" $ do+      let string = convert "これはマルチバイト文字列です" :: String+      let lbs = convert string+      it "is UTF-8" $+        detectEncodingName lbs `shouldBe` utf8+      it "is not truncated" $+        "これはマルチバイト文字列です" `shouldBe` convert string++      context "via Text" $ do+        let text = convert "これはマルチバイト文字列です" :: Text+        let lbs = convert text+        it "is UTF-8" $+          detectEncodingName lbs `shouldBe` utf8+        it "is not truncated" $+          "これはマルチバイト文字列です" `shouldBe` convert text++      context "via LazyText" $ do+        let lazyText = convert "これはマルチバイト文字列です" :: LazyText+        let lbs = convert lazyText+        it "is UTF-8" $+          detectEncodingName lbs `shouldBe` utf8+        it "is not truncated" $+          "これはマルチバイト文字列です" `shouldBe` convert lazyText++      context "via TextBuilder" $ do+        let textBuilder = convert "これはマルチバイト文字列です" :: TextBuilder+        let lbs = convert textBuilder+        it "is UTF-8" $+          detectEncodingName lbs `shouldBe` utf8+        it "is not truncated" $+          "これはマルチバイト文字列です" `shouldBe` convert textBuilder++      context "via ShortText" $ do+        let shortText = convert "これはマルチバイト文字列です" :: ShortText+        let lbs = convert shortText+        it "is UTF-8" $+          detectEncodingName lbs `shouldBe` utf8+        it "is not truncated" $+          "これはマルチバイト文字列です" `shouldBe` convert shortText++      context "via StrictByteString" $ do+        let strictByteString = convert "これはマルチバイト文字列です" :: ByteString+        let lbs = convert strictByteString+        it "is UTF-8" $+          detectEncodingName lbs `shouldBe` utf8+        it "is not truncated" $+          "これはマルチバイト文字列です" `shouldBe` convert strictByteString++      context "via ByteStringBuilder" $ do+        let byteStringBuilder = convert "これはマルチバイト文字列です" :: ByteStringBuilder+        let lbs = convert byteStringBuilder+        it "is UTF-8" $+          detectEncodingName lbs `shouldBe` utf8+        it "is not truncated" $+          "これはマルチバイト文字列です" `shouldBe` convert byteStringBuilder++      context "via ShortByteString" $ do+        let shortByteString = convert "これはマルチバイト文字列です" :: ShortByteString+        let lbs = convert shortByteString+        it "is UTF-8" $+          detectEncodingName lbs `shouldBe` utf8+        it "is not truncated" $+          "これはマルチバイト文字列です" `shouldBe` convert shortByteString++utf8 :: Maybe String+utf8 = Just "UTF-8"
test/Spec.hs view
@@ -1,2 +1,4 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}+ main :: IO () main = putStrLn "Test suite not yet implemented"
utf8-conversions.cabal view
@@ -4,17 +4,17 @@ -- -- see: https://github.com/sol/hpack ----- hash: 469d48cf5af29b780713a6d7e4eed15b8c1b9085df0e04a2477ba95f29bcf12b+-- hash: 17be1c9dd266d0583157f173d496b2cc43c279f96842fbfaaab08cc1f4aabadb  name:           utf8-conversions-version:        0.1.0.1+version:        0.1.0.2 synopsis:       A string conversion library that assumes utf8 description:    Please see the README on GitHub at <https://github.com/chemirea/utf8-conversions#readme> category:       Data, Codec homepage:       https://github.com/chemirea/utf8-conversions#readme bug-reports:    https://github.com/chemirea/utf8-conversions/issues author:         Shintaro Sakata-maintainer:     Shintaro Sakata+maintainer:     shintaro.sakata.tokyo@gmail.com copyright:      2020 Shintaro Sakata license:        BSD3 license-file:   LICENSE@@ -38,7 +38,7 @@       base >=4.7 && <5     , bytestring >=0.10.4 && <0.11     , text >=1.0 && <1.3-    , text-short >=0.1.2 && <0.1.4+    , text-short >=0.1.1 && <0.1.4     , utf8-string >=1.0 && <1.2   default-language: Haskell2010 @@ -46,6 +46,7 @@   type: exitcode-stdio-1.0   main-is: Spec.hs   other-modules:+      Data.Convertible.Utf8Spec       Paths_utf8_conversions   hs-source-dirs:       test@@ -53,8 +54,10 @@   build-depends:       base >=4.7 && <5     , bytestring >=0.10.4 && <0.11+    , charsetdetect+    , hspec     , text >=1.0 && <1.3-    , text-short >=0.1.2 && <0.1.4+    , text-short >=0.1.1 && <0.1.4     , utf8-conversions     , utf8-string >=1.0 && <1.2   default-language: Haskell2010