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


C++ SjByteVector::endsWithPartialMatch方法代码示例

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


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

示例1: BufferSize


//.........这里部分代码省略.........

		long originalPosition = Tell();

		// Start the search at the beginning of the file.

		Seek(0);

		// This loop is the crux of the find method.  There are three cases that we
		// want to account for:
		// (1) The previously searched buffer contained a partial match of the search
		// pattern and we want to see if the next one starts with the remainder of
		// that pattern.
		//
		// (2) The search pattern is wholly contained within the current buffer.
		//
		// (3) The current buffer ends with a partial match of the pattern.  We will
		// note this for use in the next itteration, where we will check for the rest
		// of the pattern.

		for(buffer = ReadBlock(BufferSize()); buffer.size() > 0; buffer = ReadBlock(BufferSize()))
		{

			// (1) previous partial match

			if(previousPartialSynchMatch && secondSynchByte(buffer[0]))
			{
				return -1;
			}

			if(previousPartialMatch >= 0 && int(BufferSize()) > previousPartialMatch)
			{
				const int patternOffset = (BufferSize() - previousPartialMatch);
				if(buffer.containsAt(ID3v2_Header::fileIdentifier(), 0, patternOffset))
				{
					Seek(originalPosition);
					return bufferOffset - BufferSize() + previousPartialMatch;
				}
			}

			// (2) pattern contained in current buffer

			long location = buffer.find(ID3v2_Header::fileIdentifier());
			if(location >= 0)
			{
				Seek(originalPosition);
				return bufferOffset + location;
			}

			int firstSynchByte = buffer.find(/*(char)*/((unsigned char)(255)));

			// Here we have to loop because there could be several of the first
			// (11111111) byte, and we want to check all such instances until we find
			// a full match (11111111 111) or hit the end of the buffer.

			while(firstSynchByte >= 0)
			{

				// if this *is not* at the end of the buffer

				if(firstSynchByte < int(buffer.size()) - 1)
				{
					if(secondSynchByte(buffer[firstSynchByte + 1]))
					{
						// We've found the frame synch pattern.
						Seek(originalPosition);
						return -1;
					}
					else
					{

						// We found 11111111 at the end of the current buffer indicating a
						// partial match of the synch pattern.  The find() below should
						// return -1 and break out of the loop.

						previousPartialSynchMatch = true;
					}
				}

				// Check in the rest of the buffer.

				firstSynchByte = buffer.find(/*char*/((unsigned char)(255)), firstSynchByte + 1);
			}

			// (3) partial match

			previousPartialMatch = buffer.endsWithPartialMatch(ID3v2_Header::fileIdentifier());

			bufferOffset += BufferSize();

		} // for()

		// Since we hit the end of the file, reset the status before continuing.

		Clear();

		Seek(originalPosition);
	}

	return -1;
}
开发者ID:boh1996,项目名称:silverjuke,代码行数:101,代码来源:tg_mpeg_file.cpp


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