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


C++ filebuf::len方法代码示例

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


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

示例1: convert

filebuf IconvWrapper::convert(const filebuf& input)
{
	size_t ret = 0;

	char* BUFFER;
	size_t BUFFSIZE;

	size_t inbytesleft = 0;
	size_t outbytesleft = 0;
	char* input_ptr = 0;
	char* output_ptr = 0;

	char* output = 0; // The final result will go here...
	size_t output_size = 0;

	// How much data should be put avaiable to iconv?
	// How about twice as much as input's length?
	inbytesleft = input.len();
	BUFFSIZE = 2 * inbytesleft;
	outbytesleft = BUFFSIZE;

	// Get memory to hold our converted data.
	BUFFER = new char[ BUFFSIZE ];

	input_ptr = (char*)input.current;
	output_ptr = BUFFER;

	ret = iconv(	cd,
			&input_ptr, &inbytesleft, 
			&output_ptr, &outbytesleft);
	if (ret == size_t(-1)) {
		delete[] BUFFER;
		throw IconvError("While converting...");
	} 

	// Got here? So everything went fine.

	// Copy data to a more memory-efficient location
	output_size = BUFFSIZE - outbytesleft;
	output = new char[output_size];
	memcpy(output, BUFFER, output_size);
	delete[] BUFFER;

	return filebuf(output, output_size);
}
开发者ID:tmacam,项目名称:CrawlingBeast,代码行数:45,代码来源:unicodebugger.cpp

示例2: decompress

filebuf decompress(filebuf data)
{
	/* This code is based on zLib's usage example, available 
	 * at http://www.zlib.net/zlib_how.html
	 */

	// Zlib stuff
	int ret;
	z_stream strm;
	unsigned int have;
	// Outputing stuff
	size_t OUTBUF_LEN = DECOMPRESS_RESERVE; 
	char outbuf[OUTBUF_LEN];
	std::vector<char> accbuf; // accumulator buffer
	accbuf.reserve(DECOMPRESS_RESERVE);

	
	if (data.len() == 0) {
		// Empty filebufs result in empty filebufs.
		return filebuf();
	}

	/* allocate inflate state */
	const int windowBits = 15 + 16; /* 15 is the default value for 
					 * windownBits in inflateInit().
					 *
					 * Bits+16 means "use gzip" in
					 * zlib >= 1.2. Use 32 instead
					 * of 16 to force automatic header
					 * detection for gzip/zlib.
					 */
	strm.zalloc = Z_NULL;
	strm.zfree = Z_NULL;
	strm.opaque = Z_NULL;
	strm.avail_in = data.len();
	strm.next_in = Z_NULL;

	ret = inflateInit2(&strm, windowBits);
	if (ret != Z_OK){
		throw ZLibException("in inflateInit2", ret);
	}

	strm.avail_in = data.len();
	strm.next_in = (unsigned char*) data.current;

	/* decompress until deflate stream ends or an error happens */
	do {
		/* Remember: all input data _is_ available! All we can and
		 * must do is loop until zlib reports that it has
		 * finished or an error occurs.
		 */

		/* run inflate() on input until output buffer not full */
		do {

			strm.avail_out = OUTBUF_LEN;
			strm.next_out = (unsigned char*) outbuf;

			ret = inflate(&strm, Z_NO_FLUSH);
			// make sure state not clobbered
			if (ret == Z_STREAM_ERROR) {
				throw ZLibException("in inflate", ret);
			}
			switch (ret) {
				case Z_NEED_DICT:
					ret = Z_DATA_ERROR; // and fall through
				case Z_DATA_ERROR:
				case Z_MEM_ERROR:
					(void)inflateEnd(&strm);
					throw ZLibException("in inflate", ret);
			}

			have = OUTBUF_LEN - strm.avail_out;

			accbuf.insert(	accbuf.end(),
					outbuf,
					&outbuf[have]);
		} while (strm.avail_out == 0);

		/* done when inflate() says it's done */

	} while(ret != Z_STREAM_END);

	/* clean up */
	(void)inflateEnd(&strm);

	/* Ugly and lazy copy to an array */
	char* final_buffer = new char[accbuf.size()];
	std::copy(accbuf.begin(), accbuf.end(), final_buffer);

	return filebuf(final_buffer, accbuf.size());

}
开发者ID:tmacam,项目名称:CrawlingBeast,代码行数:93,代码来源:zfilebuf.cpp


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