Source-highlight Library
textstyle.h
1//
2// C++ Interface: textstyle
3//
4// Description:
5//
6//
7// Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2005-2009
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12
13#ifndef _TEXTSTYLE_H_
14#define _TEXTSTYLE_H_
15
16#include <string>
17#include <vector>
18#include <map>
19#include <boost/regex.hpp>
20
21namespace srchilite {
22
23#define STYLE_VAR_TEXT "$style" // the text of the style variable
24#define TEXT_VAR_TEXT "$text" // the text of the text variable
25#define STYLE_VAR "\\" STYLE_VAR_TEXT // the name of the style variable as regexp
26#define TEXT_VAR "\\" TEXT_VAR_TEXT // the name of the text variable as regexp
28typedef std::map<std::string, std::string> SubstitutionMapping;
29
36class TextStyle {
37private:
38 typedef std::vector<std::string> StringVector;
39 typedef std::vector<int> IndexVector;
40 typedef std::map<std::string, IndexVector> SubstitutionIndexes;
41
43 boost::regex var_exp;
44
45 std::string repr;
46
48 StringVector parts;
49
51 SubstitutionIndexes substitutions;
52
54 bool invalid;
55
56 void build_vectors();
57
58public:
65 TextStyle(const std::string &s = "", const char **vars = 0);
66 ~TextStyle();
67
74 std::string output(const std::string &text, const std::string &style = "");
75
81 std::string output(SubstitutionMapping &subst_map);
82
88 std::string subst_style(const std::string &style = "");
89
93 const std::string &toString() const {
94 return repr;
95 }
96
104 TextStyle compose(const TextStyle &inner);
105
110 void update(const TextStyle &inner);
111
116 void update(const std::string &inner);
117
123 void update(const std::string &text, const std::string &style);
124
128 bool containsStyleVar() const;
129
133 bool empty() const;
134};
135
136}
137
138#endif /*_TEXTSTYLE_H_*/
Represents a formatting template where there can be some variables (starting with $,...
Definition: textstyle.h:36
bool containsStyleVar() const
Definition: textstyle.cpp:178
boost::regex var_exp
the regular expression to find variable occurrences
Definition: textstyle.h:43
void update(const TextStyle &inner)
as compose, but acts on this instance
Definition: textstyle.cpp:172
const std::string & toString() const
Definition: textstyle.h:93
StringVector parts
contains all the string parts of this TextStyle.
Definition: textstyle.h:48
SubstitutionIndexes substitutions
contains the indexes of parts where to substitute $vars.
Definition: textstyle.h:51
TextStyle compose(const TextStyle &inner)
substitutes $text with the string representation of inner e.g., if this is $text and inner is $text t...
Definition: textstyle.cpp:152
bool invalid
whether to rebuild the vectors
Definition: textstyle.h:54
std::string subst_style(const std::string &style="")
substitutes $style with style
Definition: textstyle.cpp:146
std::string output(const std::string &text, const std::string &style="")
substitutes $text with text and $style with style
Definition: textstyle.cpp:110
void build_vectors()
The parts vector contains the string repr split in parts: those that constant parts and those that re...
Definition: textstyle.cpp:68
bool empty() const
Definition: textstyle.cpp:185
C++ class: doctemplate.h.
Definition: bufferedoutput.cpp:13
std::map< std::string, std::string > SubstitutionMapping
map for substitutions
Definition: textstyle.h:28