Fixed several bugs from the new file i/o setup.

In particular:
1. Windows CR/LF weren't read properly (issue #11)
2. Scanning wasn't reading EOF properly
3. Documents may be empty (this was old, I think)
Also fixed some VS2008 warnings on /W4.
This commit is contained in:
Jesse Beder
2009-02-07 07:57:13 +00:00
parent f9c0725684
commit 9d0e0c6a48
13 changed files with 85 additions and 63 deletions

View File

@@ -6,13 +6,18 @@ namespace YAML
{
Stream::Stream(std::istream& input): buffer(0), pos(0), line(0), column(0), size(0)
{
if(!input)
return;
std::streambuf *pBuf = input.rdbuf();
// store entire file in buffer
size = pBuf->pubseekoff(0, std::ios::end, std::ios::in);
pBuf->pubseekpos(0, std::ios::in);
buffer = new char[size];
pBuf->sgetn(buffer, size);
size = pBuf->sgetn(buffer, size); // Note: when reading a Windows CR/LF file,
// pubseekoff() counts CR/LF as two characters,
// setgn() reads CR/LF as a single LF character!
}
Stream::~Stream()