Add Learning/Parser

This commit is contained in:
Eero Holmala 2023-05-30 14:16:55 +03:00
parent fb92781632
commit 93cc368a3c
6 changed files with 95 additions and 0 deletions

2
Learning/Parser/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/build
/.vscode

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<message>
<warning>
Hello World
<!--missing </warning> -->
</message>

View 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)

View 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
View 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
View 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");
}