elseLeft$("Encapsulation problem at line "<>pack(showligne)<>" in column '"<>columnHeader<>"' : the caracter \" must only appear at the beginning and the end of a field ")
elseRight(("The column '"<>columnHeader<>"' at line "<>pack(showligne)<>" is empty"):warn)
-- else Left $ ("The column '" <> columnHeader <> "' at line " <> pack (show ligne) <> " is empty")
-- Put a warning for the user to know their is a problem (empty column)
testErrorPerLine_del[]l_|del==Comma=Left(pack$"Too much field at line "<>showl<>". Try using tabulation as a delimiter. Other delimiter like comma (,) may appear in some text.")
|otherwise=Left(pack$"Too much field at line "<>showl)
testErrorPerLine[]__l_=Left(pack$"Missing one field at line "<>showl)
-- | Checks whether a given chunk of text is a valid number
checkNumber::BL.ByteString-- ^ The text to parse as a number
->Text-- ^ Current header; passed as input for logging purposes
->Int-- ^ Current line; passed as input for logging purposes
->EitherText[Text]-- ^ List of warnings
checkNumberfieldcolumnHeaderline=do
letcleanField=removeText"\""$lBLToTextfield
value<-tryE(parseNumbercleanField)$
"Error in column '"<>columnHeader<>"' at line "<>T.pack(showline)<>" : value is not a number "
assertE(value>=0)$
"Value of column '"<>columnHeader<>"' at line "<>T.pack(showline)<>" is negative"
return[]
-- | Checks whether a given chunk of text is a valid text field
-- (i.e. does not have parasite quotes)
checkTextField::BL.ByteString-- ^ The text to parse as a number
->Text-- ^ Current header; passed as input for logging purposes
->Int-- ^ Current line; passed as input for logging purposes
->EitherText[Text]-- ^ List of warnings
checkTextFieldfieldcolumnHeaderligne=do
letcleanField=removeText"\"\""$lBLToTextfield
ifT.nullcleanField
thenRight["The column '"<>columnHeader<>"' at line "<>T.pack(showligne)<>" is empty"]
elsedo
assertE(
-- Field is not empty...
(T.lengthcleanField>0)&&
-- ... and either there are no quotes at all...
(T.length(T.filter(=='\"')cleanField)==0||
-- ... or there is only one quote at the beginning and one at the end
((T.headcleanField=='"')&&
(T.lastcleanField=='"')&&
(T.length(T.filter(=='\"')cleanField)==2)
)
))$
"Encapsulation problem at line "<>T.pack(showligne)<>" in column '"<>columnHeader<>"' : the caracter \" must only appear at the beginning and the end of a field "