From 4ffbb4a8ae731838300c7c090367c8da99267fb7 Mon Sep 17 00:00:00 2001 From: p9malino26 <pm3g19@soton.ac.uk> Date: Thu, 15 Apr 2021 12:39:56 +0100 Subject: [PATCH] Implemented stripping of csv strings --- Interpreter.hs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Interpreter.hs b/Interpreter.hs index ec36d02..06709a9 100644 --- a/Interpreter.hs +++ b/Interpreter.hs @@ -2,6 +2,7 @@ import Types import Debug import Eval import System.IO +import ReadCSV parse :: String -> Program parse = notImplemented @@ -34,10 +35,6 @@ evalFinal = evalFull [] showFinal :: Expr -> IO () showFinal = notImplemented - --------------------------------------------- - - -------------------------------------------- loadInputFile :: SymbolName -> IO Expr loadInputFile name = do @@ -46,8 +43,12 @@ loadInputFile name = do return output where - toRecord stringList = Record $ map String stringList + toRecord stringList = Record $ map ((String).stripLeadingAndTrailingWhitespace) stringList + +stripLeadingAndTrailingWhitespace = stripTrailingWhitespace.dropWhile (==' ') +stripTrailingWhitespace (' ':xs) = let remainder = stripTrailingWhitespace xs in + if null remainder then [] else ' ':remainder -readCSV :: FilePath -> IO [[String]] -readCSV = notImplemented \ No newline at end of file +stripTrailingWhitespace (x:xs) = x : stripTrailingWhitespace xs +stripTrailingWhitespace [] = [] -- GitLab