Use escaped strings with simple lexer whenever appropriate

This commit is contained in:
Jan
2023-09-23 15:21:09 +02:00
parent 88bc1c1056
commit 2cd5d05a19
11 changed files with 22 additions and 41 deletions

View File

@ -1,6 +1,8 @@
#include "StringFileDumper.h"
#include <regex>
#include "Utils/StringUtils.h"
StringFileDumper::StringFileDumper(Zone* zone, std::ostream& stream)
: AbstractTextDumper(stream),
m_zone(zone),
@ -44,11 +46,10 @@ void StringFileDumper::WriteLocalizeEntry(const std::string& reference, const st
m_stream << "\n";
m_stream << "REFERENCE " << reference << "\n";
auto escapedValue = std::regex_replace(value, std::regex("\n"), "\\n");
escapedValue = std::regex_replace(escapedValue, std::regex("\r"), "\\r");
const auto valueSpacing = std::string(15 - m_language_caps.length(), ' ');
m_stream << "LANG_" << m_language_caps << valueSpacing << "\"" << escapedValue << "\"\n";
m_stream << "LANG_" << m_language_caps << valueSpacing << "\"";
utils::EscapeStringForQuotationMarks(m_stream, value);
m_stream << "\"\n";
}
void StringFileDumper::Finalize()

View File

@ -70,6 +70,7 @@ std::vector<std::string> AbstractMenuDumper::CreateScriptTokenList(const char* s
SimpleLexer::Config lexerConfig;
lexerConfig.m_emit_new_line_tokens = false;
lexerConfig.m_read_strings = true;
lexerConfig.m_string_escape_sequences = true;
lexerConfig.m_read_integer_numbers = false;
lexerConfig.m_read_floating_point_numbers = false;
SimpleLexer lexer(&inputStream, std::move(lexerConfig));

View File

@ -4,6 +4,7 @@
#include <sstream>
#include "Utils/Alignment.h"
#include "Utils/StringUtils.h"
StructuredDataDefDumper::StructuredDataDefDumper(std::ostream& stream)
: AbstractTextDumper(stream),
@ -37,7 +38,9 @@ void StructuredDataDefDumper::DumpEnum(const CommonStructuredDataEnum& _enum)
for (auto i = 0u; i < entryCount; i++)
{
Indent();
m_stream << "\"" << _enum.m_entries[i].m_name << "\"";
m_stream << "\"";
utils::EscapeStringForQuotationMarks(m_stream, _enum.m_entries[i].m_name);
m_stream << "\"";
if (i + 1 < entryCount)
m_stream << ",";