- acf-02.zip
- Acf
- docs
- lib
- samples
- Corlib
- Arrays
- Boxing
- Delegate
- Environment
- Event
- FileSystem
- Foreach
- MFCReadWrite
- ReadWrite
- Samples.sln
- Samples.txt
- Strings
- Threads
- Timer
- src
- Corlib
- Pal
- tools
- vcide
- AppWizards
- ConsoleApp
- ConsoleApp.txt
- VCProjects
- ACF
- AcfAppWiz.vsdir
- AcfAppWiz.ico
- AcfAppWiz.vsdir
- AcfAppWiz.vsz
- VCWizards
- AcfAppWiz
- Scripts
- 1033
- Templates
- 1033
- readme.txt
- usertype.dat
- acf-01.zip
|
//---------------------------------------------------------------------
//
// Copyright (C) 2004 Yingle Jia
//
// Permission to copy, use, modify, sell and distribute this software is
// granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied warranty,
// and with no claim as to its suitability for any purpose.
//
#include "stdafx.h"
namespace Acf {
namespace IO {
//---------------------------------------------------------------------
// class TextReader
// Constructor & Destructor
TextReader::TextReader()
{
}
/*virtual*/ TextReader::~TextReader()
{
Close();
}
// Methods
/*virtual*/ int TextReader::Peek()
{
return -1;
}
/*virtual*/ int TextReader::Read()
{
return -1;
}
/*virtual*/ int TextReader::Read(Array<wchar_t>* buffer, int index, int count)
{
Acf::VerifyArrayRange(buffer, index, count);
int n = 0;
do {
int ch = Read();
if (ch == -1)
break;
buffer->Item[index + n++] = (wchar_t) ch;
} while (n < count);
return n;
}
/*virtual*/ int TextReader::ReadBlock(Array<wchar_t>* buffer, int index, int count)
{
int i, n = 0;
do {
n += (i = Read(buffer, index + n, count - n));
} while (i > 0 && n < count);
return n;
}
/*virtual*/ StringPtr TextReader::ReadLine()
{
StringBuilderPtr sb = new StringBuilder();
while (true)
{
int ch = Read();
if (ch == -1)
break;
if (ch == L'\r' || ch == L'\n')
{
if (ch == L'\r' && Peek() == L'\n')
Read();
return sb->ToString();
}
sb->Append((wchar_t) ch);
}
if (sb->Length > 0)
return sb->ToString();
return null;
}
/*virtual*/ StringPtr TextReader::ReadToEnd()
{
RefPtr< Array<wchar_t> > chars = new Array<wchar_t>(4096);
StringBuilderPtr sb = new StringBuilder(4096);
int len;
while ((len = Read(chars, 0, chars->Length)) != 0)
{
sb->Append(chars, 0, len);
}
return sb->ToString();
}
/*virtual*/ void TextReader::Close()
{
}
} // namespace IO
} // namespace Acf
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
Yingle Jia is a software engineer located in Beijing, China. He currently works at IBM CSDL (China Software Development Lab). His interests include C++/COM/C#/.NET/XML, etc. He likes coding and writing.
He is the creator of ACF (Another C++ Framework) project. See
http://acfproj.sourceforge.net/.
He also has a blog at
http://blogs.wwwcoder.com/yljia/