Logo Search packages:      
Sourcecode: f-spot version File versions  Download package

int TagLib::ByteVector::Find ( ByteVector  pattern,
int  offset,
int  byteAlign 
) [inline, inherited]

Finds the first byte-aligned occurance of a pattern in the current instance, starting at a specified position.

Parameters:
pattern A ByteVector object containing the pattern to search for in the current instance.
offset A int value specifying the index in the current instance at which to start searching.
byteAlign A int value specifying the byte alignment of the pattern to search for, relative to offset .
Returns:
A int value containing the index at which pattern was found in the current instance, or -1 if the pattern was not found. The difference between the position and offset will be divisible by byteAlign .
Exceptions:
ArgumentNullException pattern is .
ArgumentOutOfRangeException offset is less than zero or byteAlign is less than 1.

Definition at line 505 of file ByteVector.cs.

References TagLib::ByteVector::Count, and TagLib::ByteVector::data.

Referenced by TagLib::ByteVector::Find(), TagLib::File::Find(), TagLib::Mpeg4::IsoHandlerBox::IsoHandlerBox(), TagLib::Ape::Item::Parse(), TagLib::Id3v2::SynchronisedLyricsFrame::ParseFields(), TagLib::Id3v2::RelativeVolumeFrame::ParseFields(), TagLib::Id3v2::PopularimeterFrame::ParseFields(), TagLib::Id3v2::GeneralEncapsulatedObjectFrame::ParseFields(), TagLib::Id3v2::AttachedPictureFrame::ParseRawData(), TagLib::Asf::Tag::PictureFromData(), TagLib::Jpeg::File::ReadCOMSegment(), TagLib::Png::File::ReadTerminatedString(), TagLib::ByteVectorCollection::Split(), TagLib::ByteVector::ToStrings(), and TagLib::IFD::Entries::UserCommentIFDEntry::UserCommentIFDEntry().

            {
                  if (pattern == null)
                        throw new ArgumentNullException ("pattern");
                  
                  if (offset < 0)
                        throw new ArgumentOutOfRangeException (
                              "offset", "offset must be at least 0.");
                  
                  if (byteAlign < 1)
                        throw new ArgumentOutOfRangeException (
                              "byteAlign",
                              "byteAlign must be at least 1.");
                  
                  if (pattern.Count > Count - offset)
                        return -1;
                  
                  // Let's go ahead and special case a pattern of size one
                  // since that's common and easy to make fast.
                  
                  if (pattern.Count == 1) {
                        byte p = pattern [0];
                        for (int i = offset; i < this.data.Count;
                              i += byteAlign)
                              if (this.data [i] == p)
                                    return i;
                        return -1;
                  }
                  
                  int [] last_occurrence = new int [256];
                  for (int i = 0; i < 256; ++i)
                        last_occurrence [i] = pattern.Count;
                  
                  for (int i = 0; i < pattern.Count - 1; ++i)
                        last_occurrence [pattern [i]] =
                              pattern.Count - i - 1;
                  
                  for (int i = pattern.Count - 1 + offset;
                        i < this.data.Count;
                        i += last_occurrence [this.data [i]]) {
                        int iBuffer = i;
                        int iPattern = pattern.Count - 1;
                        
                        while(iPattern >= 0 && this.data [iBuffer] ==
                              pattern [iPattern]) {
                              --iBuffer;
                              --iPattern;
                        }
                        
                        if (-1 == iPattern && (iBuffer + 1 - offset) %
                              byteAlign == 0)
                              return iBuffer + 1;
                  }
                  
                  return -1;
            }


Generated by  Doxygen 1.6.0   Back to index