Remove unnecessary functions in PresetFileParser.

projectm-eval can properly skip comments and whitespace.
This commit is contained in:
Kai Blaschke
2023-03-04 16:43:48 +01:00
parent 29b3d4a463
commit ecea456127
2 changed files with 0 additions and 74 deletions

View File

@ -88,8 +88,6 @@ auto PresetFileParser::GetCode(const std::string& keyPrefix) const -> std::strin
}
auto line = m_presetValues.at(key);
StripComment(line);
Trim(line);
if (!line.empty())
{
@ -108,7 +106,6 @@ auto PresetFileParser::GetCode(const std::string& keyPrefix) const -> std::strin
}
auto codeStr = code.str();
StripMultilineComment(codeStr);
return codeStr;
}
@ -175,51 +172,3 @@ void PresetFileParser::ParseLine(const std::string& line)
m_presetValues.emplace(std::move(varName), std::move(value));
}
}
void PresetFileParser::StripComment(std::string& line)
{
auto commentPos = line.find("//");
if (commentPos != std::string::npos)
{
line.resize(commentPos);
}
// While not documented, Milkdrop also considers "\\" to be a comment.
commentPos = line.find("\\\\");
if (commentPos != std::string::npos)
{
line.resize(commentPos);
}
}
void PresetFileParser::StripMultilineComment(std::string& code)
{
size_t commentPos;
while ((commentPos = code.find("/*")) != std::string::npos)
{
auto endPos = code.find("*/");
if (endPos != std::string::npos && endPos > commentPos)
{
code.erase(commentPos, endPos - commentPos + 2);
}
else
{
code.erase(commentPos, code.size() - commentPos);
}
}
}
void PresetFileParser::Trim(std::string& line)
{
if (line.empty())
{
return;
}
line.erase(line.begin(), std::find_if(line.begin(), line.end(),
std::not1(std::ptr_fun<int, int>(std::isspace))));
line.erase(std::find_if(line.rbegin(), line.rend(),
std::not1(std::ptr_fun<int, int>(std::isspace)))
.base(),
line.end());
}

View File

@ -103,29 +103,6 @@ protected:
*/
void ParseLine(const std::string& line);
/**
* @brief Strips an end-of-line comment from the given line.
* @param[in,out] line The code line to be stripped of a comment.
*/
static void StripComment(std::string& line);
/**
* @brief Strips all multi-line comments from the given code.
*
* This is also an undocumented feature of Milkdrop's equation parser. We could do it in the parser,
* but is doesn't hurt to generally remove such comments.
*
* @param[in,out] code The code to be stripped of all multi-line comments.
*/
static void StripMultilineComment(std::string& code);
/**
* @brief Trims any leading/trailing whitespace from the given line.
* @param[in,out] line The code line to be trimmed.
*/
static void Trim(std::string& line);
private:
ValueMap m_presetValues; //!< Map with preset keys and their value.
};