From ecea456127e14fa449222d8ec3765b8ff8dcf2d5 Mon Sep 17 00:00:00 2001 From: Kai Blaschke Date: Sat, 4 Mar 2023 16:43:48 +0100 Subject: [PATCH] Remove unnecessary functions in PresetFileParser. projectm-eval can properly skip comments and whitespace. --- .../MilkdropPreset/PresetFileParser.cpp | 51 ------------------- .../MilkdropPreset/PresetFileParser.hpp | 23 --------- 2 files changed, 74 deletions(-) diff --git a/src/libprojectM/MilkdropPreset/PresetFileParser.cpp b/src/libprojectM/MilkdropPreset/PresetFileParser.cpp index aba3a3ba5..1d7e29da4 100644 --- a/src/libprojectM/MilkdropPreset/PresetFileParser.cpp +++ b/src/libprojectM/MilkdropPreset/PresetFileParser.cpp @@ -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(std::isspace)))); - line.erase(std::find_if(line.rbegin(), line.rend(), - std::not1(std::ptr_fun(std::isspace))) - .base(), - line.end()); -} diff --git a/src/libprojectM/MilkdropPreset/PresetFileParser.hpp b/src/libprojectM/MilkdropPreset/PresetFileParser.hpp index 1496afb3b..53dd2374e 100644 --- a/src/libprojectM/MilkdropPreset/PresetFileParser.hpp +++ b/src/libprojectM/MilkdropPreset/PresetFileParser.hpp @@ -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. };