Add Learning/Parser
This commit is contained in:
parent
fb92781632
commit
93cc368a3c
2
Learning/Parser/.gitignore
vendored
Normal file
2
Learning/Parser/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/build
|
||||||
|
/.vscode
|
||||||
6
Learning/Parser/Assets/test.xml
Normal file
6
Learning/Parser/Assets/test.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<message>
|
||||||
|
<warning>
|
||||||
|
Hello World
|
||||||
|
<!--missing </warning> -->
|
||||||
|
</message>
|
||||||
11
Learning/Parser/CMakeLists.txt
Normal file
11
Learning/Parser/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.0.0)
|
||||||
|
project(Parser VERSION 0.1.0)
|
||||||
|
|
||||||
|
include(CTest)
|
||||||
|
enable_testing()
|
||||||
|
|
||||||
|
add_executable(Parser main.cpp Parser.cpp Parser.hh)
|
||||||
|
|
||||||
|
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
||||||
|
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
|
||||||
|
include(CPack)
|
||||||
49
Learning/Parser/Parser.cpp
Normal file
49
Learning/Parser/Parser.cpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include "Parser.hh"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace Parser
|
||||||
|
{
|
||||||
|
Parser::Parser()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Parser::Parse(char *path)
|
||||||
|
{
|
||||||
|
char ch;
|
||||||
|
std::fstream fin(path, std::fstream::in);
|
||||||
|
|
||||||
|
if(!fin.is_open()){
|
||||||
|
std::cout << "Could not open file " << path << "\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (fin >> std::noskipws >> ch)
|
||||||
|
{
|
||||||
|
Parser::Consume(ch);
|
||||||
|
|
||||||
|
}
|
||||||
|
fin.close();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Parser::~Parser()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Parser::Consume(char c)
|
||||||
|
{
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case '<':
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
std::cout << c;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
17
Learning/Parser/Parser.hh
Normal file
17
Learning/Parser/Parser.hh
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
namespace Parser
|
||||||
|
{
|
||||||
|
class Parser {
|
||||||
|
public:
|
||||||
|
Parser();
|
||||||
|
bool Parse(char* path);
|
||||||
|
~Parser();
|
||||||
|
private:
|
||||||
|
void Consume(char c);
|
||||||
|
int m_rowCount;
|
||||||
|
int m_colCount;
|
||||||
|
};
|
||||||
|
}
|
||||||
10
Learning/Parser/main.cpp
Normal file
10
Learning/Parser/main.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "Parser.hh"
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
Parser::Parser* p = new Parser::Parser();
|
||||||
|
bool result = p->Parse("../Assets/test.xml");
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user