comma::TextProvider Class Reference

Encapsulates a source of characters. More...

#include <TextProvider.h>

List of all members.

Public Member Functions

 TextProvider (const llvm::sys::Path &path)
 Construct a TextProvider over the given file.
 TextProvider (const char *buffer, size_t size)
 Construct a TextProvider over the given buffer.
 TextProvider (const std::string &string)
 Construct a TextProvider over the given string. The contents of the string are copied.
 ~TextProvider ()
std::string getIdentity () const
 Returns a string identifying this TextProvider.
Location getLocation (const TextIterator &ti) const
 Returns the Location object corresponding to the position of the supplied TextIterator.
SourceLocation getSourceLocation (const TextIterator &ti) const
 Returns a SourceLocation object corresponding to the position of the supplied iterator.
SourceLocation getSourceLocation (const Location loc) const
 Returns a SourceLocation object corresponding to the given raw Location.
unsigned getLine (Location) const
 Returns the line number associated with the given Location object.
unsigned getColumn (Location) const
 Returns the column number associated with the given Location.
unsigned getLine (const TextIterator &ti) const
 Returns the line number associated with the given TextIterator.
unsigned getColumn (const TextIterator &ti) const
 Returns the column number associated with the given TextIterator.
TextIterator begin () const
 Returns an iterator corresponding to the start of this TextProviders character data.
TextIterator end () const
 Returns a sentinel iterator.
std::string extract (Location start, Location end) const
 Provides access to a range of text.
std::string extract (const TextIterator &iter, const TextIterator &endIter) const
 Provides access to a range of text.
std::string extract (const SourceLocation &sloc) const
 Returns a string corresponding to the line of text containing the given SourceLocation.
unsigned extract (const TextIterator &iter, const TextIterator &endIter, char *buffer, size_t size) const
 Extracts a range of text into a buffer.

Friends

class TextIterator

Detailed Description

Encapsulates a source of characters.

The principle purpose of this class is to manage a source of character data. The source of the data may be a file or a raw buffer. Mechanisms are provided to iterate over the underlying characters, retrieve location information in the form of line/column coordinates, and to extract ranges of text.

Currently, lines are numbered beginning at 1 and columns are numbered beginning at 0. This is the conventional system used by Emacs. Adding additional indexing strategies should be straight forward to implement.

Todo:
Provide a set of alternative line/column indexing strategies.

Definition at line 102 of file TextProvider.h.


Constructor & Destructor Documentation

TextProvider::TextProvider ( const llvm::sys::Path &  path  ) 

Construct a TextProvider over the given file.

Initializes a TextProvider to manage the contents of the given file. The provided path must name a readable text file, or if the path specifies a file name "-", then read from all of stdin instead. If the path is invalid, this constructor will simply call abort.

Parameters:
path The file used to back this TextProvider.

Definition at line 17 of file TextProvider.cpp.

TextProvider::TextProvider ( const char *  buffer,
size_t  size 
)

Construct a TextProvider over the given buffer.

Initializes a TextProvider to manage the contents of the given region of memory. The contents of the buffer are copied -- the TextProvider does not take ownership of the memory region.

Parameters:
buffer Pointer to the start of the memory region.
size The size in bytes of the memory region.

Definition at line 36 of file TextProvider.cpp.

TextProvider::TextProvider ( const std::string &  string  ) 

Construct a TextProvider over the given string. The contents of the string are copied.

Parameters:
string The string used to back this TextProvider.

Definition at line 43 of file TextProvider.cpp.

TextProvider::~TextProvider (  ) 

Definition at line 52 of file TextProvider.cpp.


Member Function Documentation

TextIterator TextProvider::begin (  )  const

Returns an iterator corresponding to the start of this TextProviders character data.

Definition at line 76 of file TextProvider.cpp.

TextIterator TextProvider::end (  )  const

Returns a sentinel iterator.

Definition at line 81 of file TextProvider.cpp.

