-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtag.cpp
executable file
·169 lines (146 loc) · 2.96 KB
/
tag.cpp
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*Copyright 2001
*
* tag.cpp
*
* Author: Gregory Ford [email protected]
* RTF token parser based on:
* rtf2html by Dmitry Porapov <[email protected]>,
* based on earlier work of Chuck Shotton.
* distributed under BSD-style license
* RTF token lists and hashing algorithm based on
* RTF Tools, Release 1.10
* 6 April 1994
* Paul DuBois [email protected]
*
* Copying permitted under GNU licence (see COPYING)
*/
// Tag.cpp: implementation of the Tag class.
//
//////////////////////////////////////////////////////////////////////
#include <string>
#include <memory>
using namespace std;
#include "tag.h"
TagItem tagDefinition[maxTag] = {
{false, ""},
{true, "b"},
{true, "i"},
{true, "u"},
{true, "sub"},
{true, "sup"},
{false, ""},
{false, "a"},
{false, "br"},
{false, "hr"},
{true, "p"},
{true, "h1"},
{true, "h2"},
{true, "h3"},
{true, "h4"},
{true, "h5"},
{true, "table"},
{true, "ul"},
{true, "ol"},
{true, "tr"},
{true, "td"},
{true, "li"}
};
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Tag::Tag()
{
}
Tag::~Tag()
{
}
//DEL string Tag::get_tag_name()
//DEL {
//DEL return tag_name;
//DEL }
//DEL bool Tag::get_endTag()
//DEL {
//DEL return endTag;
//DEL }
//DEL Tag::Tag(string tag_name, bool endTag)
//DEL {
//DEL this->tag_name = tag_name;
//DEL this->endTag = endTag;
//DEL }
//DEL void Tag::set_endTag(bool endTag)
//DEL {
//DEL this->endTag = endTag;
//DEL }
//DEL void Tag::set_tag_name(string tag_name)
//DEL {
//DEL this->tag_name = tag_name;
//DEL }
string Tag::toString()
{
if ( endTag ) {
if ( tagDefinition[tagType].hasEndTag ) {
return "</" + string( tagDefinition[tagType].text ) + ">";
} else {
return string ("");
}
} else {
// start tag
return "<" + string( tagDefinition[tagType].text ) + attributes + ">";
}
}
Tag::Tag(TagType tagId)
{
tagType = tagId;
endTag = false;
}
Tag::Tag(TagType tagId, string &tagAttributes)
{
tagType = tagId;
endTag = false;
attributes = tagAttributes; // use overloaded = to copy string ???
}
string Tag::getAttributes()
{
return attributes; // copy constructor???
}
void Tag::setAttributes(string &attributes)
{
this->attributes = attributes;
}
bool Tag::isCharacterFormat()
{
if (tagType > noTag && tagType < maxCharTag ) {
return true;
} else {
return false;
}
}
bool Tag::isParagraphFormat()
{
if (tagType >= pTag && tagType <= olTag ) {
return true;
} else {
return false;
}
}
bool Tag::isTable()
{
if (tagType == tableTag ) {
return true;
} else {
return false;
}
}
string Tag::tagIdToString(TagType tagId, bool endTag)
{
if ( endTag ) {
if ( tagDefinition[tagId].hasEndTag ) {
return "</" + string( tagDefinition[tagId].text ) + ">";
} else {
return string ("");
}
} else {
// start tag
return "<" + string( tagDefinition[tagId].text ) + ">";
}
}