smallstring (empty) → 0.1.0
raw patch · 4 files changed
+111/−0 lines, 4 filesdep +basedep +deepseqdep +smallarraysetup-changed
Dependencies added: base, deepseq, smallarray, utf8-string
Files
- Data/SmallString.hs +58/−0
- LICENSE +30/−0
- Setup.hs +2/−0
- smallstring.cabal +21/−0
+ Data/SmallString.hs view
@@ -0,0 +1,58 @@+{-# LANGUAGE BangPatterns #-}++{-|++ The SmallString type is for storing small identifiers. We do not provide fast operations+ on strings - what we offer is low memory overhead.++ The Ord instance is not guaranteed to be the same as that of the corresponding+ string.++ -}++module Data.SmallString+ ( SmallString+ , fromString+ , toString+ ) where++import qualified Data.SmallArray as A+import qualified Codec.Binary.UTF8.String as UTF8+import Data.Word (Word8)++import Control.DeepSeq++-- | A space efficient representation of text. This is like a strict ByteString, but+-- with fewer features, and UTF preserving. Fow ASCII data, we're slightly smaller than+-- ByteStrings for small strings.+newtype SmallString = SmallString (A.Array Word8)++instance Eq SmallString where+ (==) = eqSmallString++instance Ord SmallString where+ compare = compareSmallString++instance Show SmallString where+ show = show . toString++instance NFData SmallString where+ rnf (SmallString arr) = rnf arr++compareSmallString :: SmallString -> SmallString -> Ordering+compareSmallString (SmallString lhsAry) (SmallString rhsAry)+ = compare lhsAry rhsAry++eqSmallString :: SmallString -> SmallString -> Bool+eqSmallString (SmallString lhs) (SmallString rhs)+ = lhs == rhs++-- | Convert a String into a SmallString.+fromString :: String -> SmallString+fromString+ = SmallString . A.fromList . UTF8.encode++-- | Convert a SmallString into a String.+toString :: SmallString -> String+toString (SmallString ary)+ = UTF8.decode . A.toList $ ary
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2010, Antoine Latter++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 Antoine Latter 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
+ smallstring.cabal view
@@ -0,0 +1,21 @@+Name: smallstring+Version: 0.1.0+Synopsis: A string type optimized for size in memory+Description: A string type offering very little memory overhead. No+ string manipulation functions are offered.+ .+ Equality and ordinal comparison aim to be competitive with+ the String type.+Homepage: http://community.haskell.org/~aslatter/code/smallstring/+License: BSD3+License-file: LICENSE+Author: Antoine Latter+Maintainer: aslatter@gmail.com+Category: Data+Build-type: Simple+Cabal-version: >=1.6++Library+ Build-depends: base == 4.*, utf8-string == 0.3.*, smallarray == 0.1.*,+ deepseq == 1.1.*+ Exposed-modules: Data.SmallString