unsigned TextProvider::extract ( const TextIterator iter,
const TextIterator endIter,
char *  buffer,
size_t  size 
) const

Extracts a range of text into a buffer.

Places the range of text delimited by the given pair of iterators into the given buffer.

Parameters:
iter The position of the first character to be extracted.
endIter The position of one past the last character to be extracted.
buffer A pointer to a region of memory to be filled with character data. If this is the NULL pointer, then no data is written and this function returns the number of characters which would have been written assuming a large enough buffer was provided.
size The number of characters which the supplied buffer can accommodate. If the size is smaller than the number of characters which the iterators delimit, then only size characters are written.
Returns:
The number of characters written, or if buffer is NULL, the number of characters that would have been written if the supplied buffer was large enough.

Definition at line 119 of file TextProvider.cpp.

std::string TextProvider::extract ( const SourceLocation sloc  )  const

Returns a string corresponding to the line of text containing the given SourceLocation.

Parameters:
sloc The location of the line of text to extract.

Definition at line 106 of file TextProvider.cpp.

std::string TextProvider::extract ( const TextIterator iter,
const TextIterator endIter 
) const

Provides access to a range of text.

Returns a string corresponding the the range of text starting at the position of iter and ending just before the position of endIter.

Parameters:
iter The position of the first character to be extracted.
endIter The position of one past the last character to be extracted.

Definition at line 97 of file TextProvider.cpp.

std::string TextProvider::extract ( Location  start,
Location  end 
) const

Provides access to a range of text.

Returns a string corresponding to the range of text starting at location start and ends at location end. The range of text returned includes both of its end points.

Parameters:
start The location of the first character to be extracted.
end The location of the last character to be extracted.

Definition at line 86 of file TextProvider.cpp.

unsigned comma::TextProvider::getColumn ( const TextIterator ti  )  const [inline]

Returns the column number associated with the given TextIterator.

Definition at line 173 of file TextProvider.h.

unsigned TextProvider::getColumn ( Location  loc  )  const

Returns the column number associated with the given Location.

Definition at line 208 of file TextProvider.cpp.

std::string comma::TextProvider::getIdentity (  )  const [inline]

Returns a string identifying this TextProvider.

The string is typically the name of the underlying file, or "<stdin>" if the provider has obtained its input from the standard input stream. This string may be empty for providers which were constructed over raw memory buffers.

Definition at line 140 of file TextProvider.h.

unsigned comma::TextProvider::getLine ( const TextIterator ti  )  const [inline]

Returns the line number associated with the given TextIterator.

Definition at line 168 of file TextProvider.h.

unsigned TextProvider::getLine ( Location  loc  )  const

Returns the line number associated with the given Location object.

Definition at line 143 of file TextProvider.cpp.

Location TextProvider::getLocation ( const TextIterator ti  )  const

Returns the Location object corresponding to the position of the supplied TextIterator.

Parameters:
ti The iterator we need a location for.
Returns:
A Location object corresponding to the supplied iterator.
See also:
Location

Definition at line 57 of file TextProvider.cpp.

SourceLocation TextProvider::getSourceLocation ( const Location  loc  )  const

Returns a SourceLocation object corresponding to the given raw Location.

Definition at line 69 of file TextProvider.cpp.

SourceLocation TextProvider::getSourceLocation ( const TextIterator ti  )  const

Returns a SourceLocation object corresponding to the position of the supplied iterator.

Definition at line 62 of file TextProvider.cpp.


Friends And Related Function Documentation

friend class TextIterator [friend]

Definition at line 240 of file TextProvider.h.


The documentation for this class was generated from the following files:

Generated on 1 Feb 2010 for Comma by  doxygen 1.6.1

Rabisu Mirror Service We provide mirrors to support Open source communities. Our mirror server is located in Istanbul/Turkey region.

Please do not hesitate to contact mirror@rabisu.com for new open source mirror submissions.