コード例 #1
0
bool IO_CharDecoder::ReadUNICODE(IO_InputDataStream* stream, wstring& text)
{
	if(stream == NULL)
	{
		return false;
	}

	size_t length = 0;

	text.resize(IO_CHAR_BUFFER_SIZE);

	while(true)
	{
		int ch1 = stream->ReadByte() & 0xff;
		int ch2 = stream->ReadByte() & 0xff;
		int ch = ch1 | (ch2 << 8);

		if(length >= text.max_size())
		{
			text.resize(text.max_size() * 2);
		}

		if(ch == 0)
		{
			break;
		}

		if(ch == '\r')
		{
			stream->Skip(2);
		}

		if(ch == '\n')
		{
			break;
		}

		text[length++] = (wchar_t)ch;
	}

	return true;
}