cannot handle macintosh end-of-line
I don't know how to read a macintosh text file. The end of line is a character '13'. It's '10' on unixes, 10+13 on windows.
Here is the code I use :
Code:
{
tr("Cannot read file %1:\n%2.")
.arg(fileName)
.arg(file.errorString()));
return;
}
line = in.readLine();
while (!line.isNull())
{
doneWords.append(line);
line = in.readLine();
}
The readline() function reads the whole file if it uses 13 as a newline char.
How can I set the endline char beeing '13' ?
Thank you !
Re: cannot handle macintosh end-of-line
Try this:
//line = in.readLine();
while (!in.atEnd()) {
line = in.readLine();
doneWords.append(line);
}
Re: cannot handle macintosh end-of-line
Thanks for your suggestion.
Doesn't work either. The problem is that Qt doesn't know that it's a mac style end-of-line.
I read a bit of Qt'sources and it seams that only windows and unix text handling is present.
I hope i'm wrong, but I fear I'm not.
I'll have to do this by hand, but don't know how.
It's a mater of changing every char(13) to char(10) and then load the file with a QTextStream.
Re: cannot handle macintosh end-of-line
Up!
No more suggestion ?
Strange that I find nothing about this.
I must be missing something.
Re: cannot handle macintosh end-of-line
If those files aren't too long, you could try QString::split().
Re: cannot handle macintosh end-of-line
Sadly, they can be rather large : from 80mb up to 500mb.
I'm starting doing it manually. If I find a better way using QTextStream, I'll be glad to update my code :)
Re: cannot handle macintosh end-of-line
Then maybe std::getline() will do?
Re: cannot handle macintosh end-of-line
Quote:
Originally Posted by
jacek
I'll have a look at it, thanks.
Re: cannot handle macintosh end-of-line
Answer from someone on qt-interest mailing list :
Quote:
Unfortunately, this is a known bug. But the Trolls do not seem to care that
the Mac folk have lots of old text files to read. (The line ending on Mac OS
X is now LF, not CR.)
You will have to implement your own readLine, or fix Qt's.
Of course, the _right_ way is to check for LF, CR, or LF/CR for every line.
Making any assumptions based on the platform or first line is dangerous.
(For instance, Visual Studio will create mixed line ending files when you
edit a different line ending type than the default. Edited lines will have
the default, but other lines retain the original.)
This has been a problem for years that is so easily solved. I fail to
understand why some developers still try to force everyone else to use their
line ending choice. It is such a Microsoft attitude.
Keith