packages feed

bytestring-csv 0.1.1 → 0.1.2

raw patch · 3 files changed

+30/−9 lines, 3 filesdep +dlistPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: dlist

API changes (from Hackage documentation)

- Text.CSV.ByteString.Lex: Item :: !!ByteString -> CSVToken
+ Text.CSV.ByteString.Lex: Item :: {-# UNPACK #-} !ByteString -> CSVToken

Files

Text/CSV/ByteString.hs view
@@ -25,6 +25,7 @@ import qualified Data.ByteString.Internal as S import qualified Data.ByteString.Char8    as S +import qualified Data.DList as D import Text.CSV.ByteString.Lex  ------------------------------------------------------------------------@@ -52,13 +53,13 @@ parseCSV :: S.ByteString -> Maybe CSV parseCSV s    | S.null s  = Nothing-   | otherwise = Just $! parseRecords toks []+   | otherwise = Just $! parseRecords toks D.empty   where    toks = lexCSV s -   parseRecords :: [CSVToken] -> CSV -> CSV-   parseRecords [] csv = reverse csv-   parseRecords xs csv = parseRecords (tail rest) (fields  : csv)+   parseRecords :: [CSVToken] -> D.DList Record -> CSV+   parseRecords [] csv = D.toList csv+   parseRecords xs csv = parseRecords (tail rest) (csv `D.snoc` fields)       where         (line, rest) = break (== Newline) xs         fields       = [ unquote s | Item s <- line ]
bytestring-csv.cabal view
@@ -1,5 +1,5 @@ Name:                bytestring-csv-Version:             0.1.1+Version:             0.1.2 Synopsis:            Parse CSV formatted data efficiently Description:         Parse CSV formatted data efficiently License:             BSD3@@ -25,6 +25,7 @@   if flag(small_base)       build-depends:     base >= 3, bytestring, array   else-      build-depends: base < 3+      build-depends:     base < 3+  build-depends:         dlist    ghc-options:       -O2 -funbox-strict-fields 
examples/Test.hs view
@@ -1,10 +1,29 @@ import Text.CSV.ByteString+import Data.ByteString.Lex.Double+ import Data.Maybe import Data.List+import System.Environment import qualified Data.ByteString as S +-- input of form+-- "IG2 US,43,45,NULL,2007-09-28 00:00:00,2007-09-28 16:32:00"++data T = T !Double+           !Double+           !Time+           !Time++type Time = S.ByteString++ppr (T a b _ _) = print (a,b)+ main = do-    r <- parseCSV `fmap` S.getContents+    [f] <- getArgs+    r <- parseCSV `fmap` S.readFile f     case r of-         Nothing  -> return ()-         Just csv -> mapM_ S.putStrLn $ nub [ x | (x:_) <- csv ]+         Nothing  -> error "unable to parse file"+         Just csv -> mapM_ ppr [ T (parse a) (parse b) c d | [_,a,b,_,c,d] <- csv ]++ where+    parse = fst . fromJust . readDouble