This repository was archived by the owner on Jun 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCsvReader.hs
More file actions
50 lines (35 loc) · 1.56 KB
/
CsvReader.hs
File metadata and controls
50 lines (35 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module CsvReader where
import qualified Data.Text as T
type CsvData = IO [[String]]
-- task4
-- TO-DO: need to handel empty entry
-- get rid of all spaces first
clearSpace [] = []
clearSpace (s:ss) | s == ' ' = clearSpace ss
| otherwise = s : clearSpace ss
readAnEntry :: String -> String
readAnEntry [] = []
readAnEntry (s:ss) | s == ',' = []
| otherwise = s : readAnEntry ss
readALine :: String -> Int -> [String]
readALine ss startIndex | startIndex >= Prelude.length ss = []
| otherwise = stringWithoutSpace : readALine ss (startIndex+(Prelude.length stringWithSpace)+1)
where stringWithoutSpace = T.unpack $ T.strip $ T.pack $ readAnEntry (Prelude.drop startIndex ss)
stringWithSpace = readAnEntry (Prelude.drop startIndex ss)
-- readFile writeFile
-- multiZipF = do
-- content <- readFile filePath
-- let numLines = lines content
-- let result = [num| x<-numLines, num <- [readALine (clearSpace x) 0]]
-- --let result = readALine (clearSpace content) 0
-- putStrLn "done"
-- return "";
-- file format
--1,2,3, 7, 89, 212321
--123
--readCsv :: String -> CsvData
readCsv f = do
content <- readFile f
let entryLines = Prelude.lines content
let result = [entry| x<-entryLines, entry <- [readALine x 0]]
return result;