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>
Collaboration diagram for srchilite::TextStyle:
Public Member Functions
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...
for each i substitutes: subst_map[i].first occurrence with subst_map[i].second
More...
substitutes $style with style
More...
substitutes $text with the string representation of inner e.g., if this is
$text and inner is
$text this will return
$text More...
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...
Private Types
typedef std::vector< std::string > StringVector
typedef std::vector< int > IndexVector
typedef std::map< std::string,
IndexVector > SubstitutionIndexes
Private Member Functions
The parts vector contains the string repr split in parts: those that constant parts and those that represent $text and $style variables.
More...
Private Attributes
the regular expression to find variable occurrences
std::string repr
contains all the string parts of this
TextStyle.
contains the indexes of parts where to substitute $vars.
whether to rebuild the vectors
Detailed Description
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.
Constructor & Destructor Documentation
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
Member Function Documentation
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
-
inner
- 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
-
text
style
- Returns
- the string after substitutions
- Parameters
-
text
style
- Returns
for each i substitutes: subst_map[i].first occurrence with subst_map[i].second
- Parameters
-
subst_map
- Returns
- the string after substitutions
string srchilite::TextStyle::subst_style
(
const std::string &
style = "" )
substitutes $style with style
- Parameters
-
style
- 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
-
inner
void srchilite::TextStyle::update
(
const std::string &
inner )
as compose, but acts on this instance
- Parameters
-
inner
void srchilite::TextStyle::update
(
const std::string &
text,
const std::string &
style
)
as output, but acts on this instance
- Parameters
-
text
style
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