packages feed

machines-encoding (empty) → 0

raw patch · 5 files changed

+100/−0 lines, 5 filesdep +basedep +bytestringdep +machinessetup-changed

Dependencies added: base, bytestring, machines, text

Files

+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Revision history for machines-encoding++## 0 -- 2019-01-31++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2019, davean++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of davean nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ machines-encoding.cabal view
@@ -0,0 +1,29 @@+cabal-version:       2.2++name:                machines-encoding+version:             0+synopsis:            Transcode encodings with machines.+description:         Transcoding of encodings with machines.+homepage:            https://oss.xkcd.com/+license:             BSD-3-Clause+license-file:        LICENSE+author:              davean+maintainer:          oss@xkcd.com+copyright:           Copyright (C) 2019 davean+category:            Control, Enumerator, Data, Text+extra-source-files:  CHANGELOG.md++source-repository head+  type: git+  location: https://code.xkrd.net/haskell/machines-encoding.git++library+  hs-source-dirs:      src+  default-language:    Haskell2010+  exposed-modules:+    Data.Machines.Encoding.Text+  build-depends:+      base       ^>=4.12.0.0+    , bytestring ^>= 0.10+    , machines   ^>= 0.6+    , text       ^>= 1.2
+ src/Data/Machines/Encoding/Text.hs view
@@ -0,0 +1,34 @@+module Data.Machines.Encoding.Text+ ( decodeLatin1+ , encodeUtf8, decodeUtf8+ ) where++import           Data.ByteString (ByteString)+import           Data.Machine+import           Data.Text (Text)+import qualified Data.Text.Encoding as TE++{- | Convert a stream of ByteStrings to a stream of Text+ -   by transorming the bytes from the Latin1 encoding.+ -}+decodeLatin1 :: Process ByteString Text+decodeLatin1 = auto TE.decodeLatin1+{-# INLINE decodeLatin1 #-}++{- | Convert a stream of Text to a stream of ByteStrings+ -   by transorming the symboles to the UTF-8 encoding.+ -}+encodeUtf8 :: Process Text ByteString+encodeUtf8 = auto TE.encodeUtf8+{-# LANGUAGE encodeUtf8 #-}++{- | Convert a stream of ByteStrings to a stream of Text+ -   by transorming the bytes from the UTF-8 encoding.+ -}+decodeUtf8 :: Process ByteString Text+decodeUtf8 = auto . Mealy $ runDecode . TE.streamDecodeUtf8+  where+    runDecode :: TE.Decoding -> (Text, Mealy ByteString Text)+    runDecode (TE.Some r _ c) = (r, Mealy $ runDecode . c)+    {-# INLINE runDecode #-}+{-# INLINE decodeUtf8 #-}