forked from mrizky-kur/Redux-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHTML Parser in C++.cpp
62 lines (53 loc) · 1.08 KB
/
HTML Parser in C++.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
#include <bits/stdc++.h>
using namespace std;
// Function to parse the
// HTML code
void parser(char* S)
{
// Store the length of the
// input string
int n = strlen(S);
int start = 0, end = 0;
// Traverse the string
for (int i = 0; i < n; i++) {
// If S[i] is '>', update
// start to i+1 and break
if (S[i] == '>') {
start = i + 1;
break;
}
}
// Remove the blank space
while (S[start] == ' ') {
start++;
}
// Traverse the string
for (int i = start; i < n; i++) {
// If S[i] is '<', update
// end to i-1 and break
if (S[i] == '<') {
end = i - 1;
break;
}
}
// Print the characters in the
// range [start, end]
for (int j = start; j <= end; j++) {
cout << S[j];
}
cout << endl;
}
// Driver Code
int main()
{
// Given Input
char input1[] = "<h1>This is a statement</h1>";
char input2[] = "<h1> This is a statement with some spaces</h1>";
char input3[] = "<p> This is a statement with some @ #$ ., / special characters</p> ";
cout << "Parsed Statements:\n";
// Function Call
parser(input1);
parser(input2);
parser(input3);
return 0;
}