utf (empty) → 0.0.0.0
raw patch · 7 files changed
+166/−0 lines, 7 filesdep +basedep +gaugedep +utf
Dependencies added: base, gauge, utf, util
Files
- CHANGELOG.md +11/−0
- LICENSE +29/−0
- README.md +7/−0
- bench/Main.hs +7/−0
- src/Codec/Text/UTF8.hs +30/−0
- test/Spec.hs +4/−0
- utf.cabal +78/−0
+ CHANGELOG.md view
@@ -0,0 +1,11 @@+# Changelog++`utf8.hs` uses [PVP Versioning][1].+The changelog is available [on GitHub][2].++## 0.0.0.0++* Initially created.++[1]: https://pvp.haskell.org+[2]: https://github.com/strake/utf8.hs/releases
+ LICENSE view
@@ -0,0 +1,29 @@+BSD 3-Clause License++Copyright (c) 2019, M Farkas-Dyck+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++1. Redistributions of source code must retain the above copyright notice, this+ list of conditions and the following disclaimer.++2. 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.++3. Neither the name of the copyright holder nor the names of its+ 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 HOLDER 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.
+ README.md view
@@ -0,0 +1,7 @@+# utf8.hs++[](https://travis-ci.org/strake/utf8.hs)+[](https://hackage.haskell.org/package/utf8.hs)+[](LICENSE)++See README for more info
+ bench/Main.hs view
@@ -0,0 +1,7 @@+module Main (main) where++import Gauge.Main+++main :: IO ()+main = defaultMain [bench "const" (whnf const ())]
+ src/Codec/Text/UTF8.hs view
@@ -0,0 +1,30 @@+{-# LANGUAGE BlockArguments #-}+module Codec.Text.UTF8 (Error, decode1) where++import Control.Arrow+import Data.Bits+import qualified Data.List as List+import Data.Word+import Util++decode1 :: [Word8] -> Maybe (Either Error Char, [Word8])+decode1 = List.uncons & fmap (uncurry (choose . fromEnum) >>> fmap toEnum *** id)+ where+ choose b bs+ | b < 0x80 = (Right $ toEnum b, drop 1 bs)+ | l < 2 || l > 6 = (Left InvalidSequence, drop 1 bs)+ | otherwise = go' l (fromEnum b .&. shiftR 0x7F l, bs)+ where+ l = countLeadingZeros (complement b)+ go (x, b:bs')+ | b .&. 0xC0 == 0x80 = (Right $ shiftL x 6 .|. fromEnum b .&. 0x3F, bs')+ | otherwise = (Left InvalidSequence, bs')+ go (_, bs) = (Left InvalidSequence, bs)+ go' 0 = Right *** id+ go' k = go & uncurry \ case+ Right x -> seq x $ go' (k-1) `curry` x+ z -> (,) z+{-# INLINABLE decode1 #-}++data Error = InvalidSequence+ deriving (Eq, Show)
+ test/Spec.hs view
@@ -0,0 +1,4 @@+module Main (main) where++main :: IO ()+main = putStrLn ("Test suite not yet implemented" :: String)
+ utf.cabal view
@@ -0,0 +1,78 @@+cabal-version: 2.2+name: utf+version: 0.0.0.0+synopsis: UTF-8+-- description: See README for more info+homepage: https://github.com/strake/utf.hs+bug-reports: https://github.com/strake/utf.hs/issues+license: BSD-3-Clause+license-file: LICENSE+author: M Farkas-Dyck+maintainer: strake888@gmail.com+copyright: 2019 M Farkas-Dyck+category: Parsing,Text+build-type: Simple+extra-doc-files: README.md+ , CHANGELOG.md+tested-with: GHC == 8.6.5++common c+ build-depends: base ^>= 4.12 || ^>= 4.13+ ghc-options: + -Wall+ -Wcompat+ -Wredundant-constraints+ -Wno-name-shadowing+ -Wincomplete-uni-patterns+ -Wincomplete-record-updates+ -Werror=incomplete-patterns+ -Werror=incomplete-uni-patterns+ -Werror=incomplete-record-updates+ -Werror=missing-fields+ -Werror=missing-methods+ default-language: Haskell2010+ default-extensions: UnicodeSyntax+ LambdaCase+ EmptyCase+ InstanceSigs+ PartialTypeSignatures+ PolyKinds+ ConstraintKinds+ FlexibleContexts+ FlexibleInstances+ MonadComprehensions+ StandaloneDeriving+ DeriveFunctor+ DeriveFoldable+ DeriveTraversable++library+ import: c+ hs-source-dirs: src+ exposed-modules: Codec.Text.UTF8+ build-depends: util ^>= 0.1.15++test-suite test+ import: c+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ main-is: Spec.hs+ build-depends: utf+ ghc-options: -threaded+ -rtsopts+ -with-rtsopts=-N++benchmark bench+ import: c+ type: exitcode-stdio-1.0+ hs-source-dirs: bench+ main-is: Main.hs+ build-depends: gauge+ , utf+ ghc-options: -threaded+ -rtsopts+ -with-rtsopts=-N++source-repository head+ type: git+ location: https://github.com/strake/utf.hs.git