@@ -75,14 +75,16 @@ auto PresetFileParser::Read(std::istream& presetStream) -> bool
7575
7676auto PresetFileParser::GetCode (const std::string& keyPrefix) const -> std::string
7777{
78+ auto lowerKey = ToLower (keyPrefix);
79+
7880 std::stringstream code; // !< The parsed code
79- std::string key (keyPrefix .length () + 5 , ' \0 ' ); // !< Allocate a string that can hold up to 5 digits.
81+ std::string key (lowerKey .length () + 5 , ' \0 ' ); // !< Allocate a string that can hold up to 5 digits.
8082
81- key.replace (0 , keyPrefix .length (), keyPrefix );
83+ key.replace (0 , lowerKey .length (), lowerKey );
8284
8385 for (int index{1 }; index <= 99999 ; ++index)
8486 {
85- key.replace (keyPrefix .length (), 5 , std::to_string (index));
87+ key.replace (lowerKey .length (), 5 , std::to_string (index));
8688 if (m_presetValues.find (key) == m_presetValues.end ())
8789 {
8890 break ;
@@ -105,11 +107,12 @@ auto PresetFileParser::GetCode(const std::string& keyPrefix) const -> std::strin
105107
106108auto PresetFileParser::GetInt (const std::string& key, int defaultValue) -> int
107109{
108- if (m_presetValues.find (key) != m_presetValues.end ())
110+ auto lowerKey = ToLower (key);
111+ if (m_presetValues.find (lowerKey) != m_presetValues.end ())
109112 {
110113 try
111114 {
112- return std::stoi (m_presetValues.at (key ));
115+ return std::stoi (m_presetValues.at (lowerKey ));
113116 }
114117 catch (std::logic_error&)
115118 {
@@ -121,11 +124,12 @@ auto PresetFileParser::GetInt(const std::string& key, int defaultValue) -> int
121124
122125auto PresetFileParser::GetFloat (const std::string& key, float defaultValue) -> float
123126{
124- if (m_presetValues.find (key) != m_presetValues.end ())
127+ auto lowerKey = ToLower (key);
128+ if (m_presetValues.find (lowerKey) != m_presetValues.end ())
125129 {
126130 try
127131 {
128- return std::stof (m_presetValues.at (key ));
132+ return std::stof (m_presetValues.at (lowerKey ));
129133 }
130134 catch (std::logic_error&)
131135 {
@@ -142,9 +146,10 @@ auto PresetFileParser::GetBool(const std::string& key, bool defaultValue) -> boo
142146
143147auto PresetFileParser::GetString (const std::string& key, const std::string& defaultValue) -> std::string
144148{
145- if (m_presetValues.find (key) != m_presetValues.end ())
149+ auto lowerKey = ToLower (key);
150+ if (m_presetValues.find (lowerKey) != m_presetValues.end ())
146151 {
147- return m_presetValues.at (key );
152+ return m_presetValues.at (lowerKey );
148153 }
149154
150155 return defaultValue;
@@ -166,7 +171,8 @@ void PresetFileParser::ParseLine(const std::string& line)
166171 return ;
167172 }
168173
169- std::string varName (line.begin (), line.begin () + varNameDelimiterPos);
174+ // Convert key to lower case, as INI functions are not case-sensitive.
175+ std::string varName (ToLower (std::string (line.begin (), line.begin () + varNameDelimiterPos)));
170176 std::string value (line.begin () + varNameDelimiterPos + 1 , line.end ());
171177
172178 // Only add first occurrence to mimic Milkdrop behaviour
@@ -176,4 +182,13 @@ void PresetFileParser::ParseLine(const std::string& line)
176182 }
177183}
178184
185+ auto PresetFileParser::ToLower (std::string str) -> std::string
186+ {
187+ std::transform (str.begin (), str.end (), str.begin (),
188+ [](unsigned char c){ return std::tolower (c); }
189+ );
190+
191+ return str;
192+ }
193+
179194} // namespace libprojectM
0 commit comments