Represents a formatting template where there can be some variables (starting with $, e.g., $style, $text, etc.) that will be replaced with specific elements, e.g., the actual style for the formatting, the text to format, etc.
More...
#include <textstyle.h>
|
| TextStyle (const std::string &s="", const char **vars=0) |
|
std::string | output (const std::string &text, const std::string &style="") |
| substitutes $text with text and $style with style More...
|
|
std::string | output (SubstitutionMapping &subst_map) |
| for each i substitutes: subst_map[i].first occurrence with subst_map[i].second More...
|
|
std::string | subst_style (const std::string &style="") |
| substitutes $style with style More...
|
|
const std::string & | toString () const |
|
TextStyle | compose (const TextStyle &inner) |
| substitutes $text with the string representation of inner e.g., if this is $text and inner is $text this will return $text More...
|
|
void | update (const TextStyle &inner) |
| as compose, but acts on this instance More...
|
|
void | update (const std::string &inner) |
| as compose, but acts on this instance More...
|
|
void | update (const std::string &text, const std::string &style) |
| as output, but acts on this instance More...
|
|
bool | containsStyleVar () const |
|
bool | empty () const |
|
|
typedef std::vector< std::string > | StringVector |
|
typedef std::vector< int > | IndexVector |
|
typedef std::map< std::string,
IndexVector > | SubstitutionIndexes |
|
|
void | build_vectors () |
| The parts vector contains the string repr split in parts: those that constant parts and those that represent $text and $style variables. More...
|
|
|
boost::regex | var_exp |
| the regular expression to find variable occurrences
|
|
std::string | repr |
|
StringVector | parts |
| contains all the string parts of this TextStyle.
|
|
SubstitutionIndexes | substitutions |
| contains the indexes of parts where to substitute $vars.
|
|
bool | invalid |
| whether to rebuild the vectors
|
|
Represents a formatting template where there can be some variables (starting with $, e.g., $style, $text, etc.) that will be replaced with specific elements, e.g., the actual style for the formatting, the text to format, etc.
srchilite::TextStyle::TextStyle |
( |
const std::string & |
s = "" , |
|
|
const char ** |
vars = 0 |
|
) |
| |
- Parameters
-
s | the representation |
vars | an array of string representing the variables in this TextStyle (e.g., {"linenum", "infilename", "infile", "outfile", 0}), the last element must be 0 |
void srchilite::TextStyle::build_vectors |
( |
| ) |
|
|
private |
The parts vector contains the string repr split in parts: those that constant parts and those that represent $text and $style variables.
For instance, if repr == "<span class=\"$style">$text", then we have:
- parts[0] == "<span class=\""
- parts[1] == ""
- parts[2] == "">"
- parts[3] == ""
- parts[4] == ""
Then style_substitutions contains the index(es) of parts corresponding to $style variable occurrences that will be substituted with values and text_substitutions is the same but for $text occurrences. Thus, in this case:
- style_substitutions[0] = 1
- text_substitutions[0] = 3
substitutes $text with the string representation of inner e.g., if this is $text and inner is $text this will return $text
- Parameters
-
- Returns
- a new TextStyle after substitution
bool srchilite::TextStyle::containsStyleVar |
( |
| ) |
const |
- Returns
- whether this TextStyle contains the $style variable
bool srchilite::TextStyle::empty |
( |
| ) |
const |
- Returns
- whether it is only $style or $text
string srchilite::TextStyle::output |
( |
const std::string & |
text, |
|
|
const std::string & |
style = "" |
|
) |
| |
substitutes $text with text and $style with style
First substitute in the vector parts the values for $text and $style and return a string with the substituted values.
- Parameters
-
- Returns
- the string after substitutions
- Parameters
-
- Returns
for each i substitutes: subst_map[i].first occurrence with subst_map[i].second
- Parameters
-
- Returns
- the string after substitutions
string srchilite::TextStyle::subst_style |
( |
const std::string & |
style = "" | ) |
|
substitutes $style with style
- Parameters
-
- Returns
- the string after substitutions
const std::string& srchilite::TextStyle::toString |
( |
| ) |
const |
|
inline |
- Returns
- the string representation
void srchilite::TextStyle::update |
( |
const TextStyle & |
inner | ) |
|
as compose, but acts on this instance
- Parameters
-
void srchilite::TextStyle::update |
( |
const std::string & |
inner | ) |
|
as compose, but acts on this instance
- Parameters
-
void srchilite::TextStyle::update |
( |
const std::string & |
text, |
|
|
const std::string & |
style |
|
) |
| |
as output, but acts on this instance
- Parameters
-
The documentation for this class was generated from the following files:
- /home/bettini/work/source-highlight/src-highlite/lib/srchilite/textstyle.h
- /home/bettini/work/source-highlight/src-highlite/lib/srchilite/textstyle.cpp