mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
Escape string values when menu dumping
This commit is contained in:
parent
8a1fe03358
commit
aea76d0b42
@ -193,7 +193,7 @@ void MenuDumper::WriteStatementOperand(const Statement_s* statement, size_t& cur
|
||||
break;
|
||||
|
||||
case VAL_STRING:
|
||||
m_stream << "\"" << operand.internals.stringVal.string << "\"";
|
||||
WriteEscapedString(operand.internals.stringVal.string);
|
||||
break;
|
||||
|
||||
case VAL_FUNCTION:
|
||||
|
@ -192,7 +192,7 @@ void MenuDumper::WriteStatementOperand(const Statement_s* statement, size_t& cur
|
||||
break;
|
||||
|
||||
case VAL_STRING:
|
||||
m_stream << "\"" << operand.internals.stringVal.string << "\"";
|
||||
WriteEscapedString(operand.internals.stringVal.string);
|
||||
break;
|
||||
|
||||
case VAL_FUNCTION:
|
||||
|
@ -130,6 +130,38 @@ bool AbstractMenuDumper::DoesTokenNeedQuotationMarks(const std::string& token)
|
||||
return hasNonIdentifierCharacter;
|
||||
}
|
||||
|
||||
void AbstractMenuDumper::WriteEscapedString(const std::string_view& str) const
|
||||
{
|
||||
m_stream << "\"";
|
||||
|
||||
for (const auto& c : str)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '\r':
|
||||
m_stream << "\\r";
|
||||
break;
|
||||
case '\n':
|
||||
m_stream << "\\n";
|
||||
break;
|
||||
case '\t':
|
||||
m_stream << "\\t";
|
||||
break;
|
||||
case '\f':
|
||||
m_stream << "\\f";
|
||||
break;
|
||||
case '"':
|
||||
m_stream << "\\\"";
|
||||
break;
|
||||
default:
|
||||
m_stream << c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_stream << "\"";
|
||||
}
|
||||
|
||||
const std::string& AbstractMenuDumper::BoolValue(const bool value)
|
||||
{
|
||||
return value ? BOOL_VALUE_TRUE : BOOL_VALUE_FALSE;
|
||||
@ -154,7 +186,9 @@ void AbstractMenuDumper::WriteStringProperty(const std::string& propertyKey, con
|
||||
|
||||
Indent();
|
||||
WriteKey(propertyKey);
|
||||
m_stream << "\"" << propertyValue << "\"\n";
|
||||
|
||||
WriteEscapedString(propertyValue);
|
||||
m_stream << "\n";
|
||||
}
|
||||
|
||||
void AbstractMenuDumper::WriteStringProperty(const std::string& propertyKey, const char* propertyValue) const
|
||||
@ -164,7 +198,9 @@ void AbstractMenuDumper::WriteStringProperty(const std::string& propertyKey, con
|
||||
|
||||
Indent();
|
||||
WriteKey(propertyKey);
|
||||
m_stream << "\"" << propertyValue << "\"\n";
|
||||
|
||||
WriteEscapedString(propertyValue);
|
||||
m_stream << "\n";
|
||||
}
|
||||
|
||||
void AbstractMenuDumper::WriteBoolProperty(const std::string& propertyKey, const bool propertyValue, const bool defaultValue) const
|
||||
|
@ -30,6 +30,8 @@ protected:
|
||||
static std::vector<std::string> CreateScriptTokenList(const char* script);
|
||||
static bool DoesTokenNeedQuotationMarks(const std::string& token);
|
||||
|
||||
void WriteEscapedString(const std::string_view& str) const;
|
||||
|
||||
static const std::string& BoolValue(bool value);
|
||||
void WriteKey(const std::string& keyName) const;
|
||||
void WriteStringProperty(const std::string& propertyKey, const std::string& propertyValue) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user