spreadsheet 0.1.1 → 0.1.1.1
raw patch · 2 files changed
+46/−9 lines, 2 files
Files
- spreadsheet.cabal +2/−2
- src/Data/Spreadsheet.hs +44/−7
spreadsheet.cabal view
@@ -1,5 +1,5 @@ Name: spreadsheet-Version: 0.1.1+Version: 0.1.1.1 License: BSD3 License-File: LICENSE Author: Henning Thielemann <haskell@henning-thielemann.de>@@ -24,7 +24,7 @@ Source-Repository this type: darcs location: http://code.haskell.org/~thielema/spreadsheet/- tag: 0.1.1+ tag: 0.1.1.1 Flag splitBase description: Choose the new smaller, split-up base package.
src/Data/Spreadsheet.hs view
@@ -106,24 +106,61 @@ -- quote qm s = [qm] ++ replace [qm] [qm,qm] s ++ [qm] +{- |+This is a quick hack.+It does neither handle field nor line separators within quoted fields.+You must provide well-formed CSV content+without field and line separators within quotations.+Everything else yields an error.+-} fromStringSimple :: Char -> Char -> String -> T fromStringSimple qm sep =- map (map (dequoteSimple qm) . chop (sep==)) . lines+ map (map (dequoteSimpleOptional qm) . chop (sep==)) . lines toStringSimple :: Char -> Char -> T -> String toStringSimple qm sep = unlines . map (concat . intersperse [sep] . map (\s -> [qm]++s++[qm])) -dequoteSimple :: Eq a => a -> [a] -> [a]-dequoteSimple _ [] = error "dequoteSimple: string is empty"-dequoteSimple qm (x:xs) =- if x == qm+_dequoteSimple :: Eq a => a -> [a] -> [a]+_dequoteSimple _ [] = error "dequoteSimple: string is empty"+_dequoteSimple qm (x:xs) =+ if x /= qm then error "dequoteSimple: quotation mark missing at beginning" else switchR (error "dequoteSimple: string consists only of a single quotation mark") (\ys y ->+ ys ++ if y == qm- then ys- else (error "dequoteSimple: string does not end with a quotation mark"))+ then []+ else error "dequoteSimple: string does not end with a quotation mark") xs++dequoteSimpleOptional :: Eq a => a -> [a] -> [a]+dequoteSimpleOptional _ [] = []+dequoteSimpleOptional qm xt@(x:xs) =+ if x /= qm+ then unescapeQuoteSimple qm xt+ else+ switchR+ (error "dequoteSimpleOptional: string consists only of a single quotation mark")+ (\ys y ->+ unescapeQuoteSimple qm ys +++ if y == qm+ then []+ else error "dequoteSimpleOptional: string does not end with a quotation mark")+ xs++unescapeQuoteSimple :: Eq a => a -> [a] -> [a]+unescapeQuoteSimple qm =+ let recourse [] = []+ recourse (x:xs) =+ if x /= qm+ then x : recourse xs+ else case xs of+ [] -> error "unescapeQuoteSimple: single quotation mark at end of string"+ y:ys ->+ if y/=qm+ then error "unescapeQuoteSimple: unmatched quotation mark"+ else qm : recourse ys+ in recourse