Support localize entries that have a name that cannot be represented as an identifier

This commit is contained in:
Jan 2023-09-24 15:58:57 +02:00
parent cf711c3af7
commit 36cd9e11fe
4 changed files with 24 additions and 2 deletions

View File

@ -8,7 +8,10 @@ SequenceLocalizeFileReference::SequenceLocalizeFileReference()
AddMatchers({
create.Keyword("REFERENCE"),
create.Identifier().Capture(CAPTURE_REFERENCE_NAME),
create.Or({
create.Identifier(),
create.String()
}).Capture(CAPTURE_REFERENCE_NAME),
create.Type(SimpleParserValueType::NEW_LINE)
});
}

View File

@ -38,13 +38,27 @@ void StringFileDumper::WriteHeader()
m_wrote_header = true;
}
void StringFileDumper::WriteReference(const std::string& reference) const
{
if (reference.find_first_not_of(utils::LETTERS_AL_NUM_UNDERSCORE) != std::string::npos)
{
m_stream << "REFERENCE \"";
utils::EscapeStringForQuotationMarks(m_stream, reference);
m_stream << "\"\n";
}
else
m_stream << "REFERENCE " << reference << "\n";
}
void StringFileDumper::WriteLocalizeEntry(const std::string& reference, const std::string& value)
{
if (!m_wrote_header)
WriteHeader();
m_stream << "\n";
m_stream << "REFERENCE " << reference << "\n";
WriteReference(reference);
const auto valueSpacing = std::string(15 - m_language_caps.length(), ' ');
m_stream << "LANG_" << m_language_caps << valueSpacing << "\"";

View File

@ -14,6 +14,7 @@ class StringFileDumper : AbstractTextDumper
bool m_wrote_header;
void WriteHeader();
void WriteReference(const std::string& reference) const;
public:
StringFileDumper(Zone* zone, std::ostream& stream);

View File

@ -3,6 +3,10 @@
namespace utils
{
#define M_LETTERS_AL_NUM "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
static constexpr const char* LETTERS_AL_NUM = M_LETTERS_AL_NUM;
static constexpr const char* LETTERS_AL_NUM_UNDERSCORE = M_LETTERS_AL_NUM "_";
std::string EscapeStringForQuotationMarks(const std::string_view& str);
void EscapeStringForQuotationMarks(std::ostream& stream, const std::string_view& str);
std::string UnescapeStringFromQuotationMarks(const std::string_view& str);