-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRule.h
92 lines (83 loc) · 1.94 KB
/
Rule.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Rule.h: interface for the CRule class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_RULE_H__A43BBCAB_07B1_4953_B5D8_3FC886AF1D1F__INCLUDED_)
#define AFX_RULE_H__A43BBCAB_07B1_4953_B5D8_3FC886AF1D1F__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CHandler;
class CRule
{
public:
virtual bool condition(const string& block) = 0;
virtual bool action(const string& block, CHandler* handler);
CRule();
virtual ~CRule();
protected:
string m_type;
};
class CHeadingRule : public CRule
{
public:
CHeadingRule() { m_type = "heading"; }
virtual ~CHeadingRule(){}
virtual bool condition(const string& block){
do{
if(block.find('\n') != string::npos)
break;
if(block.length() > 70)
break;
if(block[block.size() - 1] == ':')
break;
return true;
}while(0);
return false;
}
};
class CTitleRule : public CHeadingRule
{
public:
CTitleRule() : m_bFirst(true) { m_type = "title"; }
virtual ~CTitleRule(){}
virtual bool condition(const string& block){
if(!m_bFirst)
return false;
m_bFirst = true;
return CHeadingRule::condition(block);
}
private:
bool m_bFirst;
};
class CListItemRule : public CRule
{
public:
CListItemRule() { m_type = "listitem"; }
virtual ~CListItemRule(){}
virtual bool condition(const string& block){
return block[0] == '-';
}
virtual bool action(const string& block, CHandler* handler);
};
class CListRule : public CListItemRule
{
public:
CListRule() : m_bInside(false) { m_type = "list"; }
virtual ~CListRule(){}
virtual bool condition(const string& block){
return true;
}
virtual bool action(const string& block, CHandler* handler);
private:
bool m_bInside;
};
class CParagraphRule : public CRule
{
public:
CParagraphRule() { m_type = "paragraph"; }
virtual ~CParagraphRule(){}
virtual bool condition(const string& blcok){
return true;
}
};
#endif // !defined(AFX_RULE_H__A43BBCAB_07B1_4953_B5D8_3FC886AF1D1F__INCLUDED_)