-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXMLStatsHandler.cpp
More file actions
159 lines (129 loc) · 3.49 KB
/
XMLStatsHandler.cpp
File metadata and controls
159 lines (129 loc) · 3.49 KB
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
/*
XMLStatsHandler.cpp
Implementation file for the concrete class specific to XML Stats inheriting from the abstract class XMLParser
*/
#include "XMLStatsHandler.hpp"
#include <algorithm>
// constructor
XMLStatsHandler::XMLStatsHandler() :
unitCount(0), loc(0),
startDocumentCount(0), XMLDeclarationCount(0),
startTagCount(0), endTagCount(0), charactersCount(0),
attributeCount(0), XMLNamespaceCount(0),
XMLCommentCount(0), CDATACount(0),
processingInstructionCount(0), endDocumentCount(0)
{}
// get unitCount
int XMLStatsHandler::getUnitCount()
{
return unitCount;
}
// get loc
int XMLStatsHandler::getLoc()
{
return loc;
}
// get startDocumentCount
int XMLStatsHandler::getStartDocumentCount()
{
return startDocumentCount;
}
// get XMLDeclarationCount
int XMLStatsHandler::getXMLDeclarationCount()
{
return XMLDeclarationCount;
}
// get startTagCount
int XMLStatsHandler::getStartTagCount()
{
return startTagCount;
}
// get endTagCount
int XMLStatsHandler::getEndTagCount()
{
return endTagCount;
}
// get charactersCount
int XMLStatsHandler::getCharactersCount()
{
return charactersCount;
}
// get attributeCount
int XMLStatsHandler::getAttributeCount()
{
return attributeCount;
}
// get XMLNamespaceCount
int XMLStatsHandler::getXMLNamespaceCount()
{
return XMLNamespaceCount;
}
// get XMLCommentCount
int XMLStatsHandler::getXMLCommentCount()
{
return XMLCommentCount;
}
// get CDATACount
int XMLStatsHandler::getCDATACount()
{
return CDATACount;
}
// get processingInstructionCount
int XMLStatsHandler::getProcessingInstructionCount()
{
return processingInstructionCount;
}
// get endDocumentCount
int XMLStatsHandler::getEndDocumentCount()
{
return endDocumentCount;
}
// start Document Handler
void XMLStatsHandler::handleStartDocument() {
++startDocumentCount;
}
// XML Declaration Handler
void XMLStatsHandler::handleXMLDeclaration(std::string_view version, std::optional<std::string_view>& encoding, std::optional<std::string_view>& standalone) {
++XMLDeclarationCount;
}
// Start Tag Handler
void XMLStatsHandler::handleStartTag(std::string_view qName, std::string_view prefix, std::string_view localName) {
++startTagCount;
if (localName == "unit"sv) {
++unitCount;
}
}
// End Tag Handler
void XMLStatsHandler::handleEndTag(std::string_view qName, std::string_view prefix, std::string_view localName) {
++endTagCount;
}
// Character Handler
void XMLStatsHandler::handleCharacter(std::string_view characters) {
++charactersCount;
loc += static_cast<int>(std::count(characters.cbegin(), characters.cend(), '\n'));
}
// attribute Handler
void XMLStatsHandler::handleAttribute(std::string_view qName, std::string_view prefix, std::string_view localName, std::string_view value) {
++attributeCount;
}
// XML Namespace Handler
void XMLStatsHandler::handleXMLNamespace(std::string_view prefix, std::string_view uri) {
++XMLNamespaceCount;
}
// XML Comment Handler
void XMLStatsHandler::handleXMLComment(std::string_view value) {
++XMLCommentCount;
}
// CDATA Handler
void XMLStatsHandler::handleCDATA(std::string_view characters) {
++CDATACount;
loc += static_cast<int>(std::count(characters.cbegin(), characters.cend(), '\n'));
}
// processing Instruction Handler
void XMLStatsHandler::handleProcessingInstruction(std::string_view target, std::string_view data) {
++processingInstructionCount;
}
// end Document Handler
void XMLStatsHandler::handleEndDocument() {
++endDocumentCount;
}