module Data.Array.Repa.IO.Internals.Text
( hWriteValues
, readValues)
where
import System.IO
import Data.Char
hWriteValues
:: Show a
=> Handle
-> [a]
-> IO ()
hWriteValues handle xx
= go xx
where go [] = return ()
go (x:xs)
= do hPutStr handle $ show x
hPutStr handle $ "\n"
go xs
readValues :: (Num a, Read a) => String -> [a]
readValues cs = readValues' [] cs
where readValues' _ [] = []
readValues' acc (c : rest)
| isSpace c
= if null acc
then readValues' [] rest
else read (reverse acc) : readValues' [] rest
| isDigit c || c == '.' || c == 'e' || c == '-'
= readValues' (c : acc) rest
| otherwise
= error $ "unexpected char in Matrix file " ++ show (ord c)