当前位置: 首页>>代码示例>>C++>>正文


C++ TIXML_STRING::clear方法代码示例

本文整理汇总了C++中TIXML_STRING::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ TIXML_STRING::clear方法的具体用法?C++ TIXML_STRING::clear怎么用?C++ TIXML_STRING::clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TIXML_STRING的用法示例。


在下文中一共展示了TIXML_STRING::clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: LoadFile

bool TiXmlDocument::LoadFile( const TCHAR* filename )
{
	// Delete the existing data:
	Clear();
	location.Clear();

	// There was a really terrifying little bug here. The code:
	//		value = filename
	// in the STL case, cause the assignment method of the std::generic_string to
	// be called. What is strange, is that the std::generic_string had the same
	// address as it's c_str() method, and so bad things happen. Looks
	// like a bug in the Microsoft STL implementation.
	// See STL_STRING_BUG above.
	// Fixed with the StringToBuffer class.
	value = filename;

	FILE* file = generic_fopen( value.c_str (), TEXT("r") );

	if ( file )
	{
		// Get the file size, so we can pre-allocate the generic_string. HUGE speed impact.
		long length = 0;
		fseek( file, 0, SEEK_END );
		length = ftell( file );
		fseek( file, 0, SEEK_SET );

		// Strange case, but good to handle up front.
		if ( length == 0 )
		{
			fclose( file );
			return false;
		}

		// If we have a file, assume it is all one big XML file, and read it in.
		// The document parser may decide the document ends sooner than the entire file, however.
		TIXML_STRING data;
		data.reserve( length );

		const int BUF_SIZE = 2048;
		TCHAR buf[BUF_SIZE];

		while( generic_fgets( buf, BUF_SIZE, file ) )
		{
			data += buf;
		}
		fclose( file );

		//input is in UTF-8, so transformation is needed to UTF-16 used by windows for TCHAR in unicode mode
		std::vector<char> inputdataInUTF8(data.size()+1); //+1 for the null termination
		size_t datalength = wcstombs(inputdataInUTF8.data(), data.c_str(), data.size());
		int transformedDataCharCount = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)inputdataInUTF8.data(), -1, nullptr, 0);
		std::vector<wchar_t> transformedData(transformedDataCharCount+1); //+1 for the null termination
		transformedDataCharCount = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)inputdataInUTF8.data(), -1, transformedData.data(), transformedDataCharCount);
		if(transformedDataCharCount > 0)
		{
			//replace the original data with the new tranformed one, on success ot transformation otherwise go with old style data
			data.clear();
			data = transformedData.data();
		}
		Parse( data.c_str(), 0 );

		if (  Error() )
            return false;
        else
			return true;
	}
	SetError( TIXML_ERROR_OPENING_FILE, 0, 0 );
	return false;
}
开发者ID:bruderstein,项目名称:nppPluginManager,代码行数:69,代码来源:tinyxml.cpp


注:本文中的TIXML_STRING::clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。