mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-20 07:36:31 -05:00
Use QFile/QString for C parser files and paths
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <QFile>
|
||||
|
||||
namespace fex
|
||||
{
|
||||
@@ -155,48 +156,26 @@ namespace fex
|
||||
return Token(Token::Type::kDefine, filename_, line_number_);
|
||||
}
|
||||
|
||||
std::vector<Token> Lexer::LexString(const std::string &data)
|
||||
std::vector<Token> Lexer::LexFile(const QString &path)
|
||||
{
|
||||
filename_ = "string literal";
|
||||
line_number_ = 1;
|
||||
index_ = 0;
|
||||
data_ = data;
|
||||
|
||||
return Lex();
|
||||
}
|
||||
|
||||
std::vector<Token> Lexer::LexFile(const std::string &path)
|
||||
{
|
||||
filename_ = path;
|
||||
filename_ = path.toStdString();
|
||||
line_number_ = 1;
|
||||
|
||||
std::ifstream file;
|
||||
file.open(path);
|
||||
// Note: Using QFile instead of ifstream to handle encoding differences between platforms
|
||||
// (specifically to handle accented characters on Windows)
|
||||
QFile file(path);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
|
||||
std::stringstream stream;
|
||||
stream << file.rdbuf();
|
||||
const QByteArray data = file.readAll();
|
||||
|
||||
index_ = 0;
|
||||
data_ = stream.str();
|
||||
data_ = data.toStdString();
|
||||
|
||||
file.close();
|
||||
|
||||
return Lex();
|
||||
}
|
||||
|
||||
void Lexer::LexFileDumpTokens(const std::string &path, const std::string &out)
|
||||
{
|
||||
std::ofstream file;
|
||||
file.open(out);
|
||||
|
||||
for (Token token : LexFile(path))
|
||||
{
|
||||
file << token.ToString() << std::endl;
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
std::vector<Token> Lexer::Lex()
|
||||
{
|
||||
std::vector<Token> tokens;
|
||||
|
||||
@@ -337,7 +337,7 @@ namespace fex
|
||||
return DefineStatement(identifer, value);
|
||||
}
|
||||
|
||||
std::map<std::string, int> Parser::ReadDefines(const std::string &filename, std::vector<std::string> matching)
|
||||
std::map<std::string, int> Parser::ReadDefines(const QString &filename, std::vector<std::string> matching)
|
||||
{
|
||||
std::map<std::string, int> out;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user