-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0032b7
commit 12ab03f
Showing
9 changed files
with
175 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# -*-LIC_BEGIN-*- | ||
# | ||
# DrawSpace Rendering engine | ||
# Emmanuel Chaumont Copyright (c) 2013-2023 | ||
# | ||
# This file is part of DrawSpace. | ||
# | ||
# DrawSpace is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# DrawSpace is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with DrawSpace. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# -*-LIC_END-*- | ||
|
||
cmake_minimum_required(VERSION 3.0) | ||
project(CORE_parser) | ||
|
||
include_directories(${CMAKE_SOURCE_DIR}/src) | ||
include_directories(${physfs_include_dir}) | ||
|
||
file( | ||
GLOB_RECURSE | ||
source_files | ||
${CMAKE_SOURCE_DIR}/CORE_parser/src/*.h | ||
${CMAKE_SOURCE_DIR}/CORE_parser/src/*.cpp | ||
) | ||
|
||
|
||
add_definitions( -D_FROMCMAKE ) | ||
|
||
add_library(CORE_parser ${source_files}) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,82 @@ | ||
/* -*-LIC_BEGIN-*- */ | ||
/* | ||
* | ||
* DrawSpace Rendering engine | ||
* Emmanuel Chaumont Copyright (c) 2013-2023 | ||
* | ||
* This file is part of DrawSpace. | ||
* | ||
* DrawSpace is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* DrawSpace is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with DrawSpace. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
/* -*-LIC_END-*- */ | ||
|
||
#include <vector> | ||
#include "parser.h" | ||
#include "file.h" | ||
|
||
|
||
using namespace DrawSpace; | ||
using namespace DrawSpace::Utils; | ||
|
||
static std::vector<dsstring> split(const std::string& s, const std::string& seperators) | ||
{ | ||
std::vector<std::string> output; | ||
std::string::size_type prev_pos{ 0 }; | ||
std::string::size_type pos{ 0 }; | ||
|
||
while ((pos = s.find(seperators, pos)) != std::string::npos) | ||
{ | ||
std::string substring(s.substr(prev_pos, pos - prev_pos)); | ||
|
||
output.push_back(substring); | ||
prev_pos = ++pos; | ||
} | ||
|
||
output.push_back(s.substr(prev_pos, pos - prev_pos)); // Last word | ||
return output; | ||
} | ||
|
||
void Parser::run(const dsstring& p_filepath, const dsstring& p_separators, const ParserCallback& p_callback) | ||
{ | ||
long line_count{ 0 }; | ||
|
||
File file(p_filepath, File::OPENEXISTINGTEXT); | ||
constexpr int lineMaxSize{ 1024 }; | ||
|
||
char line[lineMaxSize]; | ||
|
||
while (file.Gets(line, lineMaxSize)) | ||
{ | ||
line_count++; | ||
// supprimer le retour chariot en fin de ligne | ||
if (0x0a != line[0]) | ||
{ | ||
const auto len{ strlen(line) }; | ||
|
||
if (0x0a == line[len - 1]) | ||
{ | ||
line[len - 1] = 0x00; | ||
} | ||
|
||
const dsstring current_line(line); | ||
if (current_line != "") | ||
{ | ||
const auto words{ split(current_line, p_separators)}; | ||
|
||
p_callback(current_line, line_count, words); | ||
} | ||
} | ||
} | ||
/* -*-LIC_BEGIN-*- */ | ||
/* | ||
* | ||
* DrawSpace Rendering engine | ||
* Emmanuel Chaumont Copyright (c) 2013-2023 | ||
* | ||
* This file is part of DrawSpace. | ||
* | ||
* DrawSpace is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* DrawSpace is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with DrawSpace. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
/* -*-LIC_END-*- */ | ||
|
||
#include <vector> | ||
#include "parser.h" | ||
#include "file.h" | ||
|
||
|
||
using namespace DrawSpace; | ||
using namespace DrawSpace::Utils; | ||
|
||
static std::vector<dsstring> split(const std::string& s, const std::string& seperators) | ||
{ | ||
std::vector<std::string> output; | ||
std::string::size_type prev_pos{ 0 }; | ||
std::string::size_type pos{ 0 }; | ||
|
||
while ((pos = s.find(seperators, pos)) != std::string::npos) | ||
{ | ||
std::string substring(s.substr(prev_pos, pos - prev_pos)); | ||
|
||
output.push_back(substring); | ||
prev_pos = ++pos; | ||
} | ||
|
||
output.push_back(s.substr(prev_pos, pos - prev_pos)); // Last word | ||
return output; | ||
} | ||
|
||
void Parser::run(const dsstring& p_filepath, const dsstring& p_separators, const ParserCallback& p_callback) | ||
{ | ||
long line_count{ 0 }; | ||
|
||
File file(p_filepath, File::OPENEXISTINGTEXT); | ||
constexpr int lineMaxSize{ 1024 }; | ||
|
||
char line[lineMaxSize]; | ||
|
||
while (file.Gets(line, lineMaxSize)) | ||
{ | ||
line_count++; | ||
// supprimer le retour chariot en fin de ligne | ||
if (0x0a != line[0]) | ||
{ | ||
const auto len{ strlen(line) }; | ||
|
||
if (0x0a == line[len - 1]) | ||
{ | ||
line[len - 1] = 0x00; | ||
} | ||
|
||
const dsstring current_line(line); | ||
if (current_line != "") | ||
{ | ||
const auto words{ split(current_line, p_separators)}; | ||
|
||
p_callback(current_line, line_count, words); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
/* -*-LIC_BEGIN-*- */ | ||
/* | ||
* | ||
* DrawSpace Rendering engine | ||
* Emmanuel Chaumont Copyright (c) 2013-2023 | ||
* | ||
* This file is part of DrawSpace. | ||
* | ||
* DrawSpace is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* DrawSpace is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with DrawSpace. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
/* -*-LIC_END-*- */ | ||
|
||
#pragma once | ||
|
||
#include <vector> | ||
#include <functional> | ||
#include "ds_types.h" | ||
|
||
namespace DrawSpace | ||
{ | ||
namespace Parser | ||
{ | ||
using ParserCallback = std::function<void(const dsstring&, long, const std::vector<dsstring>&)>; | ||
|
||
void run(const dsstring& p_filepath, | ||
const dsstring& p_separators, | ||
const ParserCallback& p_callback | ||
); | ||
} | ||
} | ||
|
||
/* -*-LIC_BEGIN-*- */ | ||
/* | ||
* | ||
* DrawSpace Rendering engine | ||
* Emmanuel Chaumont Copyright (c) 2013-2023 | ||
* | ||
* This file is part of DrawSpace. | ||
* | ||
* DrawSpace is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* DrawSpace is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with DrawSpace. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
/* -*-LIC_END-*- */ | ||
|
||
#pragma once | ||
|
||
#include <vector> | ||
#include <functional> | ||
#include "ds_types.h" | ||
|
||
namespace DrawSpace | ||
{ | ||
namespace Parser | ||
{ | ||
using ParserCallback = std::function<void(const dsstring&, long, const std::vector<dsstring>&)>; | ||
|
||
void run(const dsstring& p_filepath, | ||
const dsstring& p_separators, | ||
const ParserCallback& p_callback | ||
); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters