Fix error loading LUT files with Turkish locale (#984)

In file parsing there are tests like Lower(x) == "spilut". However this was
using the locale dependent std::tolower, which for Turkish does not change
I to i.

Instead this implements a custom Lower() function which is not affected by
locale and so can be used for file parsing.

Signed-off-by: Brecht Van Lommel <brecht@blender.org>

Co-authored-by: Patrick Hodoul <patrickhodoul@gmail.com>
This commit is contained in:
Brecht Van LommelandPatrick Hodoul authored and GitHub committed 2020-04-22 09:53:55 -04:00
1 parent e38fec8dc3
commit 3aab90d31f
1 file changed
+24 -2
+24 -2
View File
@@ -21,12 +21,34 @@ namespace StringUtils
using StringVec = std::vector<std::string>;
// Return the lower case character without taking into account locale like
// std::tolower, to avoid the "Turkish I" problem in file parsing.
inline unsigned char Lower(unsigned char c)
{
if(c >= 'A' && c <= 'Z') {
return c + ('a' - 'A');
}
else {
return c;
}
}
// Return the upper case character, without taking into account locale.
inline unsigned char Upper(unsigned char c)
{
if(c >= 'a' && c <= 'z') {
return c - ('a' - 'A');
}
else {
return c;
}
}
// Return the lower case string.
inline std::string Lower(std::string str)
{
std::transform(str.begin(), str.end(), str.begin(),
[](unsigned char c) { return std::tolower(c); });
[](unsigned char c) { return Lower(c); });
return str;
}
@@ -34,7 +56,7 @@ inline std::string Lower(std::string str)
inline std::string Upper(std::string str)
{
std::transform(str.begin(), str.end(), str.begin(),
[](unsigned char c) { return std::toupper(c); });
[](unsigned char c) { return Upper(c); });
return str;
}