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

long TagLib::File::RFind ( ByteVector  pattern,
long  startPosition,
ByteVector  after 
) [inline, private]

Searches backwards through a file for a specified pattern, starting at a specified offset.

Parameters:
pattern A ByteVector object containing a pattern to search for in the current instance.
startPosition A int value specifying at what seek position to start searching.
after A ByteVector object specifying a pattern that the searched for pattern must appear after. If this pattern is found first, -1 is returned.
Returns:
A long value containing the index at which the value was found. If not found, -1 is returned.

Searching for after is not yet implemented.

Exceptions:
ArgumentNullException pattern is .

Definition at line 908 of file File.cs.

References buffer_size, TagLib::ByteVector::Count, file_stream, Length, Mode, ReadBlock(), and TagLib::ByteVector::RFind().

Referenced by RFind(), and TagLib::Mpeg::File::RFindMarker().

            {
                  if (pattern == null)
                        throw new ArgumentNullException ("pattern");
                  
                  Mode = AccessMode.Read;
                  
                  if (pattern.Count > buffer_size)
                        return -1;
                  
                  // The position in the file that the current buffer
                  // starts at.
                  
                  ByteVector buffer;
                  
                  // These variables are used to keep track of a partial
                  // match that happens at the end of a buffer.

                  /*
                  int previous_partial_match = -1;
                  int after_previous_partial_match = -1;
                  */
                  
                  // Save the location of the current read pointer.  We
                  // will restore the position using Seek() before all 
                  // returns.
                  
                  long original_position = file_stream.Position;
                  
                  // Start the search at the offset.
                  
                  long buffer_offset = Length - startPosition;
                  int read_size = buffer_size;
                  
                  read_size = (int) Math.Min (buffer_offset, buffer_size);
                  buffer_offset -= read_size;
                  file_stream.Position = buffer_offset;
                  
                  // See the notes in find() for an explanation of this
                  // algorithm.
                  
                  for (buffer = ReadBlock (read_size); buffer.Count > 0;
                        buffer = ReadBlock (read_size)) {
                        
                        // TODO: (1) previous partial match
                        
                        // (2) pattern contained in current buffer
                        
                        long location = buffer.RFind (pattern);
                        if (location >= 0) {
                              file_stream.Position = original_position;
                              return buffer_offset + location;
                        }
                        
                        if(after != null && buffer.RFind (after) >= 0) {
                              file_stream.Position = original_position;
                              return -1;
                        }
                        
                        // TODO: (3) partial match

                        
                        read_size = (int) Math.Min (buffer_offset, buffer_size);
                        buffer_offset -= read_size;
                  
                        file_stream.Position = buffer_offset;
                  }
                  
                  // Since we hit the end of the file, reset the status
                  // before continuing.
                  
                  file_stream.Position = original_position;
                  return -1;
            }


Generated by  Doxygen 1.6.0   Back to index