Source-highlight Library
highlightstate.h
1//
2// Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2004-2008
3//
4// Copyright: See COPYING file that comes with this distribution
5//
6
7#ifndef HIGHLIGHTSTATE_H_
8#define HIGHLIGHTSTATE_H_
9
10#include <deque>
11#include <vector>
12#include <string>
13#include <boost/shared_ptr.hpp>
14
15namespace srchilite {
16
17class HighlightRule;
18struct HighlightToken;
19struct MatchingParameters;
20
29typedef boost::shared_ptr<HighlightRule> HighlightRulePtr;
30
32typedef std::deque<HighlightRulePtr> RuleList;
33
36typedef std::vector<std::string> ReplacementList;
37
38class HighlightState;
39
41typedef boost::shared_ptr<HighlightState> HighlightStatePtr;
42
49 static unsigned int global_id;
50
52 const unsigned int id;
53
57 std::string defaultElement;
58
61
64
70
71public:
75 HighlightState(const std::string &e = "normal");
81 HighlightState(const HighlightState &copy);
83
88 void addRule(HighlightRulePtr rule);
89
97 HighlightRulePtr replaceRule(RuleList::size_type index,
98 HighlightRulePtr rule);
99
100 unsigned int getId() const {
101 return id;
102 }
103 const RuleList &getRuleList() const {
104 return ruleList;
105 }
106
107 const std::string &getDefaultElement() const {
108 return defaultElement;
109 }
110 void setDefaultElement(const std::string &e) {
111 defaultElement = e;
112 }
113
122 bool findBestMatch(const std::string &s, HighlightToken &token,
123 const MatchingParameters &params) const;
124
134 bool findBestMatch(std::string::const_iterator start,
135 std::string::const_iterator end, HighlightToken &token,
136 const MatchingParameters &params) const;
137
146 static bool betterThan(const HighlightToken &t1, const HighlightToken &t2);
147
155 void replaceReferences(const ReplacementList &rep);
156
157 bool getNeedsReferenceReplacement() const {
159 }
160
161 void setNeedsReferenceReplacement(bool b = true) {
163 }
164
165 HighlightStatePtr getOriginalState() const {
166 return originalState;
167 }
168
169 void setOriginalState(HighlightStatePtr orig) {
170 originalState = orig;
171 }
172
173};
174
175}
176
177#endif /*HIGHLIGHTSTATE_H_*/
Represents a state during the highlighting (e.g., comment state, string state, etc....
Definition: highlightstate.h:47
void addRule(HighlightRulePtr rule)
Adss a rule to this state.
Definition: highlightstate.cpp:32
const unsigned int id
the identifier of the state
Definition: highlightstate.h:52
RuleList ruleList
the list of rules of this state
Definition: highlightstate.h:60
bool needsReferenceReplacement
whether one of the contained rules has dynamic references to be replaced
Definition: highlightstate.h:63
HighlightStatePtr originalState
In case this state is a copy of another state, in this field we store the original state.
Definition: highlightstate.h:69
HighlightRulePtr replaceRule(RuleList::size_type index, HighlightRulePtr rule)
Substitutes the rule at the specified position.
Definition: highlightstate.cpp:36
void replaceReferences(const ReplacementList &rep)
Performs replacement of references in the rules of this state.
Definition: highlightstate.cpp:94
std::string defaultElement
the name of the element for strings when no rule matches (default: "normal") for states this should a...
Definition: highlightstate.h:57
static unsigned int global_id
the global counter to assign unique state ids
Definition: highlightstate.h:49
static bool betterThan(const HighlightToken &t1, const HighlightToken &t2)
Whether t1 is better than t2: t1 has a non-longer prefix and a longer matching string (this makes sen...
Definition: highlightstate.cpp:43
HighlightState(const std::string &e="normal")
Definition: highlightstate.cpp:20
bool findBestMatch(const std::string &s, HighlightToken &token, const MatchingParameters &params) const
Tries to find the rule that matches best (and first): the first rule with the smallest prefix and lon...
Definition: highlightstate.cpp:89
C++ class: doctemplate.h.
Definition: bufferedoutput.cpp:13
boost::shared_ptr< HighlightRule > HighlightRulePtr
Shared pointer for HighlightRule.
Definition: highlightstate.h:19
std::vector< std::string > ReplacementList
the values for replacing references (it should contain 9 possibly empty elements, because 9 is usuall...
Definition: highlightstate.h:36
std::deque< HighlightRulePtr > RuleList
List of rules.
Definition: highlightstate.h:32
boost::shared_ptr< HighlightState > HighlightStatePtr
the reference to an HighlightState
Definition: highlightstate.h:38