本文整理汇总了C++中SjByteVector::containsAt方法的典型用法代码示例。如果您正苦于以下问题:C++ SjByteVector::containsAt方法的具体用法?C++ SjByteVector::containsAt怎么用?C++ SjByteVector::containsAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SjByteVector
的用法示例。
在下文中一共展示了SjByteVector::containsAt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BufferSize
long MPEG_File::findID3v2()
{
// This method is based on the contents of Tagger_File::find(), but because
// of some subtlteies -- specifically the need to look for the bit pattern of
// an MPEG sync, it has been modified for use here.
if( IsValid()
&& ID3v2_Header::fileIdentifier().size() <= BufferSize() )
{
// The position in the file that the current buffer starts at.
long bufferOffset = 0;
SjByteVector buffer;
// These variables are used to keep track of a partial match that happens at
// the end of a buffer.
int previousPartialMatch = -1;
bool previousPartialSynchMatch = false;
// Save the location of the current read pointer. We will restore the
// position using seek() before all returns.
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;
}
}
//.........这里部分代码省略.........