Hi,

I'm changing my CSV program to use ByteStrings, but I have problems with this:


readCSVLine       :: String   -- line as String
                  -> [String] -- line broken down into the value Strings
readCSVLine       = unfoldr builder
                      where
                        builder [] = Nothing
                        builder xs = Just $ readField xs

                        readField []       = ([],[])
                        readField (',':xs) = ([],xs)
                        readField ('"':xs) = (field,rest)
                          where
                            (field,'"':rest) = break (== '"') xs


So far, I have something like this - doesn't look too good to me, and doesn't compile:


import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C8

type CSV = [[B.ByteString]]

readCSVLine :: B.ByteString   -- line as String
            -> [B.ByteString] -- line broken down into the value Strings
readCSVLine = unfoldr builder
                where
                  builder xs | xs == B.empty = Nothing
                             | otherwise     = Just $ readField xs

                  readField xs | xs == B.empty    = ([],[])
                               | B.head xs == ',' = ([], B.tail xs)
                               | B.head xs == '"' = (field, B.tail rest)
                                    where
                                       field,rest) = B.break (== '"') xs


I do not know how to compare a Word8 to a Char. Or maybe I don't need to?

Regards
Philip
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to