-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.cpp
63 lines (55 loc) · 1.26 KB
/
validate.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
//Created by Ian Reitmaier
#include "LStack.cpp"
#include "Logger.cpp"
#include <fstream>
#include <string>
#include <istream>
//Creating the validate function
bool Validate(std::string fileName);
int main(){
Logger logger("./test.txt");
std::string file;
std::cout << "Enter File Name: ";
std::cin >> file;
logger.EnableConsoleLogging();
if(Validate(file)){
logger.Log("File is Valid");
}
else{
logger.Log("File is not valid Syntax Error");
}
}
bool Validate(std::string fileName){
int tracker;
char chr;
LStack <char> myStack;
std::fstream fin(fileName, std::fstream::in);
std::string trash;
getline(fin, trash);
while(fin >> chr){
if(chr == '<' ){
tracker = 1;
continue;
}
else if((tracker == 1) && (chr != '/')){
tracker = 0;
myStack.Push(chr);
continue;
}
else if(chr == '/'){
tracker = 2;
continue;
}
else if(tracker == 2){
if(myStack.Top() != chr){
return false;
}
else{
myStack.Pop();
tracker = 0;
continue;
}
}
}
return true;
}