packages feed

string-convert (empty) → 0.1.0.0

raw patch · 4 files changed

+141/−0 lines, 4 filesdep +basedep +bytestringdep +textsetup-changed

Dependencies added: base, bytestring, text, utf8-string

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2014, Tobias Dammers++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 Tobias Dammers 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
+ Text/StringConvert.hs view
@@ -0,0 +1,81 @@+-- | Provides universal conversions between any two string-like types.+-- Out-of-the-box, @Text@ (both lazy and strict), @ByteString@ (both lazy and+-- strict), and String, are supported.+--+-- To hook custom string types into the conversion mechanism, implement both+-- @FromString@ and @ToString@ for your type, and optionally provide special+-- cases for conversions to and from some other string-like type by+-- implementing @StringConvert@ directly.+{-#LANGUAGE MultiParamTypeClasses #-}+{-#LANGUAGE FlexibleInstances #-}+module Text.StringConvert+( FromString+, fromString+, ToString+, toString+, StringConvert+, s+)+where++import qualified Data.Text as Text+import qualified Data.Text.Lazy as LText+import qualified Data.ByteString.UTF8 as UTF8+import qualified Data.ByteString.Lazy.UTF8 as LUTF8+import qualified Data.ByteString.Lazy as LBS++class FromString a where+    fromString :: String -> a++instance FromString [Char] where+    fromString = id++instance FromString Text.Text where+    fromString = Text.pack++instance FromString LText.Text where+    fromString = LText.pack++instance FromString UTF8.ByteString where+    fromString = UTF8.fromString++instance FromString LUTF8.ByteString where+    fromString = LUTF8.fromString++-- | Defines how a given type should be converted to String.+-- If at all possible, the conversion should be loss-less, and if encodings are+-- involved, UTF-8 should be the default.+class ToString a where+    toString :: a -> String++instance ToString [Char] where+    toString = id++instance ToString LText.Text where+    toString = LText.unpack++instance ToString Text.Text where+    toString = Text.unpack++instance ToString UTF8.ByteString where+    toString = UTF8.toString+++-- | Defines conversions between two given stringish types.+class StringConvert a b where+    s :: a -> b++instance (ToString a, FromString b) => StringConvert a b where+    s = fromString . toString++instance StringConvert Text.Text LText.Text where+    s = LText.fromStrict++instance StringConvert LText.Text Text.Text where+    s = LText.toStrict++instance StringConvert UTF8.ByteString LUTF8.ByteString where+    s = LBS.fromStrict++instance StringConvert LUTF8.ByteString UTF8.ByteString where+    s = LBS.toStrict
+ string-convert.cabal view
@@ -0,0 +1,28 @@+-- Initial string-convert.cabal generated by cabal init.  For further +-- documentation, see http://haskell.org/cabal/users-guide/++name:                string-convert+version:             0.1.0.0+synopsis:            Provide universal string conversions between any two string-like types+-- description:         +homepage:            https://bitbucket.org/tdammers/string-convert+license:             BSD3+license-file:        LICENSE+author:              Tobias Dammers+maintainer:          tdammers@gmail.com+-- copyright:           +category:            Text+build-type:          Simple+-- extra-source-files:  +cabal-version:       >=1.10++library+  exposed-modules:     Text.StringConvert+  -- other-modules:       +  -- other-extensions:    +  build-depends: base >=4.5 && <4.7+               , bytestring+               , text+               , utf8-string+  -- hs-source-dirs:      +  default-language:    Haskell2010