Subject CSV line termination issue
From Gaetano <gaetanodd@hotmail.com>
Date Fri, 9 Oct 2020 08:21:47 +1000
Newsgroups dbase.getting-started


Hi All,

I have an input CSV file that has a CHR(10) (\n - hard line feed) at the
end of each line. When I f.gets(1000), dbase returns the first 1000
characters and ignores that end of line character.

When I f.gets(1000,chr(10)), it works, but then it may not handle
correctly a CSV file created in Windows.

What is a good way to handle an unknown end of line character? How do I
test for the end of line character since gets() stops at the first end
of line character it finds? I tried the following

cRead = f.gets(1000)
ASC(substr(cRead,167,1)

and that returned 0 (zero) on a Windows file but I'm not sure whether
that is a hidden end of line character in the string (a European soft
line feed as per gets() help) or whether ASC() returns zero because
substr() returns a NULL since start position 167 is past the end of string.

I do know that the length of the first line MUST be 166 characters (it's
a control I hard-code to make sure the app gets the right loader file
structure).

I was thinking of something like:

cRead = f.gets(1000)
if len(cRead)>166 // must be non-Windows end of line
        f.seek(0)  // move back to start of file
        cRead = f.gets(1000, chr(10))
endif

But I'm not sure if that covers all possibilities because the help for
gets() shows a number of different line terminations...

The input sources should be limited to Windows, Mac, Android, iOS and Linux.

Cheers,
Gaetano.