コード例 #1
0
ファイル: table_paser.cpp プロジェクト: Garfield-Chen/tng
	int TablePaser::GetLine(std::basic_istream<char>& in_put, vector<string>& columns)
	{
		if (in_put.eof())
			return -1;

		std::streamoff i = in_put.tellg();
		memset(LineData, 0, LINE_DATA_MAX);
		in_put.getline(LineData, LINE_DATA_MAX);
		char* r_ch = strchr(LineData, '\r');
		if (r_ch)
		{
			in_put.seekg(i + (r_ch - LineData) + 1);
			*r_ch = '\0';
		}

		if (strlen(LineData) == 0)
			return GetLine(in_put, columns);

		stringstream ss_str;
		ss_str << LineData;

		int ret = 1;
		string column;
		while (ret == 1)
		{
			if ((ret = GetColumn(ss_str, in_put, column)) == -1)
				break;
			columns.push_back(column);
		}
		if (in_put.eof())
			return 0;
		return 1;
	}
コード例 #2
0
ファイル: wav.hpp プロジェクト: januswel/avsutil
            bool validate(std::basic_istream<Char>& in) const {
                typename std::basic_istream<Char>::streampos current =
                    in.tellg();
                in.seekg(0, std::ios::end);
                uint32_t file_size = static_cast<uint32_t>(in.tellg());
                in.seekg(current, std::ios::beg);
                uint32_t supposed_size =
                    data_subchunk.size + sizeof(header_type);

                if (file_size != supposed_size) {
                    DBGLOG("There is a difference between the wav file size"
                            " and the size of data that is written in the"
                            " header: "
                            << file_size << " != " << supposed_size);
                    return false;
                }

                return true;
            }
コード例 #3
0
void use_byte_order_mark (
	std::basic_istream <codepoint, char_traits <codepoint> > & stream)
{
	std::fpos<utf_mbstate> original_position = stream.tellg ();
	if (!stream.good())
	{
		imbue_default (stream);
		return;
	}
	try
	{
		stream.imbue (std::locale (stream.getloc(), new trivial_codecvt));

		/*
		We now start looking for a byte order mark.
		The following must be recognised:
		00 00 FE FF:	UTF-32BE
		FF FE 00 00:	UTF-32LE
		FE FF:			UTF-16BE
		FF FE:			UTF-16LE
		EF BB BF:		UTF-8
		*/

		codepoint byte = stream.rdbuf()->sbumpc();

		switch (byte)
		{
		case 0x00:
			if (stream.rdbuf()->sbumpc() == 0x00 &&
				stream.rdbuf()->sbumpc() == 0xfe &&
				stream.rdbuf()->sbumpc() == 0xff)
			{
				imbue_and_eat_bom (stream, original_position,
					new utf32be_codecvt);
				return;
			}
			break;
			
		case 0xef:
			if (stream.rdbuf()->sbumpc() == 0xbb &&
				stream.rdbuf()->sbumpc() == 0xbf)
			{
				imbue_and_eat_bom (stream, original_position,
					new utf8_codecvt);
				return;
			}
			break;

		case 0xfe:
			if (stream.rdbuf()->sbumpc() == 0xff)
			{
				imbue_and_eat_bom (stream, original_position,
					new utf16be_codecvt);
				return;
			}
			break;

		case 0xff:
			if (stream.rdbuf()->sbumpc() == 0xfe)
			{
				// This is either UTF-16LE or UTF-32LE.
				if (stream.rdbuf()->sbumpc() == 0x00 &&
					stream.rdbuf()->sbumpc() == 0x00)
				{
					imbue_and_eat_bom (stream, original_position,
						new utf32le_codecvt);
				} else
				{
					imbue_and_eat_bom (stream, original_position,
						new utf16le_codecvt);
				}
				return;
			}
			break;
		}
	}
	// If anything has gone wrong, just return to the original position and
	// state and imbue the default codecvt.
	catch (std::ios_base::failure &)
	{}
	stream.seekg (original_position);
	stream.clear();
	imbue_default (stream);
}