@@ -75,14 +75,16 @@ auto PresetFileParser::Read(std::istream& presetStream) -> bool
75
75
76
76
auto PresetFileParser::GetCode (const std::string& keyPrefix) const -> std::string
77
77
{
78
+ auto lowerKey = ToLower (keyPrefix);
79
+
78
80
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.
80
82
81
- key.replace (0 , keyPrefix .length (), keyPrefix );
83
+ key.replace (0 , lowerKey .length (), lowerKey );
82
84
83
85
for (int index {1 }; index <= 99999 ; ++index )
84
86
{
85
- key.replace (keyPrefix .length (), 5 , std::to_string (index ));
87
+ key.replace (lowerKey .length (), 5 , std::to_string (index ));
86
88
if (m_presetValues.find (key) == m_presetValues.end ())
87
89
{
88
90
break ;
@@ -105,11 +107,12 @@ auto PresetFileParser::GetCode(const std::string& keyPrefix) const -> std::strin
105
107
106
108
auto PresetFileParser::GetInt (const std::string& key, int defaultValue) -> int
107
109
{
108
- if (m_presetValues.find (key) != m_presetValues.end ())
110
+ auto lowerKey = ToLower (key);
111
+ if (m_presetValues.find (lowerKey) != m_presetValues.end ())
109
112
{
110
113
try
111
114
{
112
- return std::stoi (m_presetValues.at (key ));
115
+ return std::stoi (m_presetValues.at (lowerKey ));
113
116
}
114
117
catch (std::logic_error&)
115
118
{
@@ -121,11 +124,12 @@ auto PresetFileParser::GetInt(const std::string& key, int defaultValue) -> int
121
124
122
125
auto PresetFileParser::GetFloat (const std::string& key, float defaultValue) -> float
123
126
{
124
- if (m_presetValues.find (key) != m_presetValues.end ())
127
+ auto lowerKey = ToLower (key);
128
+ if (m_presetValues.find (lowerKey) != m_presetValues.end ())
125
129
{
126
130
try
127
131
{
128
- return std::stof (m_presetValues.at (key ));
132
+ return std::stof (m_presetValues.at (lowerKey ));
129
133
}
130
134
catch (std::logic_error&)
131
135
{
@@ -142,9 +146,10 @@ auto PresetFileParser::GetBool(const std::string& key, bool defaultValue) -> boo
142
146
143
147
auto PresetFileParser::GetString (const std::string& key, const std::string& defaultValue) -> std::string
144
148
{
145
- if (m_presetValues.find (key) != m_presetValues.end ())
149
+ auto lowerKey = ToLower (key);
150
+ if (m_presetValues.find (lowerKey) != m_presetValues.end ())
146
151
{
147
- return m_presetValues.at (key );
152
+ return m_presetValues.at (lowerKey );
148
153
}
149
154
150
155
return defaultValue;
@@ -166,7 +171,8 @@ void PresetFileParser::ParseLine(const std::string& line)
166
171
return ;
167
172
}
168
173
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)));
170
176
std::string value (line.begin () + varNameDelimiterPos + 1 , line.end ());
171
177
172
178
// Only add first occurrence to mimic Milkdrop behaviour
@@ -176,4 +182,13 @@ void PresetFileParser::ParseLine(const std::string& line)
176
182
}
177
183
}
178
184
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
+
179
194
} // namespace libprojectM
0 commit comments