-
Notifications
You must be signed in to change notification settings - Fork 0
/
Extractor.h
executable file
·51 lines (40 loc) · 1.34 KB
/
Extractor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef EXTRACTOR_H
#define EXTRACTOR_H
#include "Runnable.h"
#include "TextBlock.h"
#include <QList>
#include <QString>
class QString;
class CommentModel;
// Extracts substrings from a file
// the substrings are caught by a regular expression
// implements IRunnableOnFile
class Extractor : public IRunnableOnFile
{
public:
Extractor(const QString& pattern);
QList<TextBlock> getResult() const { return _result; }
void run(const QString& filePath); // run extractor on the file
private:
// extract one matching substring from text, starting from cursor,
// filePath is the file containing the text
// cursor will be updated after each call
TextBlock extractOne(const QString& text, const QString& filePath, int& cursor) const;
// returns the line num of the cursor in the text
int getLineNumber(const QString& text, int cursor) const;
private:
QString _pattern; // RegEx pattern
QList<TextBlock> _result;
};
// connecting an Extractor to a CommentModel
class ExtractorAdapter : public IRunnableOnFile
{
public:
ExtractorAdapter(Extractor* extractor, CommentModel* model = 0);
QList<TextBlock> getResult() const;
void run(const QString& filePath);
private:
Extractor* _extractor;
CommentModel* _model;
};
#endif // EXTRACTOR_H