Source-highlight Library
sourcefilehighlighter.h
1 //
2 // C++ Interface: SourceFileHighlighter
3 //
4 // Description:
5 //
6 //
7 // Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2008
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12 
13 #ifndef SOURCEFILEHIGHLIGHTER_H_
14 #define SOURCEFILEHIGHLIGHTER_H_
15 
16 #include <string>
17 #include <istream>
18 
19 namespace srchilite {
20 
21 class SourceHighlighter;
22 class BufferedOutput;
23 class PreFormatter;
24 class LineNumGenerator;
25 class LineRanges;
26 class RegexRanges;
27 class Formatter;
28 
31  NO_DEBUG = 0, DEBUG, DEBUG_INTERACTIVE
32 };
33 
39  const std::string fileName;
40 
43 
46 
49 
52 
55 
58 
61 
64 
66  std::string linePrefix;
67 
69  std::string rangeSeparator;
70 
71 public:
78  SourceFileHighlighter(const std::string &file,
79  SourceHighlighter *sourceHighlighter, BufferedOutput *output);
80 
81  void setDebugPolicy(FileHighlighterDebug p) {
82  debugPolicy = p;
83  }
84 
85  void setPreformatter(PreFormatter *pf) {
86  preformatter = pf;
87  }
88 
89  void setContextFormatter(Formatter *cf) {
90  contextFormatter = cf;
91  }
92 
93  void setLineNumGenerator(LineNumGenerator *lG) {
94  lineNumGenerator = lG;
95  }
96 
97  void setLinePrefix(const std::string &prefix) {
98  linePrefix = prefix;
99  }
100 
107  void setRangeSeparator(const std::string &rangeSep);
108 
109  const LineRanges *getLineRanges() const {
110  return lineRanges;
111  }
112 
113  void setLineRanges(LineRanges *lr) {
114  lineRanges = lr;
115  }
116 
117  void setRegexRanges(RegexRanges *rr) {
118  regexRanges = rr;
119  }
120 
125  void highlight();
126 
132  void highlight(std::istream &is);
133 
139  void highlight(const std::string &is);
140 
141 };
142 
143 }
144 
145 #endif /*SOURCEFILEHIGHLIGHTER_H_*/
The base abstract class for formatting strings.
Definition: formatter.h:25
Preformats text to be generated.
Definition: preformatter.h:31
Stores possible separators implemented as regular expressions and provides functionalities to search ...
Definition: regexranges.h:22
C++ class: doctemplate.h.
Definition: bufferedoutput.cpp:13
Generates line numbers in the output.
Definition: linenumgenerator.h:19
RegexRanges * regexRanges
if not null, it detects whether a line is in the stored ranges
Definition: sourcefilehighlighter.h:60
void setRangeSeparator(const std::string &rangeSep)
The range separator will be automatically preformatted to deal with the specific output format...
Definition: sourcefilehighlighter.cpp:66
SourceFileHighlighter(const std::string &file, SourceHighlighter *sourceHighlighter, BufferedOutput *output)
Definition: sourcefilehighlighter.cpp:43
void highlight()
Performs the highlighting; Once the highlighting is finished, this object can be re-used.
Definition: sourcefilehighlighter.cpp:74
Highlights the contents of a file relying on a SourceHighlighter.
Definition: sourcefilehighlighter.h:37
const std::string fileName
the name of the file to highlight
Definition: sourcefilehighlighter.h:39
LineRanges * lineRanges
if not null, it detects whether a line is in the stored ranges
Definition: sourcefilehighlighter.h:57
The main class performing the highlighting of a single line.
Definition: sourcehighlighter.h:43
Functionalities for detecting whether a line is in one of the stored line ranges (or in the context o...
Definition: lineranges.h:38
LineNumGenerator * lineNumGenerator
for generation of line numbers (if not null)
Definition: sourcefilehighlighter.h:54
PreFormatter * preformatter
the preformatter for characters, e.g., for
Definition: sourcefilehighlighter.h:51
FileHighlighterDebug debugPolicy
debugging policy
Definition: sourcefilehighlighter.h:48
FileHighlighterDebug
debugging policy
Definition: sourcefilehighlighter.h:30
The main class for writing into the output.
Definition: bufferedoutput.h:28
std::string linePrefix
a prefix to be generated in front of each formatted code line
Definition: sourcefilehighlighter.h:66
std::string rangeSeparator
if specified, a string to be printed between two ranges
Definition: sourcefilehighlighter.h:69
Formatter * contextFormatter
the formatter for possible context lines
Definition: sourcefilehighlighter.h:63
SourceHighlighter * sourceHighlighter
the initial regexp state
Definition: sourcefilehighlighter.h:42
BufferedOutput * output
the output object
Definition: sourcefilehighlighter.h:45