Source-highlight Library
srchilite::SourceHighlighter Class Reference

The main class performing the highlighting of a single line. More...

#include <sourcehighlighter.h>

Inheritance diagram for srchilite::SourceHighlighter:
Collaboration diagram for srchilite::SourceHighlighter:

Public Member Functions

 SourceHighlighter (HighlightStatePtr mainState)
void highlightParagraph (const std::string &paragraph)
 Highlights a paragraph (a line actually) More...
HighlightStatePtr getCurrentState () const
void setCurrentState (HighlightStatePtr state)
HighlightStateStackPtr getStateStack ()
void setStateStack (HighlightStateStackPtr state)
void clearStateStack ()
 Clears the statck of states.
HighlightStatePtr getMainState () const
const FormatterManagergetFormatterManager () const
void setFormatterManager (const FormatterManager *_formatterManager)
bool getOptimize () const
void setOptimize (bool b=true)
void setFormatterParams (FormatterParams *p)
bool isSuspended () const
void setSuspended (bool b=true)
void addListener (HighlightEventListener *listener)
void removeListener (HighlightEventListener *listener)
bool hasListeners () const
void notify (const HighlightEvent &event)
 Notifies all listeners of a specific event. More...

Private Member Functions

void enterState (HighlightStatePtr state)
 Enters a new state (using the stack) More...
void exitState (int level)
 Exits level states (-1 means exit all states) More...
void exitAll ()
 Exits all states in the stack (and thus go back to the initial main state)
HighlightStatePtr getNextState (const HighlightToken &token)
 Computes the (possible) next state for the given rule (if required, also performs reference replacement) More...
void format (const std::string &elem, const std::string &s)
 Formats the given string as the specified element. More...
void flush ()
 Makes sure to flush the possible buffer of the current element (e.g., during optimizations)

Private Attributes

HighlightStatePtr mainHighlightState
 the main (and initial) highlight state
HighlightStatePtr currentHighlightState
 the current highlight state
HighlightStateStackPtr stateStack
 the stack for the highlight states
const FormatterManagerformatterManager
 the formatter manager, used to format element strings
bool optimize
 Whether to optimize output (e.g., adjacent text parts belonging to the same element will be buffered and generated as a single text part)
bool suspended
 Whether formatting is currently suspended. More...
 Additional parameters for the formatters.
std::string currentElement
 The current element being formatted (used for optmization and buffering)
std::ostringstream currentElementBuffer
 The buffer for the text for the current element.

Detailed Description

The main class performing the highlighting of a single line.

It relies on a HighlightState (and its HighlightRule objects).

It provides the method highlightParagraph() to highlight a single line.

The current highlighting state can be retrieved with getCurrentState().

The highlighting state is not reset after highlighting a line, thus, the same object can be used to highlight, for instance, an entire file, by calling highlightParagraph on each line.

An example of use of this class is in infoformatter-main.cpp

Constructor & Destructor Documentation

srchilite::SourceHighlighter::SourceHighlighter ( HighlightStatePtr  mainState)
mainStatethe main and initial state for highlighting

Member Function Documentation

void srchilite::SourceHighlighter::enterState ( HighlightStatePtr  state)

Enters a new state (using the stack)

void srchilite::SourceHighlighter::exitState ( int  level)

Exits level states (-1 means exit all states)

void srchilite::SourceHighlighter::format ( const std::string &  elem,
const std::string &  s 

Formats the given string as the specified element.

HighlightStatePtr srchilite::SourceHighlighter::getNextState ( const HighlightToken token)

Computes the (possible) next state for the given rule (if required, also performs reference replacement)

void srchilite::SourceHighlighter::highlightParagraph ( const std::string &  paragraph)

Highlights a paragraph (a line actually)

void srchilite::EventGenerator< HighlightEventListener , HighlightEvent >::notify ( const HighlightEvent event)

Notifies all listeners of a specific event.

eventthe event

Member Data Documentation

bool srchilite::SourceHighlighter::suspended

Whether formatting is currently suspended.

Note that matching for regular expressions is not suspended: only the actual output of formatted code is suspended.

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